diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0c4326a8762a..2316124e9b04 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1408,7 +1408,7 @@ def link(self, target): msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. " msg += "Use the 'pic' option to static_library to build with PIC." raise InvalidArguments(msg) - if self.for_machine is not t.for_machine: + if self.for_machine is not t.for_machine and (not t.uses_rust() 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}' if self.environment.is_cross_build(): raise InvalidArguments(msg + ' This is not possible in a cross build.') @@ -1432,7 +1432,7 @@ def link_whole(self, target): msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. " msg += "Use the 'pic' option to static_library to build with PIC." raise InvalidArguments(msg) - if self.for_machine is not t.for_machine: + if self.for_machine is not t.for_machine and (not t.uses_rust() 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}' if self.environment.is_cross_build(): raise InvalidArguments(msg + ' This is not possible in a cross build.') @@ -2328,6 +2328,13 @@ def process_kwargs(self, kwargs): else: raise InvalidArguments(f'Invalid rust_crate_type "{rust_crate_type}": must be a string.') if rust_crate_type == 'proc-macro': + if 'native' not in kwargs: + kwargs['native'] = True + if not kwargs.get('native', False): + if self.environment.is_cross_build(): + raise InvalidArguments('Rust "proc-macro" crate type requires "native: true". This will fail in a cross-build.') + else: + mlog.warning('Rust "proc-macro" crate type requires "native: true". This will fail in a cross-build.') FeatureNew.single_use('Rust crate type "proc-macro"', '0.62.0', self.subproject) def get_import_filename(self) -> T.Optional[str]: diff --git a/test cases/rust/18 proc-macro/meson.build b/test cases/rust/18 proc-macro/meson.build index 01c4cbe17569..09cde8314515 100644 --- a/test cases/rust/18 proc-macro/meson.build +++ b/test cases/rust/18 proc-macro/meson.build @@ -8,6 +8,7 @@ pm = shared_library( 'proc_macro_examples', 'proc.rs', rust_crate_type : 'proc-macro', + native: true, ) main = executable(