mesonbuild/meson

gnome.generate_gir crashing in C++ subproject with meson >= 1.2.0

JoseExposito opened this issue · 6 comments

Describe the bug

Compiling a C++ subproject with meson >= 1.2.0 is generating this crash:

Executing subproject libtouche 

libtouche| Project name: libtouche
libtouche| Project version: 2.0.0
libtouche| C++ compiler for the host machine: c++ (gcc 13.2.1 "c++ (GCC) 13.2.1 20230801")
libtouche| C++ linker for the host machine: c++ ld.bfd 2.41.0
libtouche| Found pkg-config: /usr/bin/pkg-config (1.8.1)
libtouche| Run-time dependency glib-2.0 found: YES 2.76.4
libtouche| Run-time dependency gobject-2.0 found: YES 2.76.4
libtouche| Run-time dependency x11 found: YES 1.8.6
libtouche| Run-time dependency gobject-introspection-1.0 found: YES 1.76.1
libtouche| Dependency gobject-introspection-1.0 found: YES 1.76.1 (cached)
libtouche| Program g-ir-scanner found: YES (/usr/bin/g-ir-scanner)
libtouche| Dependency gobject-introspection-1.0 found: YES 1.76.1 (cached)
libtouche| Program g-ir-compiler found: YES (/usr/bin/g-ir-compiler)
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/mesonbuild/mesonmain.py", line 194, in run
    return options.run_func(options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 358, in run
    app.generate()
  File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 183, in generate
    return self._generate(env, capture, vslite_ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 228, in _generate
    intr.run()
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 2997, in run
    super().run()
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 164, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 190, in evaluate_codeblock
    raise e
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 182, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 196, in evaluate_statement
    return self.function_call(cur)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 521, in function_call
    res = func(node, func_args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 277, in wrapper
    return f(*nargs, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 596, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 878, in func_subproject
    return self.do_subproject(args[0], 'meson', kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 959, in do_subproject
    raise e
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 943, in do_subproject
    return self._do_subproject_meson(subp_name, subdir, default_options, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 986, in _do_subproject_meson
    subi.run()
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 2997, in run
    super().run()
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 164, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 190, in evaluate_codeblock
    raise e
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 182, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
    return self.method_call(cur)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 550, in method_call
    res = obj.method_call(method_name, args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreterobjects.py", line 811, in method_call
    ret = method(state, args, kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 277, in wrapper
    return f(*nargs, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 596, in wrapper
    return f(*wrapped_args, **wrapped_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/modules/gnome.py", line 1204, in generate_gir
    scan_target = self._make_gir_target(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mesonbuild/modules/gnome.py", line 972, in _make_gir_target
    cc_exelist = state.environment.coredata.compilers.host['c'].get_exelist()
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
KeyError: 'c'

subprojects/libtouche/meson.build:37:6: ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

I believe that the commit causing this issue is: bf44120

And it is included in 1.2.0 and 1.2.1:

$ git tag --contains bf44120a4f272652f98c607bd05065e8a0492d3a
1.2.0
1.2.0rc1
1.2.0rc2
1.2.0rc3
1.2.1

I tested it with meson <= 1.1.1 and it works.

To Reproduce

Here is the meson file, highlighted in the line that is crashing:
https://github.com/JoseExposito/touche/blob/master/subprojects/libtouche/meson.build#L37

Detailed instructions about how to compile the project are available here:
https://github.com/JoseExposito/touche/blob/master/HACKING.md

Upstream bug report: JoseExposito/touche#92

System parameters

  • Is this a cross build or just a plain native build (for the same computer)? Plain native build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.): Fedora 38
  • what Python version are you using: Python 3.11.4
  • what meson --version: >= 1.2.0
  • what ninja --version: 1.11.1

The reason it crash is because you only add cpp language and not c. I'm not sure if gir always require aC compiler or if there is a way to work only with C++

Maybe what gir was doing in that case was finding its own C compiler completely independent of what C++ compiler meson used, generating its own blackbox output, and yielding to the pure C++ project...

It doesn't seem very safe, probably breaks at least cross compilation. The bug that that commit closed, also mentions failing to find GCC entirely.

The question is whether meson should check for a C compiler and error out if you need one but don't specify one, or whether it should implicitly add one for you.

We have precedent for adding C compiler implicitly, when doing Vala or cython for example. I think gir could be another case for that. Seems safer in case of cross compilation indeed.

This is a regression in generate_gir() but has always been crashing in gtkdoc(). Made a fix in #12164.

Thanks a lot for the quick fix!

Just in case anyone else finds this issue, it is possible to workaround it and make you code compile with any meson version with a change similar to JoseExposito/touche@b1cc9a2