Skip to content

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

@jonhoo

Description

@jonhoo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions