summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/rust.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-12-04 17:02:01 -0800
committerXavier Claessens <xclaesse@gmail.com>2024-03-15 11:38:54 -0400
commit18f8aeda8b59a132f24fa1af800ff65cac2f61f4 (patch)
tree8ee7e9f4923836ba3e93dd51a237a3f0cf0638f7 /mesonbuild/compilers/rust.py
parentc1076241af11f10acac28d771688bb54c6b0b340 (diff)
downloadmeson-18f8aeda8b59a132f24fa1af800ff65cac2f61f4.tar.gz
rust: Get native-static-libs even when it cannot run host binaries
When rustc cannot run host binaries it does an early return which skipped getting native-static-libs. Move that code earlier to always run it. While at it, failing to determine those libs is a fatal error. We would crash later when trying to access rustc.native_static_libs attribute otherwise.
Diffstat (limited to 'mesonbuild/compilers/rust.py')
-rw-r--r--mesonbuild/compilers/rust.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index f557e89fa..65f4ac1b1 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -84,6 +84,7 @@ class RustCompiler(Compiler):
pc, stdo, stde = Popen_safe_logged(cmdlist, cwd=work_dir)
if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
+ self._native_static_libs(work_dir, source_name)
if environment.need_exe_wrapper(self.for_machine):
if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
@@ -95,18 +96,22 @@ class RustCompiler(Compiler):
pe.wait()
if pe.returncode != 0:
raise EnvironmentException(f'Executables created by Rust compiler {self.name_string()} are not runnable.')
+
+ def _native_static_libs(self, work_dir: str, source_name: str) -> None:
# Get libraries needed to link with a Rust staticlib
cmdlist = self.exelist + ['--crate-type', 'staticlib', '--print', 'native-static-libs', source_name]
p, stdo, stde = Popen_safe_logged(cmdlist, cwd=work_dir)
- if p.returncode == 0:
- match = re.search('native-static-libs: (.*)$', stde, re.MULTILINE)
- if match:
- # Exclude some well known libraries that we don't need because they
- # are always part of C/C++ linkers. Rustc probably should not print
- # them, pkg-config for example never specify them.
- # FIXME: https://github.com/rust-lang/rust/issues/55120
- exclude = {'-lc', '-lgcc_s', '-lkernel32', '-ladvapi32'}
- self.native_static_libs = [i for i in match.group(1).split() if i not in exclude]
+ if p.returncode != 0:
+ raise EnvironmentException('Rust compiler cannot compile staticlib.')
+ match = re.search('native-static-libs: (.*)$', stde, re.MULTILINE)
+ if not match:
+ raise EnvironmentException('Failed to find native-static-libs in Rust compiler output.')
+ # Exclude some well known libraries that we don't need because they
+ # are always part of C/C++ linkers. Rustc probably should not print
+ # them, pkg-config for example never specify them.
+ # FIXME: https://github.com/rust-lang/rust/issues/55120
+ exclude = {'-lc', '-lgcc_s', '-lkernel32', '-ladvapi32'}
+ self.native_static_libs = [i for i in match.group(1).split() if i not in exclude]
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return ['--dep-info', outfile]