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

Crypto_Box doesn't compile on No_Std target #242

Closed
tl8roy opened this issue Nov 30, 2020 · 4 comments
Closed

Crypto_Box doesn't compile on No_Std target #242

tl8roy opened this issue Nov 30, 2020 · 4 comments

Comments

@tl8roy
Copy link

tl8roy commented Nov 30, 2020

I am building a PoC on a STM32 Nucleo board and want to use the Crypto_Box crate. The problem is that when I include it like:
crypto_box = {version = "0.5", default-features = false, features = ["heapless","u64_backend"]}, I get the following error when I try to compile it:

Compiling getrandom v0.1.15
error[E0463]: can't find crate for `std`
 --> C:\Users\Tristan\.cargo\registry\src\github.com-1ecc6299db9ec823\getrandom-0.1.15\src\error_impls.rs:8:1
  |
8 | extern crate std;
  | ^^^^^^^^^^^^^^^^^ can't find crate

I'm not sure what features I need to include/exclude.

@tarcieri
Copy link
Member

The error you're quoting is arising from getrandom, which is not a transitive dependency of crypto_box.

Are you explicitly listing it in your lockfile somewhere? It's not no_std compatible.

You need to use the rand_core APIs to generate randomness.

@newpavlov
Copy link
Member

Well, getrandom has became no_std compatible in v0.2 (see the custom feature) and it's possible to [repalce] or [patch] it.

I've created an empty project and added crypto_box using the line you provided and I got the following compilation log:

   Compiling typenum v1.12.0
   Compiling version_check v0.9.2
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.53
   Compiling byteorder v1.3.4
   Compiling subtle v2.3.0
   Compiling stable_deref_trait v1.2.0
   Compiling heapless v0.5.6
   Compiling rand_core v0.5.1
   Compiling generic-array v0.14.4
   Compiling hash32 v0.1.1
   Compiling quote v1.0.7
   Compiling generic-array v0.12.3
   Compiling generic-array v0.13.2
   Compiling as-slice v0.1.4
   Compiling cipher v0.2.5
   Compiling universal-hash v0.4.0
   Compiling digest v0.9.0
   Compiling poly1305 v0.6.1
   Compiling synstructure v0.12.4
   Compiling aead v0.3.2
   Compiling zeroize_derive v1.0.1
   Compiling zeroize v1.1.1
   Compiling salsa20 v0.7.2
   Compiling chacha20 v0.6.0
   Compiling curve25519-dalek v3.0.0
   Compiling xsalsa20poly1305 v0.6.0
   Compiling chacha20poly1305 v0.7.1
   Compiling x25519-dalek v1.1.0
   Compiling crypto_box v0.5.0

As you can see, it does not contain getrandom, so the most likely cause of your problem is that some other dependency of your project enables std feature for one of the rand crates.

@tl8roy
Copy link
Author

tl8roy commented Nov 30, 2020

Hmm, I was pulling in rand as a dev-dependency and that was somehow pulling into the main project (Maybe via probe-run or defmt). Anyway it is building now. Thanks

@tl8roy tl8roy closed this as completed Nov 30, 2020
@tarcieri
Copy link
Member

@tl8roy aah, seems you were hitting one of my least favorite Rust bugs:

rust-lang/cargo#7915

Fortunately there's a new resolver which fixes feature unification for these cases you can try out (see linked issue).

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

No branches or pull requests

3 participants