diff options
| author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-23 16:03:10 -0400 |
|---|---|---|
| committer | Xavier Claessens <xclaesse@gmail.com> | 2023-09-19 13:54:49 -0400 |
| commit | 759200348476752b304ffca0cb3737a5b61f9137 (patch) | |
| tree | 5f6c43f1dd6e45949f8e2c902e6de278b774dffa /mesonbuild/build.py | |
| parent | bdf1f3c0e2a772a81fd6a19ec1a2f495948406fc (diff) | |
| download | meson-759200348476752b304ffca0cb3737a5b61f9137.tar.gz | |
Rust: Prevent linking Rust ABI with C library/executable
Diffstat (limited to 'mesonbuild/build.py')
| -rw-r--r-- | mesonbuild/build.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5820b5076..9a87225dd 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1408,12 +1408,7 @@ class BuildTarget(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: - 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.') - else: - mlog.warning(msg + ' This will fail in cross build.') + self.check_can_link_together(t) self.link_targets.append(t) def link_whole(self, targets, promoted: bool = False): @@ -1429,12 +1424,7 @@ class BuildTarget(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: - 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.') - else: - mlog.warning(msg + ' This will fail in cross build.') + self.check_can_link_together(t) if isinstance(self, StaticLibrary) and not self.uses_rust(): # When we're a static library and we link_whole: to another static # library, we need to add that target's objects to ourselves. @@ -1480,6 +1470,17 @@ class BuildTarget(Target): f' and thus has to include objects from {t.name!r} to be usable.') raise InvalidArguments(m) + def check_can_link_together(self, t: BuildTargetTypes) -> None: + links_with_rust_abi = isinstance(t, BuildTarget) and t.uses_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}') + if self.for_machine is not t.for_machine: + 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.') + else: + mlog.warning(msg + ' This will fail in cross build.') + def add_pch(self, language: str, pchlist: T.List[str]) -> None: if not pchlist: return @@ -1645,6 +1646,9 @@ class BuildTarget(Target): def uses_rust(self) -> bool: return 'rust' in self.compilers + def uses_rust_abi(self) -> bool: + return self.uses_rust() and self.rust_crate_type in {'dylib', 'rlib', 'proc-macro'} + def uses_fortran(self) -> bool: return 'fortran' in self.compilers |
