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

modules/rust: Specify the compiler version to bindgen when possible #14030

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions mesonbuild/modules/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class RustModule(ExtensionModule):
def __init__(self, interpreter: Interpreter) -> None:
super().__init__(interpreter)
self._bindgen_bin: T.Optional[T.Union[ExternalProgram, Executable, OverrideProgram]] = None
if 'rust' in interpreter.compilers.host:
self._bindgen_rust_target: T.Optional[str] = interpreter.compilers.host['rust'].version
else:
self._bindgen_rust_target = None
self.methods.update({
'test': self.test,
'bindgen': self.bindgen,
Expand Down Expand Up @@ -250,6 +254,15 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu

if self._bindgen_bin is None:
self._bindgen_bin = state.find_program('bindgen', wanted=kwargs['bindgen_version'])
if self._bindgen_rust_target is not None:
# ExternalCommand.command's type is bonkers
_, _, err = mesonlib.Popen_safe(
T.cast('T.List[str]', self._bindgen_bin.get_command()) +
['--rust-target', self._bindgen_rust_target])
# Sometimes this is "invalid Rust target" and sometimes "invalid
# rust target"
if 'Got an invalid' in err:
self._bindgen_rust_target = None

name: str
if isinstance(header, File):
Expand Down Expand Up @@ -317,9 +330,13 @@ def bindgen(self, state: ModuleState, args: T.List, kwargs: FuncBindgen) -> Modu
'@INPUT@', '--output',
os.path.join(state.environment.build_dir, '@OUTPUT0@')
] + \
kwargs['args'] + inline_wrapper_args + ['--'] + \
kwargs['c_args'] + clang_args + \
['-MD', '-MQ', '@INPUT@', '-MF', '@DEPFILE@']
kwargs['args'] + inline_wrapper_args
if self._bindgen_rust_target and '--rust-target' not in cmd:
cmd.extend(['--rust-target', self._bindgen_rust_target])
cmd.append('--')
cmd.extend(kwargs['c_args'])
cmd.extend(clang_args)
cmd.extend(['-MD', '-MQ', '@INPUT@', '-MF', '@DEPFILE@'])

target = CustomTarget(
f'rustmod-bindgen-{name}'.replace('/', '_'),
Expand Down
Loading