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

Can't seem to use without std #23

Closed
dcarosone opened this issue Apr 17, 2018 · 5 comments
Closed

Can't seem to use without std #23

dcarosone opened this issue Apr 17, 2018 · 5 comments

Comments

@dcarosone
Copy link

Cargo.toml has what seems to me to be the right thing from the documentation:

[dependencies.either]
version = "1.5.0"
default-features = false

and yet cargo build complains, in a no_std project:

   Compiling either v1.5.0
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv7m-none-eabi` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `either`.

Disclaimer: I'm a newb, and probably doing something dumb, but I can't see what. Today's nightly, in case it matters.

@bluss
Copy link
Contributor

bluss commented Apr 17, 2018

Hi,

I would suspect that some other dependency is pulling in either with default features, or either with the serde feature. Either of those seems to be the likely explanation.

cargo build -v will give you a short list of crates and their versions that are being built in your project. If either is the only dep you have, feel free to point to the whole code so that we can reproduce and investigate.

@dcarosone
Copy link
Author

dcarosone commented Apr 18, 2018

Adding and removing the dependency lines above causes the failure. It's not getting to any of my code yet. If I take it out, it fails in my code with the expected errors about Either being unresolved but all the deps are built (so it seems like nothing else is pulling it in).

cargo build -v shows that it's being build with --cfg feature="default" --cfg feature="use_std", and manually invoking that rustc ... without those two args exits without failure, so it's clearly something weird in cargo land rather than (say) a bug in Either not fully conditionalising std dependencies.

Code is at https://github.com/dcarosone/ws2812b (the firmware subdir). Note: there's plenty of other brokenness here; it's a WIP for japaric/ws2812b#5 chosen very much as a learning exercise. In some of the updated examples, Either is being used and I'm trying to replicate that.

@cuviper
Copy link
Member

cuviper commented Apr 18, 2018

Here's your inverted dependency tree:

$ cargo tree -i -p either
either v1.5.0
[dependencies]
├── firmware v0.1.0 (file:///tmp/ws2812b/firmware)
└── rtfm-syntax v0.3.0
    [dependencies]
    └── cortex-m-rtfm-macros v0.3.1
        [dependencies]
        └── cortex-m-rtfm v0.3.2
            [dependencies]
            └── firmware v0.1.0 (file:///tmp/ws2812b/firmware) (*)
  • firmware -> either sets default-features = false
  • firmware -> cortex-m-rtfm -> cortex-m-rtfm-macros -> rtfm-syntax -> either does not.

However, cortex-m-rtfm-macros is a proc-macro crate, which means it's always compiled for the host as a plugin to rustc, where std is fine. I think this is a bug/limitation in Cargo: the either features selected here for the host are different than the either features selected for your target, but Cargo is simply using the superset of either features everywhere.

@dcarosone
Copy link
Author

Oh. Well, that's at least an explanation, thank you!

I guess I'll try going back to xargo and see if that helps; being able to use cargo for this is quite new and perhaps this is a missed case.

@cuviper
Copy link
Member

cuviper commented Apr 18, 2018

Just for cross reference, I think this is rust-lang/cargo#2589.

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