modules/rust: use absolute path for bindgen input when output_inline_wrapper is set#15862
Open
simonfrechette-dev wants to merge 1 commit into
Conversation
…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 "<whatever-was-passed-as-input>" 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 mesonbuild#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: mesonbuild#13227
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adjusts the Rust bindgen() wrapper generation to avoid broken #include paths when output_inline_wrapper is enabled by ensuring the header path used inside the generated wrapper is absolute in relevant cases.
Changes:
- Introduce a
bindgen_input_argthat switches from@INPUT@to an absolute path whenoutput_inline_wrapperis set and the header is aFile. - Add explanatory comments and link to meson issue #13227.
- Use
bindgen_input_argin the bindgen command invocation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+942
to
+946
| 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', |
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
output_inline_wrapperis used, bindgen embeds the input header path verbatim as an#includein the generated wrapper.cfile:If the input is
@INPUT@(a path relative to the build root, e.g.../src/foo.h), this#includebreaks compilation whenever the generated.cfile resides in a subdirectory of the build root, because GCC resolves the include relative to the.cfile's directory rather than the build root.Real-world impact
mesa-9999-abi_x86_32.x86/). The 64-bit pass succeeds but the 32-bit pass fails with:fatal error: ../mesa-9999/src/compiler/rust/bindings.h: No such file or directorymesa-gitAUR package (see Rust bindgen with output_inline_wrapper create c file with incorrect include path if build directory is not inside source directory #13227)Fix
When
output_inline_wrapperis set andheaderis aFileobject, substitute the absolute path to the header instead of@INPUT@. Ninja's dependency tracking is unaffected because the header is still listed in theCustomTargetinputs.Fixes #13227