tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

OK to inject BUILDLINK_PASSTHRU_RPATHDIRS into lang/rust?



Hi,

I had a variant of this patch for quite some time, now after adaptation
for moved sources. It still seems to do the job: Making rustc link to
the toolchain libraries that I provide. Please ignore for now why the
toolchain doesn't add the paths itself. There are reasons for
BUILDLINK_PASSTHROUGH_RPATHDIRS and I use it to inject paths into the
normal builds.

Rust is different and needs explicit insertion of RPATH. We have a
patch for that. I propose to change it like this:

diff -ruN pkgsrc-2025Q1/lang/rust/patches/patch-src_bootstrap_src_core_builder.rs pkgsrc/lang/rust/patches/patch-src_bootstrap_src_core_builder.rs
--- pkgsrc-2025Q1/lang/rust/patches/patch-src_bootstrap_src_core_builder.rs     2025-04-02 05:01:42.000000000 +0200
+++ pkgsrc/lang/rust/patches/patch-src_bootstrap_src_core_builder.rs    2025-04-11 16:45:22.543345358 +0200
@@ -2,6 +2,8 @@

 Find external libunwind and libLLVM on pkgsrc (not just Linux).
 Use @PREFIX@ in rpath.
+Also pass along our configured RPATH directories from the environment
+(for example supporting custom toolchain).

 Also, follow up on
 https://github.com/rust-lang/rust/issues/133629 by applying
@@ -40,11 +42,17 @@
          Cargo {
              command: cargo,
              compiler,
-@@ -2617,7 +2624,7 @@ impl Cargo {
+@@ -2617,7 +2624,13 @@ impl Cargo {
                  Some(format!("-Wl,-rpath,@loader_path/../{libdir}"))
              } else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") {
                  self.rustflags.arg("-Clink-args=-Wl,-z,origin");
 -                Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}"))
++                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() {
++                    self.rustflags.arg(&format!("-Clink-args=-Wl,-rpath,{}", p));
++                }
 +                Some(format!("-Wl,-rpath,@PREFIX@/lib"))
              } else {
                  None

I had this code already in 2023 at least, where this block as at a
different location, but still bootstrap*builder.rs. It works for me to
insert my list of paths into rustc, for example:

$ readelf -d .prefix/bin/rustc |grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [/sw/env/gcc-13.2.0_openmpi-4.1.6/pkgsrc/2025Q1-devel/lib:/sw/env/gcc-13.2.0/openmpi/4.1.6/lib/openmpi:/sw/env/gcc-13.2.0/openmpi/4.1.6/lib:/sw/compiler/gcc-13.2.0/lib64:/sw/compiler/gcc-13.2.0/lib]

I see one detail differing from my earlier patch. Before, we had 

 +                Some(format!("-Wl,-rpath,@PREFIX@/{libdir}"))

instead of a plain /lib. I wonder if that should also be the case again.

Ideally, I would like to have some facility to insert rpaths upstreamed
to rust. But for some reason not even the @PREFIX@ part got in. Or did
nobody try? I can only hope that this is the one and only place that
matters and it's the right way. I didn't ever code something in rust
besides hacking its toolchain, truly cargo-coding here;-)



Alrighty then,

Thomas

-- 
Dr. Thomas Orgis
Universität Hamburg
Regionales Rechenzentrum / Regional Computing Center
Basis-Infrastruktur / Basic Infrastructure
High-Performance Computing

Schlüterstr. 70
20146 Hamburg

Tel.: +49 40 42838 8826
E-Mail: thomas.orgis%uni-hamburg.de@localhost
Team: hpc%uni-hamburg.de@localhost
https://www.uni-hamburg.de
https://www.rrz.uni-hamburg.de

Attachment: smime.p7s
Description: S/MIME cryptographic signature



Home | Main Index | Thread Index | Old Index