rust-lang/cargo

cargo install does not respect LDFLAGS

Closed this issue · 9 comments

When the building system has LDFLAGS set, cargo / rustc should respect the system's LDFLAGS

Right now Cargo respects RUSTFLAGS but that's the only env var for passing flags down. What sort of LDFLAGS are you thinking of?

Note that the exact linker that the compiler invokes isn't guaranteed to not change over time, so there's not always a valid interpretation of LDFLAGS even if it exists.

Sorry for the delay, @sergiusens would be able to go into more depth on the specifics. The goal was to get a Rust project built into a Snap with Snapcraft but the built binary wasn't using the correct libraries

where are RUSTFLAGS documented? The linker flags we want to pass on are runpath/rpath related as well as the one that sets the linker loader the binary should use.

expanding a bit on this, some issues we're having with getting this working: https://gist.github.com/ChrisMacNaughton/a81233e05995013ebb9a0c333c157b76

stale commented

As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it.

I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect?

The team would be especially grateful if such a comment included details such as:

  • Is this still relevant?
  • If so, what is blocking it?
  • Is it known what could be done to help move this forward?

Thank you for contributing!

(The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.)

If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable!

stale commented

As I didn't see any updates in 30 days I'm going to close this. Please see the previous comment for more information!

A simple question related to this issue.

I need to send the options -Wl,-rpath,/data0/opt/miniconda3/envs/env_hg_rust/lib -Wl,-rpath-link,/data0/opt/miniconda3/envs/env_hg_rust/lib to the linker.

Is it possible to do that with an environment variable (I don't control the cargo or rustc command)?

I can use RUSTFLAGS for things like -L/data0/opt/miniconda3/envs/env_hg_rust/lib but what about more advanced linker options?

I'm running into a related issue - we have --coverage (amongst other things) set in our CFLAGS. For some build script builds this is resulting in link errors such as undefined symbol: llvm_gcov_init because --coverage isn't also being passed to the link step as well. Leaving aside the question of whether or not CFLAGS should be having an effect on a build script build, there are several similar flags which will cause problems if used in CFLAGS (which usually applies because it's consumed by something like cc::Build in a build script) but not in LDFLAGS, for example -fopenmp or -flto. Particularly in a context where cargo is being used as one step in a larger build process, honoring CFLAGS but not LDFLAGS can cause all kinds of problems.