Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnome: Add support for gi-compile-repository for generate_gir #13997

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ewlsh
Copy link

@ewlsh ewlsh commented Dec 10, 2024

Opening this MR to start considering how to support gi-compile-repository (from glib) in place of g-ir-compiler (from gobject-introspection). gi-compile-repository is the replacement for g-ir-compiler and is currently used by GLib to compile its GIR files. This is currently being done by overriding the g-ir-compiler executable but we want to incorporate gi-compile-repository into the gnome meson module for all projects.

I've added a new kwarg, use_glib_to_compile_repositories, which allows opting into gi-compile-repository but this is definitely open to bikeshedding and ideas. In general I think this should probably be an opt-in to projects using gnome module even if gi-compile-repository should be a drop-in replacement.

@ewlsh ewlsh requested a review from jpakkane as a code owner December 10, 2024 18:04
@ewlsh
Copy link
Author

ewlsh commented Dec 10, 2024

GLib does not currently expose the binary path in pkg-config, a future version may via https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4428

'glib-genmarshal': ('glib-2.0', 'glib_genmarshal'),
'glib-mkenums': ('glib-2.0', 'glib_mkenums'),
# TODO: Use gi_compile_repository once GLib exposes it
'gi-compile-repository': ('girepository-2.0', None),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code as-written does not allow looking up tools which are not in pkg-config, this adapts the code to allow finding tools via binary lookup only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. That's just state.find_program() instead of state.find_tool()...
  2. Upstream MR has been merged (not released) so I guess we can simplify this again.

Copy link
Member

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a new kwarg, use_glib_to_compile_repositories, which allows opting into gi-compile-repository but this is definitely open to bikeshedding and ideas. In general I think this should probably be an opt-in to projects using gnome module even if gi-compile-repository should be a drop-in replacement.

What's the advantages and disadvantages of each? If gi-compile-repository is a drop-in replacement, why not unconditionally use it?

@@ -1112,6 +1124,7 @@ def _get_scanner_ldflags(ldflags: T.Iterable[str]) -> T.Iterable[str]:
KwargInfo('install_dir_gir', (str, bool, NoneType),
deprecated_values={False: ('0.61.0', 'Use install_gir to disable installation')},
validator=lambda x: 'as boolean can only be false' if x is True else None),
KwargInfo('use_glib_to_compile_repositories', (bool), default=False),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not just a long name, it's an unfortunately long name...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a stand-in, meant to be bikeshed :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like use_{new,latest}_compiler, use_glib_compiler, or even use_glib would suffice, given that it's an opt-in flag for fairly specific functionality. It can always be explained more fully in the documentation.

Plus, it's meant to be temporary, surely?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have this as part of the existing test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changes the library/binary which is compiling all of the GIRs. Both cases seem important to test. If there is a way to parameterize tests in this suite or a suggestion you have to combine the source files, let me know (first time navigating the meson codebase)

@ewlsh
Copy link
Author

ewlsh commented Dec 12, 2024

I've added a new kwarg, use_glib_to_compile_repositories, which allows opting into gi-compile-repository but this is definitely open to bikeshedding and ideas. In general I think this should probably be an opt-in to projects using gnome module even if gi-compile-repository should be a drop-in replacement.

What's the advantages and disadvantages of each? If gi-compile-repository is a drop-in replacement, why not unconditionally use it?

g-ir-compiler is deprecated and supports GIRepository 1.0, it was a separate codebase (https://gitlab.gnome.org/GNOME/gobject-introspection/). gi-compile-repository is a part of GLib proper (https://gitlab.gnome.org/GNOME/glib) and supports both GIRepository 1.0 and GIRepository 2.0 (roughly).

gi-compile-repository should work as a "drop-in" replacement tool-wise but it does support newer GLib features (asynchronous annotations, for example) which could cause existing toolchains to fail to compile without code changes.

@ewlsh
Copy link
Author

ewlsh commented Dec 12, 2024

If gi-compile-repository is a drop-in replacement, why not unconditionally use it?

@eli-schwartz Additionally gi-compile-repository is only shipped since GLib 2.79.2 so LTS distributions don't have it yet. Ubuntu bionic, for example, would not.

@ewlsh ewlsh force-pushed the ewlsh/gi-compile-repository branch from efabb27 to 3034fff Compare December 12, 2024 10:03
@ewlsh ewlsh force-pushed the ewlsh/gi-compile-repository branch from 3034fff to b7ac866 Compare December 12, 2024 10:06
@ferdnyc
Copy link
Contributor

ferdnyc commented Dec 17, 2024

@ewlsh

@eli-schwartz Additionally gi-compile-repository is only shipped since GLib 2.79.2 so LTS distributions don't have it yet. Ubuntu bionic, for example, would not.

Hmm. THAT makes it sound like the tooling should start with autodetecting the available compiler(s), and just automatically use what it finds.

Only when both compilers are available, would it even make sense to make it selectable. (And even then, only if there's a reason to continue using the old one even when the newer is also an option. Though it sounds like there may be, from your other comments.)

@eli-schwartz
Copy link
Member

gi-compile-repository should work as a "drop-in" replacement tool-wise but it does support newer GLib features (asynchronous annotations, for example) which could cause existing toolchains to fail to compile without code changes.

You're saying:

  • it's a drop-in replacement which also supports newer features
  • existing codebases could fail to compile their gi repositories unless they change their code to use the new features?

@eli-schwartz Additionally gi-compile-repository is only shipped since GLib 2.79.2 so LTS distributions don't have it yet. Ubuntu bionic, for example, would not.

Well yeah but inherent in this premise is that we only unconditionally use it when it exists, and the "unconditional" was a contrast to "require that it exists, and also require opting in to it".

Obviously I can't and couldn't possibly be suggesting that we modify meson to delete all support of g-ir-compiler and raise the minimum supported version of glib to 2.79.2?

Comment on lines 805 to 815
if not self.gir_dep:
self.gir_dep = state.dependency('gobject-introspection-1.0')
self.giscanner = self._find_tool(state, 'g-ir-scanner')
self.gicompiler = self._find_tool(state, 'g-ir-compiler')

if not self.gicompiler:
if use_gi_repository_compile and supports_girepository_2:
self.gicompiler = self._find_tool(state, 'gi-compile-repository')
else:
self.gicompiler = self._find_tool(state, 'g-ir-compiler')

return self.gir_dep, self.giscanner, self.gicompiler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation-wise, this is very problematic. The current design requires people to specify which compiler they want via a meson.build DSL keyword argument, but once passed for the first time it will cache the value globally.

This means for example that if you have a project which knows nothing about this new feature -- it supports meson 0.40.0, or more charitably, supports meson 1.6.0 -- it will configure to build a gir using g-ir-compiler, and then it invokes a subproject that has a minimum meson_version: '>=1.7.0' and makes heavy use of GIRepository 2.0 features and is simply incompatible with GIRepository 1.0... and fails to compile, even though it passes your use_gi_repository_compile: true kwarg, because meson simply detects that self.gicompiler is g-ir-compiler.

This is one of the reasons I was hoping it would be practical to simply use the newer tool by default. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants