Skip to content

Commit

Permalink
rust: fix computation of library directory
Browse files Browse the repository at this point in the history
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 <pbonzini@redhat.com>
  • Loading branch information
bonzini authored and dcbaker committed Nov 20, 2024
1 parent 69af44d commit 9f3f88f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ def _link_library(libname: str, static: bool, bundle: bool = False):
# ... but then add rustc's sysroot to account for rustup
# installations
for rpath_arg in rpath_args:
args += ['-C', 'link-arg=' + rpath_arg + ':' + os.path.join(rustc.get_sysroot(), 'lib')]
args += ['-C', 'link-arg=' + rpath_arg + ':' + rustc.get_target_libdir()]

proc_macro_dylib_path = None
if getattr(target, 'rust_crate_type', '') == 'proc-macro':
Expand Down
7 changes: 7 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ def _native_static_libs(self, work_dir: str, source_name: str) -> None:
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return ['--dep-info', outfile]

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

@functools.lru_cache(maxsize=None)
def get_target_libdir(self) -> str:
cmd = self.get_exelist(ccache=False) + ['--print', 'target-libdir']
p, stdo, stde = Popen_safe_logged(cmd)
return stdo.split('\n', maxsplit=1)[0]

@functools.lru_cache(maxsize=None)
def get_crt_static(self) -> bool:
cmd = self.get_exelist(ccache=False) + ['--print', 'cfg']
Expand Down

0 comments on commit 9f3f88f

Please sign in to comment.