diff options
| author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-05-16 11:09:08 -0400 |
|---|---|---|
| committer | Xavier Claessens <xclaesse@gmail.com> | 2023-05-20 10:35:42 -0400 |
| commit | c6db870fc7fbc9f6c3098ff439d59b49f7255df2 (patch) | |
| tree | f1ca8ed43f69a162d01d6960d87611886e472177 /mesonbuild/compilers/rust.py | |
| parent | 01bb7564847dded2c9de756363c2ff97f0a02a8e (diff) | |
| download | meson-c6db870fc7fbc9f6c3098ff439d59b49f7255df2.tar.gz | |
rust: Add system libs used by rust std to staticlib external deps
Diffstat (limited to 'mesonbuild/compilers/rust.py')
| -rw-r--r-- | mesonbuild/compilers/rust.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index abdc2b354..450f65797 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -15,6 +15,7 @@ from __future__ import annotations import subprocess, os.path import textwrap +import re import typing as T from .. import coredata, mlog @@ -66,6 +67,7 @@ class RustCompiler(Compiler): self.base_options.update({OptionKey(o) for o in ['b_colorout', 'b_ndebug']}) if 'link' in self.linker.id: self.base_options.add(OptionKey('b_vscrt')) + self.native_static_libs: T.List[str] = [] def needs_static_linker(self) -> bool: return False @@ -100,6 +102,18 @@ class RustCompiler(Compiler): pe.wait() if pe.returncode != 0: raise EnvironmentException(f'Executables created by Rust compiler {self.name_string()} are not runnable.') + # 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(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] def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: return ['--dep-info', outfile] |
