mirror of
https://github.com/mesonbuild/meson.git
synced 2026-11-06 05:16:42 +00:00
rust: only add rustc's sysroot to the rpath when Rust dylibs are linked
The sysroot's target libdir was added to the build rpath of every Rust target that links any shared library, to make dynamically linked Rust dylibs (and libstd with -C prefer-dynamic) from rustup installations work. It was not marked for removal at install time, so every installed Rust program that links a C shared library ended up with the toolchain's library directory in its runpath, and 'meson install' fails outright whenever install_rpath is longer than the build-time rpath, because the leftover entry has to fit next to it: New rpath must not be longer than the old one. Old: $ORIGIN/../shared:/home/user/.rustup/.../rustlib/x86_64-unknown-linux-gnu/lib New: /usr/lib/x86_64-linux-gnu/systemd:/home/user/.rustup/.../lib Only add the sysroot when the target actually links Rust dylibs. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
1 parent
524db46e29
commit
c65cf102d5
2 files changed
+12
-5
No files matched your search
@@ -2277,7 +2277,14 @@ class NinjaBackend(backends.Backend):
|
||||
if has_rust_shared_deps:
|
||||
args += ['-C', 'prefer-dynamic']
|
||||
if has_shared_deps or has_rust_shared_deps:
|
||||
args += self.get_build_rpath_args(target, rustc)
|
||||
# rustc's sysroot is only needed to find Rust dylibs (and a
|
||||
# dynamically linked libstd) from rustup installations. A program
|
||||
# that links libstd statically must not carry the toolchain's
|
||||
# library directory in its runpath, and the entry also cannot be
|
||||
# removed at install time, which makes 'meson install' fail when
|
||||
# install_rpath is longer than the build-time rpath.
|
||||
extra_paths = [rustc.get_target_libdir()] if has_rust_shared_deps else None
|
||||
args += self.get_build_rpath_args(target, rustc, extra_paths)
|
||||
|
||||
return deps, project_deps, args
|
||||
|
||||
@@ -3815,7 +3822,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
|
||||
self.add_build(elem)
|
||||
return obj_list
|
||||
|
||||
def get_build_rpath_args(self, target: build.BuildTarget, linker: T.Union[Compiler, StaticLinker]) -> T.List[str]:
|
||||
def get_build_rpath_args(self, target: build.BuildTarget, linker: T.Union[Compiler, StaticLinker],
|
||||
extra_paths: T.Optional[T.List[str]] = None) -> T.List[str]:
|
||||
if has_path_sep(target.name):
|
||||
# Target names really should not have slashes in them, but
|
||||
# unfortunately we did not check for that and some downstream projects
|
||||
@@ -3827,7 +3835,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
|
||||
(rpath_args, target.rpath_dirs_to_remove) = (
|
||||
linker.build_rpath_args(self.environment.get_build_dir(),
|
||||
target_slashname_workaround_dir,
|
||||
target))
|
||||
target, extra_paths))
|
||||
return rpath_args
|
||||
|
||||
def generate_link(self, target: build.BuildTarget, outname: str, obj_list: T.List[str],
|
||||
|
||||
@@ -377,9 +377,8 @@ class RustCompiler(Compiler):
|
||||
def build_rpath_args(self, build_dir: str, from_dir: str, target: BuildTarget,
|
||||
extra_paths: T.Optional[T.List[str]] = None
|
||||
) -> T.Tuple[T.List[str], T.Set[bytes]]:
|
||||
# add rustc's sysroot to account for rustup installations
|
||||
args, to_remove = super().build_rpath_args(
|
||||
build_dir, from_dir, target, [self.get_target_libdir()])
|
||||
build_dir, from_dir, target, extra_paths)
|
||||
return rustc_link_args(args), to_remove
|
||||
|
||||
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
|
||||
|
||||
Reference in new issue
Block a user