From 6af4e0b30034a5b3406e354b644523a03acd21a5 Mon Sep 17 00:00:00 2001 From: simonfrechette-dev Date: Sat, 30 May 2026 11:40:31 -0500 Subject: [PATCH] modules/rust: use absolute path for bindgen input when output_inline_wrapper is set When output_inline_wrapper is used, bindgen embeds the input header path verbatim as an #include in the generated wrapper .c file: #include "" If the input is @INPUT@ (a relative path from the build root, e.g. ../src/foo.h), this #include breaks compilation whenever the generated .c file resides in a subdirectory of the build root, because GCC resolves the include relative to the .c file's directory rather than the build root. This is a real-world failure on Gentoo Linux, where multilib/ABI builds use a sub-directory build tree (e.g. mesa-9999-abi_x86_32.x86/), and was also reported by Arch Linux users building mesa-git (issue #13227). Fix: when output_inline_wrapper is set and the header is a File object, substitute the absolute path to the header instead of @INPUT@. Ninja's dependency tracking is unaffected because the header is still listed in the CustomTarget inputs. Fixes: #13227 --- mesonbuild/modules/rust.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index d07f7fcdb3f4..1b20a6621bd5 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -932,9 +932,22 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu '--wrap-static-fns-path', os.path.join(state.environment.build_dir, '@OUTPUT1@') ] + # When output_inline_wrapper is set, bindgen embeds the input path + # verbatim as an #include in the generated wrapper .c file. A relative + # path (from @INPUT@) breaks compilation when the generated file is in + # a build subdirectory, because GCC resolves the include relative to + # the .c file's directory rather than the build root. Use an absolute + # path so the generated #include is always valid. See also: + # https://github.com/mesonbuild/meson/issues/13227 + if kwargs['output_inline_wrapper'] and isinstance(header, File): + bindgen_input_arg: T.Union[str, File] = header.absolute_path( + state.environment.source_dir, state.environment.build_dir) + else: + bindgen_input_arg = '@INPUT@' + cmd = self._bindgen_bin.get_command() + \ [ - '@INPUT@', '--output', + bindgen_input_arg, '--output', os.path.join(state.environment.build_dir, '@OUTPUT0@') ] + \ kwargs['args'] + inline_wrapper_args