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

Compile probe does not take Cargo rustc configuration into account #156

Closed
jonhoo opened this issue Jun 17, 2021 · 4 comments · Fixed by #157
Closed

Compile probe does not take Cargo rustc configuration into account #156

jonhoo opened this issue Jun 17, 2021 · 4 comments · Fixed by #157

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jun 17, 2021

The compile probe just invokes rustc directly, without including relevant cargo configuration. This causes problems in environments where that configuration may change whether or not backtrace is available (or compiles):

cargo new anyhow-issue
cd anyhow-issue
mkdir .cargo
echo '[build]' >> .cargo/config.toml
echo 'rustflags = ["-Zallow-features="]' >> .cargo/config.toml
echo 'anyhow = "1"' >> Cargo.toml
rustup override set nightly
cargo check

produces

    Updating crates.io index
  Downloaded anyhow v1.0.41
  Downloaded 1 crate (34.6 KB) in 0.68s
   Compiling anyhow v1.0.41
error[E0725]: the feature `backtrace` is not in the list of allowed features
   --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.41/src/lib.rs:213:32
    |
213 | #![cfg_attr(backtrace, feature(backtrace))]
    |                                ^^^^^^^^^

error[E0658]: use of unstable library feature 'backtrace'
 --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.41/src/backtrace.rs:2:33
  |
2 | pub(crate) use std::backtrace::{Backtrace, BacktraceStatus};
  |                                 ^^^^^^^^^
  |
  = note: see issue #53487 <https://github.com/rust-lang/rust/issues/53487> for more information
  = help: add `#![feature(backtrace)]` to the crate attributes to enable
...

Taking everything into account is probably too tall of an order, but the Cargo environment variables should get us pretty far. In particular, if set, anyhow should probably take into account these three:

  • CARGO_BUILD_RUSTC
  • CARGO_BUILD_RUSTC_WRAPPER
  • CARGO_BUILD_RUSTFLAGS

Together, those should encapsulate most of the rustc configuration in cargo.

@dtolnay
Copy link
Owner

dtolnay commented Jun 18, 2021

Ah, good call. I would accept a PR to fix this.

@jonhoo
Copy link
Contributor Author

jonhoo commented Jun 18, 2021

Ooof, looks like those environment variables are only used to configure said settings. And the variables Cargo sets for build scripts does not include the wrapper nor rustflags. I'll follow up with the Cargo team.

@jonhoo
Copy link
Contributor Author

jonhoo commented Jun 18, 2021

Filed rust-lang/cargo#9600

@jonhoo
Copy link
Contributor Author

jonhoo commented Jun 18, 2021

Submitted fix in rust-lang/cargo#9601, though this means we'll have to wait a while to actually implement this fix.

jonhoo pushed a commit to jonhoo/anyhow that referenced this issue Jun 18, 2021
Without this, environments that configure `RUSTFLAGS` or the
`RUSTC_WRAPPER` in ways that break compilation with `backtrace` will
fail to compile anyhow (see dtolnay#156).

With this, the compiler probe takes into account that Cargo
configuration, and thus (more) accurately represents whether the
`backtrace` feature can be safely enabled.

Requires rust-lang/cargo#9600.

Fixes dtolnay#156.
jonhoo pushed a commit to jonhoo/anyhow that referenced this issue Aug 13, 2021
Without this, environments that configure `RUSTFLAGS` or the
`RUSTC_WRAPPER` in ways that break compilation with `backtrace` will
fail to compile anyhow (see dtolnay#156).

With this, the compiler probe takes into account that Cargo
configuration, and thus (more) accurately represents whether the
`backtrace` feature can be safely enabled.

Requires rust-lang/cargo#9601, but does not break without.

Fixes dtolnay#156.
jonhoo pushed a commit to jonhoo/anyhow that referenced this issue Aug 13, 2021
Without this, environments that configure `RUSTFLAGS` or the
`RUSTC_WRAPPER` in ways that break compilation with `backtrace` will
fail to compile anyhow (see dtolnay#156).

With this, the compiler probe takes into account that Cargo
configuration, and thus (more) accurately represents whether the
`backtrace` feature can be safely enabled.

Requires rust-lang/cargo#9601, but does not break without.

Fixes dtolnay#156.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants