Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: options -C bitcode-in-rlib=no and -C lto are incompatible #71848

Closed
chinedufn opened this issue May 3, 2020 · 8 comments
Closed

error: options -C bitcode-in-rlib=no and -C lto are incompatible #71848

chinedufn opened this issue May 3, 2020 · 8 comments
Labels
C-bug Category: This is a bug. relnotes Marks issues that should be documented in the release notes of the next release. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@chinedufn
Copy link
Contributor

chinedufn commented May 3, 2020

I recently updated to the latest nightly a couple of days ago and started getting an error when trying to build a crate.

error: options `-C bitcode-in-rlib=no` and `-C lto` are incompatible

The build command that I'm using is:

RUSTFLAGS="-C lto" cargo build -p my-crate-name --target x86_64-unknown-linux-gnu --release

Version info (I've tried this on MacOS as well, also fails)

$ rustc -V
rustc 1.45.0-nightly (7f65393b9 2020-05-01)
$ cargo -V
cargo 1.45.0-nightly (258c89644 2020-04-30)
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.8 (stretch)
Release:	9.8
Codename:	stretch

I see that there was some recent work around optimizing bitcode in rlibs (example: #66961 ), so that could be related but I'm not sure.


As far as I can tell I'm not setting -C bitcode-in-rlib=no anywhere - unless there's some way that it can be set by default in some scenarios?

Minimal Reproduction Steps

cargo new rlib-test
cd rlib-test
RUSTFLAGS="-C lto" cargo build --release
# error: options `-C bitcode-in-rlib=no` and `-C lto` are incompatible

Works fine on nightly-2020-03-01.
(I didn't check any other nightly releases in between March and May)

@chinedufn chinedufn added the C-bug Category: This is a bug. label May 3, 2020
@Mark-Simulacrum
Copy link
Member

Is there a reason you're passing LTO via rustflags instead of setting it in Cargo.toml? That's the recommended approach, and should work I believe.

@chinedufn
Copy link
Contributor Author

Reason is that I don't always want LTO when building for release so by using RUSTFLAGS I can configure that without needing to edit source files whenever I want to enable/disable LTO.

Some more tangible scenarios in my own codebase:

  • Fat LTO for production release builds
  • Thin LTO when running the application locally
  • Thin LTO when iterating on benchmarks

So the different scripts that power these things either set or don't set certain RUSTFLAGS

@Mark-Simulacrum
Copy link
Member

You can set CARGO_PROFILE_<name>_LTO in the environment instead of rustflags to override the profile option (it takes the same values as the key in the profile).

@chinedufn
Copy link
Contributor Author

Woah thanks never knew about that!

I suppose I'll leave the issue open since RUSTFLAGS="-C LTO" no longer works (unless that's intended?)

But your answer solves my problems so I'm personally good to go.

Thanks!

@Mark-Simulacrum
Copy link
Member

cc @alexcrichton @nnethercote -- this is at least to me unexpected fallout but I personally think that just recommending people not set lto via RUSTFLAGS is reasonable (and instead use the environment variable overrides for Cargo).

@alexcrichton
Copy link
Member

While not necessarily intentional it's going to be pretty hard to keep this working given the changes we have to Cargo in the pipeline. You'll likely want to use the profile env vars because Cargo has much more intrusive knowledge of LTO now for compile time speedups. This is definitely a regression but I would hope that we could rely on users moving to the profile env vars for both updated builds and compile time wins.

@Alexendoo Alexendoo added the T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. label May 6, 2020
@Mark-Simulacrum Mark-Simulacrum added the relnotes Marks issues that should be documented in the release notes of the next release. label May 13, 2020
@Mark-Simulacrum
Copy link
Member

I'm going to go ahead and close this as won't fix but cc @XAMPPRocky -- I've tagged this relnotes as a compat note, will it get picked up?

@XAMPPRocky
Copy link
Member

Currently no, the relnotes tool only looks at pull requests, but I was already planning a small rewrite that will change that. If I don't get to that in time however I have saved this issue so I don't forget to include it.

praveenperera added a commit to praveenperera/trust that referenced this issue Sep 6, 2020
chinedufn added a commit to chinedufn/flamegraph that referenced this issue Jan 14, 2021
bors bot added a commit to flamegraph-rs/flamegraph that referenced this issue Jan 14, 2021
116: Recommend CARGO_PROFILE_RELEASE_DEBUG r=djc a=chinedufn

RUSTFLAGS does not always work rust-lang/rust#71848 (comment)

Co-authored-by: Chinedu Francis Nwafili <frankie.nwafili@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. relnotes Marks issues that should be documented in the release notes of the next release. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants