Skip to content

Commit 9f3f88f

Browse files
bonzinidcbaker
authored andcommitted
rust: fix computation of library directory
Using a rustup-based toolchain fails the "rust/2 sharedlib" test for me: ./prog: error while loading shared libraries: libstd-211931512faabf29.so: cannot open shared object file: No such file or directory This happens because recent rustup places the standard library under SYSROOT/lib/rustlib/TARGET/lib. Retrieve the right directory using "--print target-libdir". This also provides a more accurate version for rustc installed in /usr. Before: $ echo $(/usr/bin/rustc --print sysroot)/lib /usr/lib After: $ /usr/bin/rustc --print target-libdir /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib While at it, cache the value to avoid repeated process invocation. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 69af44d commit 9f3f88f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,7 @@ def _link_library(libname: str, static: bool, bundle: bool = False):
21252125
# ... but then add rustc's sysroot to account for rustup
21262126
# installations
21272127
for rpath_arg in rpath_args:
2128-
args += ['-C', 'link-arg=' + rpath_arg + ':' + os.path.join(rustc.get_sysroot(), 'lib')]
2128+
args += ['-C', 'link-arg=' + rpath_arg + ':' + rustc.get_target_libdir()]
21292129

21302130
proc_macro_dylib_path = None
21312131
if getattr(target, 'rust_crate_type', '') == 'proc-macro':

mesonbuild/compilers/rust.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,18 @@ def _native_static_libs(self, work_dir: str, source_name: str) -> None:
142142
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
143143
return ['--dep-info', outfile]
144144

145+
@functools.lru_cache(maxsize=None)
145146
def get_sysroot(self) -> str:
146147
cmd = self.get_exelist(ccache=False) + ['--print', 'sysroot']
147148
p, stdo, stde = Popen_safe_logged(cmd)
148149
return stdo.split('\n', maxsplit=1)[0]
149150

151+
@functools.lru_cache(maxsize=None)
152+
def get_target_libdir(self) -> str:
153+
cmd = self.get_exelist(ccache=False) + ['--print', 'target-libdir']
154+
p, stdo, stde = Popen_safe_logged(cmd)
155+
return stdo.split('\n', maxsplit=1)[0]
156+
150157
@functools.lru_cache(maxsize=None)
151158
def get_crt_static(self) -> bool:
152159
cmd = self.get_exelist(ccache=False) + ['--print', 'cfg']

0 commit comments

Comments
 (0)