autocfg icon indicating copy to clipboard operation
autocfg copied to clipboard

autocfg does not work in the presence of -Z build-std

Open jdm opened this issue 4 years ago • 8 comments

build.rs:

fn main() {
  assert!(autocfg::new().probe_sysroot_crate("std"));
}

cargo build works fine for any target where libstd is already distributed. cargo build --target x86_64-uwp-windows-msvc -Z build-std panics even though the sysroot is being built correctly.

jdm avatar Feb 25 '21 03:02 jdm

Does cargo communicate this in any way? Maybe an environment variable?

cuviper avatar Feb 25 '21 03:02 cuviper

I've asked that question in https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Signalling.20the.20presence.20of.20-Z.20build-std.

jdm avatar Feb 25 '21 05:02 jdm

This breaks the bigint crate for certain targets like i686-apple-darwin. Any idea for when this might be fixed?

melvyn2 avatar Apr 20 '23 01:04 melvyn2

There's no plan how to fix it yet...

Assuming you mean num-bigint, it should degrade ok without it, no?

cuviper avatar Apr 20 '23 02:04 cuviper

Some dependent crates rely on features which get deactivated because of this, even though bigint builds successfully... I'll try to build the stdlib by hand in the meantime. Hopefully -Z build-std will be stabilized eventually.

melvyn2 avatar Apr 20 '23 02:04 melvyn2

Why does autocfg care if the crate is loaded from the sysroot or passed with --extern? Shouldn't extern crate std work in both cases?

jyn514 avatar Apr 20 '23 04:04 jyn514

Oh, is the problem that cargo only passes --extern std=... to the final crate, not to build scripts? I wonder if it should set some environment variable with a list of the std crates built from source ... in general I think it would be nice for cargo to expose a way for build scripts to invoke rustc the same way cargo would in the current build.

jyn514 avatar Apr 20 '23 04:04 jyn514

Ah, that already exists and it's called CARGO_ENCODED_RUSTFLAGS 😄 I think we should open an upstream issue for cargo to include the --extern std flags in CARGO_ENCODED_RUSTFLAGS.

jyn514 avatar Apr 20 '23 04:04 jyn514