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.
pull/12983/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent c1076241af
commit 18f8aeda8b
  1. 23
      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]

Loading…
Cancel
Save