Rust: Fix proc-macro usage when cross compiling

Force BUILD machine and allow to link with HOST machine.
pull/12276/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent 7592003484
commit c6f33aed2d
  1. 2
      mesonbuild/build.py
  2. 4
      mesonbuild/interpreter/interpreter.py

@ -1474,7 +1474,7 @@ class BuildTarget(Target):
links_with_rust_abi = isinstance(t, BuildTarget) and t.uses_rust_abi() links_with_rust_abi = isinstance(t, BuildTarget) and t.uses_rust_abi()
if not self.uses_rust() and links_with_rust_abi: if not self.uses_rust() and links_with_rust_abi:
raise InvalidArguments(f'Try to link Rust ABI library {t.name!r} with a non-Rust target {self.name!r}') raise InvalidArguments(f'Try to link Rust ABI library {t.name!r} with a non-Rust target {self.name!r}')
if self.for_machine is not t.for_machine: if self.for_machine is not t.for_machine and (not links_with_rust_abi or t.rust_crate_type != 'proc-macro'):
msg = f'Tried to mix libraries for machines {self.for_machine} and {t.for_machine} in target {self.name!r}' msg = f'Tried to mix libraries for machines {self.for_machine} and {t.for_machine} in target {self.name!r}'
if self.environment.is_cross_build(): if self.environment.is_cross_build():
raise InvalidArguments(msg + ' This is not possible in a cross build.') raise InvalidArguments(msg + ' This is not possible in a cross build.')

@ -3247,6 +3247,10 @@ class Interpreter(InterpreterBase, HoldableObject):
name, sources = args name, sources = args
for_machine = self.machine_from_native_kwarg(kwargs) for_machine = self.machine_from_native_kwarg(kwargs)
if kwargs.get('rust_crate_type') == 'proc-macro':
# Silently force to native because that's the only sensible value
# and rust_crate_type is deprecated any way.
for_machine = MachineChoice.BUILD
if 'sources' in kwargs: if 'sources' in kwargs:
sources += listify(kwargs['sources']) sources += listify(kwargs['sources'])
if any(isinstance(s, build.BuildTarget) for s in sources): if any(isinstance(s, build.BuildTarget) for s in sources):

Loading…
Cancel
Save