rust-lang / cfg-if

A if/elif-like macro for Rust #[cfg] statements
Apache License 2.0
557 stars 40 forks source link

Make create be no_std #1

Closed dhylands closed 7 years ago

dhylands commented 7 years ago

The regular portion of the crate doesn't need anything from std so turn off std for non-test. This allows this to be used from projects which are also no_std.

alexcrichton commented 7 years ago

Thanks! I think the attribute here for not(test) may not be necessary though? What's the error you see if that's omitted?

dhylands commented 7 years ago

If I just use #![no_std] then I get this when trying to run cargo test:

3053 >cargo test
   Compiling cfg-if v0.1.0 (file:///home/dhylands/Dropbox/sensorweb/cfg-if)
error[E0432]: unresolved import `std::option::Option`
  --> src/lib.rs:72:17
   |
70 |     cfg_if! {
   |     - in this macro invocation
71 |         if #[cfg(test)] {
72 |             use std::option::Option as Option2;
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Maybe a missing `extern crate std;`?

error: aborting due to previous error

Build failed, waiting for other jobs to finish...
error: Could not compile `cfg-if`.

To learn more, run the command again with --verbose.

I thought that cargo test needed std for other purposes, but if I change std::option::Option to core::option::Option then cargo test still works with just the plain #![no_std]. I'll rework the patch to do it that way.

dhylands commented 7 years ago

I added a commit (assuming this would be squashed when its merged) to make #![no_std] unconditional and have the test using core::option::Option instead of std::option::Option

alexcrichton commented 7 years ago

Looks good to me, thanks!