rust-lang / wg-cargo-std-aware

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

"use of unstable library feature 'restricted_std'" can't be fixed for deps #69

Open Manishearth opened 3 years ago

Manishearth commented 3 years ago

I'm trying to build code with dependencies for thumbv7m-none-eabi, and crates like serde fail due to the lack of restricted_std.

This makes sense, but there doesn't seem to be a way to globally disable it, so either I have to edit and patch each of my dependencies, or I have to edit the requirement out of std. Neither is good. It would be nice if there were a way to globally opt in to this.

$ cargo +nightly build -Zbuild-std --target=thumbv7m-none-eabi
warning: unused manifest key: bench.1.required_features
   Compiling serde v1.0.126
error[E0658]: use of unstable library feature 'restricted_std'
  |
  = help: add `#![feature(restricted_std)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'restricted_std'
   --> /home/manishearth/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.126/src/lib.rs:157:17
    |
157 |         pub use std::*;
    |                 ^^^
    |
    = help: add `#![feature(restricted_std)]` to the crate attributes to enable

error: aborting due to 2 previous errors
ehuss commented 3 years ago

Do you have any thoughts on how that could be accomplished? It seems like it would be quite difficult without some compiler magic. This is very much in the experimental phase, so it is somewhat expected that you'll need to patch things to try it out.

For serde specifically, you can build without default features if there isn't anything in particular you need from std.

Manishearth commented 3 years ago

@ehuss I feel like another -Z flag would work? -Zunstable_restricted_std? It's super weird that std becomes unstable this way.

RMheng commented 2 years ago

I ran into the same problem like use of unstable library feature 'restricted_std', is there any compiler magic instead of patching each of the dependencies? I am using rustup-nightly-2021-08-01.

wcampbell0x2a commented 2 years ago

Any fixes for this issue?

bjc commented 2 years ago

This is causing problems with miri, as well:

$ cargo miri test --target riscv64gc-unknown-none-elf
   Compiling compiler_builtins v0.1.70
    Checking core v0.0.0 (/home/bjc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.116

   [snip]

    Checking getopts v0.2.21
    Checking test v0.0.0 (/home/bjc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test)
error[E0658]: use of unstable library feature 'restricted_std'
  |
  = help: add `#![feature(restricted_std)]` to the crate attributes to enable

For more information about this error, try `rustc --explain E0658`.
warning: `test` (lib) generated 1 warning (1 duplicate)
error: could not compile `test` due to previous error; 1 warning emitted
error: `"/home/bjc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo" "check" "--release" "--manifest-path" "/tmp/xargo.BtaXXCUpYvdM/Cargo.toml" "--target" "riscv64gc-unknown-none-elf" "-p" "test"` failed with exit code: Some(101)
note: run with `RUST_BACKTRACE=1` for a backtrace
fatal error: failed to run xargo