Skip to content

modules/rust: use absolute path for bindgen input when output_inline_wrapper is set#15862

Open
simonfrechette-dev wants to merge 1 commit into
mesonbuild:masterfrom
simonfrechette-dev:fix-bindgen-output-inline-wrapper-absolute-path
Open

modules/rust: use absolute path for bindgen input when output_inline_wrapper is set#15862
simonfrechette-dev wants to merge 1 commit into
mesonbuild:masterfrom
simonfrechette-dev:fix-bindgen-output-inline-wrapper-absolute-path

Conversation

@simonfrechette-dev

Copy link
Copy Markdown

Summary

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 path relative to 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.

Real-world impact

Fix

When output_inline_wrapper is set and 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

…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
Copilot AI review requested due to automatic review settings May 30, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_arg that switches from @INPUT@ to an absolute path when output_inline_wrapper is set and the header is a File.
  • Add explanatory comments and link to meson issue #13227.
  • Use bindgen_input_arg in 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust bindgen with output_inline_wrapper create c file with incorrect include path if build directory is not inside source directory

3 participants