Skip to content

Commit

Permalink
rust: Require native: true for proc-macro targets and allow linki…
Browse files Browse the repository at this point in the history
…ng into targets for other platforms

proc-macros are basically compiler extensions and must be compiled for
the build machine so that the compiler can load and execute it at
runtime.

Without this, cross-compilation of targets that use proc-macro
dependencies is going to fail.

Fixes #11702
  • Loading branch information
sdroege committed Apr 27, 2023
1 parent 01420bf commit 13f3a7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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.')
Expand Down Expand Up @@ -2328,6 +2328,8 @@ 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 not kwargs.get('native', False):
raise InvalidArguments(f'Rust "proc-macro" crate type requires "native: true".')
FeatureNew.single_use('Rust crate type "proc-macro"', '0.62.0', self.subproject)

def get_import_filename(self) -> T.Optional[str]:
Expand Down
1 change: 1 addition & 0 deletions test cases/rust/18 proc-macro/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pm = shared_library(
'proc_macro_examples',
'proc.rs',
rust_crate_type : 'proc-macro',
native: true,
)

main = executable(
Expand Down

0 comments on commit 13f3a7f

Please sign in to comment.