rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

Possibly add a way to disable sysroot on `rustc` #31

Open ehuss opened 4 years ago

ehuss commented 4 years ago

The current implementation uses --extern flags to tell rustc where the standard library dependencies are located. This runs into a few problems when a user attempts to use extern crate for a crate that was not included. For example, a no_std crate that has extern std, or an extern crate test when libtest is not built. These will attempt to load from the default sysroot which causes a huge number of inscrutable errors.

It may be nice to tell rustc to not look in the pre-built sysroot to avoid this problem (and will result in a nicer "crate not found" error). This can be done with --sysroot=nonexistent or an empty directory. Alternatively, we can add a new flag to rustc to disable the sysroot search.

This may have complications, since the sysroot is used for more than rlib dependencies. For example, it is also used for bundled things (like linkers? bundled crt objects?).

Beware this may affect things like clippy-driver, rustdoc, etc.

Ericson2314 commented 4 years ago

Yes this is definitely the right approach long term. Banish the sysroot!

alexcrichton commented 4 years ago

I would personally consider this a blocker for stabilization in one form or another. It should be easy enough and is basically a form of hygiene, but I just ran into some really weird errors locally which ended up being caused because rustc was still using its original sysroot to load the proc_macro, which transitively loaded two versions of std. The bug was in Cargo/on my end for not building proc_macro, but if we either cleared out the sysroot or passed it an empty one then I would've gotten a proper error for "the proc_macro crate can't be found".

alexcrichton commented 4 years ago

One thing I just thought of thinking about this again, if we turn off --sysroot then rustc would lose implicit access to the bundled rust-lld linker which I believe a number of custom targets rely on (and wasm surely does too). We may not actually be able to remove the --sysroot in that case?

alexcrichton commented 4 years ago

Fixed in https://github.com/rust-lang/cargo/pull/7421

ehuss commented 4 years ago

Reopen due to https://github.com/rust-lang/cargo/pull/7699.