These are chat archives for rust-lang/rust

16th
Jan 2016
Igor
@target-san
Jan 16 2016 09:56
Does anyone know whether it's possible to pass custom linker flags to rustc? Preferably via Cargo, and most preferably based on current platform. F.e. I'm linking with custom proprietary shared lib, which I wanna keep in the same folder as executable; for this, LD has -rpath $ORIGIN, and GCC allows to pass it down via -Wl. But Rust seems to only have #[link_args], which are nightly.
Igor
@target-san
Jan 16 2016 10:01
Correction. There's -C link-args, -C rpath compiler args for this purpose. Though it's still unknown how to pass them via Cargo.
Jarred Nicholls
@jnicholls
Jan 16 2016 14:35
@target-san you use a build.rs to specify additional linker options if necessary.
Igor
@target-san
Jan 16 2016 14:44
I haven't found way to do so. Build script can add -l, -L, --cfg
But not arbitrary option.
Jarred Nicholls
@jnicholls
Jan 16 2016 15:48
cargo build can pass arbitrary options I think
Igor
@target-san
Jan 16 2016 15:55
yup, it can via cargo rustc, but that's another set of square wheels, sadly
it means I'll have to configure command each time I compile
Jarred Nicholls
@jnicholls
Jan 16 2016 15:59
What exactly are you trying to pass?
Jarred Nicholls
@jnicholls
Jan 16 2016 16:06
A lot of options and cfgs can be managed in cargo profiles or features
Note that cargo is not a replacement for e.g. Makefiles
If you have an unusual requirement, write a make file that calls cargo rustc.
If you need other crates to depend on your crate, provide a build.rs to run the Makefiles etc.
Lots of examples of this, e.g. any of the -sys wrapper crates from Alex Crichton
Igor
@target-san
Jan 16 2016 16:14
-C link-args="-Wl,-rpath,\$ORIGIN", which is a common way to enable SO search alongside binary
AFAIK build.rs doesn't allow modifying link phase
Igor
@target-san
Jan 16 2016 16:50
BTW, does anyone know why Rust adds RPATHs to its libs directory? Aren't they statically linked?
Peter Atashian
@retep998
Jan 16 2016 18:01
@target-san Because plugins dynamically link to them, and people can still do -Cprefer-dynamic