tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
rust and rpath
Hi,
I built rust for the first time in my toolchain setup and promptly got
into trouble because rust likes to hardcode RPATH into its binaries …
only one path, though. So, in my setup like this …
CXX=g++
FC=gfortran
GCCBASE=/sw/compiler/gcc-10.3.0
USE_NATIVE_GCC=yes
TOOLS_PLATFORM.cpp=/sw/compiler/gcc-10.3.0/bin/cpp
TOOLS_PLATFORM.ld=/sw/compiler/gcc-10.3.0/bin/ld
TOOLS_PLATFORM.readelf=/sw/compiler/gcc-10.3.0/bin/readelf
TOOLS_PLATFORM.strip=/sw/compiler/gcc-10.3.0/bin/strip
CFLAGS+= -I/sw/env/gcc-10.3.0/openmpi/4.1.1/include -I/sw/compiler/gcc-10.3.0/include
CFLAGS+= -I/sw/env/gcc-10.3.0/openmpi/4.1.1/include -I/sw/compiler/gcc-10.3.0/include
FFLAGS+=-march=native -O2 -fno-math-errno -ftree-vectorize -fallow-argument-mismatch
FCFLAGS=${FFLAGS}
LDFLAGS+= -L/sw/env/gcc-10.3.0/openmpi/4.1.1/lib/openmpi -L/sw/env/gcc-10.3.0/openmpi/4.1.1/lib -L/sw/compiler/gcc-10.3.0/lib64 -L/sw/compiler/gcc-10.3.0/lib
LDFLAGS+= -Wl,-R/sw/env/gcc-10.3.0/openmpi/4.1.1/lib/openmpi -Wl,-R/sw/env/gcc-10.3.0/openmpi/4.1.1/lib -Wl,-R/sw/compiler/gcc-10.3.0/lib64 -Wl,-R/sw/compiler/gcc-10.3.0/lib
BUILDLINK_PASSTHRU_DIRS+= /sw/env/gcc-10.3.0/openmpi/4.1.1/lib/openmpi /sw/env/gcc-10.3.0/openmpi/4.1.1/lib /sw/compiler/gcc-10.3.0/lib64 /sw/compiler/gcc-10.3.0/lib /sw/env/gcc-10.3.0/openmpi/4.1.1/include /sw/compiler/gcc-10.3.0/include
BUILDLINK_PASSTHRU_RPATHDIRS+= /sw/env/gcc-10.3.0/openmpi/4.1.1/lib/openmpi /sw/env/gcc-10.3.0/openmpi/4.1.1/lib /sw/compiler/gcc-10.3.0/lib64 /sw/compiler/gcc-10.3.0/lib
… to use my prepared build of gcc-10.3.0 and openmpi-4.1.1 (using
native MPI type), this hardcoding of only $PREFIX/lib into RPATH by
rust breaks things. Binaries miss the correct libstdc++.so, for
example. This applies to rustc itself already, as it links to llvm,
which needs to find the correct libstdc++. It would, actually get it
with it's correct RPATH due to BUILDLINK_PASSTHRU_RPATHDIRS … but not
if rustc pulls in a wrong one first.
My current hack is the attached patch, which adds
BUILDLINK_PASSTHRU_RPATHDIRS to the RPATH that rust uses — just like
the other builds in pkgsrc.
I got that recommendation as an alternative to hacking rustc's build
directly:
18:01 < tnn> except cargo.mk doesn't pass RUSTFLAGS in environment. If we move
MAKE_ENV+=RUSTFLAGS=${RUSTFLAGS:Q} into cargo.mk you should be able to do this in
mk.conf:
18:01 < tnn> RUSTFLAGS+=-C link-arg=-Wl,-R/opt/stuff/lib
18:01 < tnn> BUILDLINK_PASSTHRU_RPATHDIRS+=/opt/stuff/lib
I'd be fine with that, too. But first I'd like to understand what we'd
agree on being the best for all.
First: Are there objections against my use of
BUILDLINK_PASSTHRU_RPATHDIRS? Do you think it is correct to force its
contents into RPATH for rust, to match what the LDFLAGS would do on
other builds?
Maybe someone actually using rust could also weigh in … ideally, I'd
like it to just pick up LDFLAGS like everyone else, having such a
change upstreamed. Pkgsrc did start me on patching the builder.rs
directly, as there is already patching against ORIGIN;-)
Alrighty then,
Thomas
--
Dr. Thomas Orgis
HPC @ Universität Hamburg
diff -ruN pkgsrc-2021Q2/lang/rust/distinfo pkgsrc/lang/rust/distinfo
--- pkgsrc-2021Q2/lang/rust/distinfo 2021-06-13 14:19:16.000000000 +0200
+++ pkgsrc/lang/rust/distinfo 2021-07-22 14:54:28.727882601 +0200
@@ -140,7 +140,7 @@
SHA1 (patch-library_std_src_sys_unix_thread.rs) = f3af869fba5bc0ab8d28042f55fe830f93b8ef54
SHA1 (patch-library_unwind_build.rs) = 7ece6de566ead1d9aae490ba91d81ac2d0bc50a8
SHA1 (patch-src_bootstrap_bootstrap.py) = ca87e6c58f34835b420a63a18ca95605a18657c6
-SHA1 (patch-src_bootstrap_builder.rs) = d075aacb6b51b4786e66fed14aa8727106ade201
+SHA1 (patch-src_bootstrap_builder.rs) = 6dfc772f6c343f1046db222dd82877f308f97d3d
SHA1 (patch-src_bootstrap_compile.rs) = 86fe55d04f7a8c5ec05dbdcb0fe5a0d6c07584d5
SHA1 (patch-src_bootstrap_lib.rs) = 3277f2be69a269ac761a2a6ab4d5389d121e6ca6
SHA1 (patch-src_llvm-project_llvm_CMakeLists.txt) = 23c0f170cf328b3e15bc2c520f5a16af75247ea7
diff -ruN pkgsrc-2021Q2/lang/rust/Makefile pkgsrc/lang/rust/Makefile
--- pkgsrc-2021Q2/lang/rust/Makefile 2021-06-13 14:19:16.000000000 +0200
+++ pkgsrc/lang/rust/Makefile 2021-07-22 09:16:15.328980477 +0200
@@ -361,6 +361,7 @@
SUBST_FILES.rpath+= src/bootstrap/builder.rs
SUBST_FILES.rpath+= src/bootstrap/compile.rs
SUBST_VARS.rpath= PREFIX
+SUBST_VARS.rpath+= BUILDLINK_PASSTHRU_RPATHDIRS
#
# Generate list of subst entries for various .cargo-checksum.json files. These
diff -ruN pkgsrc-2021Q2/lang/rust/patches/patch-src_bootstrap_builder.rs pkgsrc/lang/rust/patches/patch-src_bootstrap_builder.rs
--- pkgsrc-2021Q2/lang/rust/patches/patch-src_bootstrap_builder.rs 2021-05-31 12:17:53.000000000 +0200
+++ pkgsrc/lang/rust/patches/patch-src_bootstrap_builder.rs 2021-07-22 14:53:52.487822909 +0200
@@ -5,7 +5,7 @@
Fix RPATH for pkgsrc.
---- src/bootstrap/builder.rs.orig 2021-05-03 20:57:16.000000000 +0000
+--- src/bootstrap/builder.rs.orig 2021-05-09 02:52:39.000000000 +0000
+++ src/bootstrap/builder.rs
@@ -484,7 +484,6 @@ impl<'a> Builder<'a> {
install::Clippy,
@@ -15,11 +15,17 @@
install::Rustc
),
Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest),
-@@ -1106,7 +1105,7 @@ impl<'a> Builder<'a> {
+@@ -1106,7 +1105,13 @@ impl<'a> Builder<'a> {
rustflags.arg("-Zosx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib")
} else if !target.contains("windows") {
- Some("-Wl,-rpath,$ORIGIN/../lib")
++ let s = "@BUILDLINK_PASSTHRU_RPATHDIRS@".to_string();
++ let mut more_paths:Vec<_> = s.split_whitespace().collect();
++ more_paths.reverse(); // To have correct order when pop()ing.
++ while let Some(p) = more_paths.pop() {
++ rustflags.arg(&format!("-Clink-args=-Wl,-rpath,{}", p));
++ }
+ Some("-Wl,-rpath,@PREFIX@/lib")
} else {
None
Home |
Main Index |
Thread Index |
Old Index