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

Always depends on std when built with cargo #14

Closed
jdub opened this issue Jul 1, 2015 · 3 comments
Closed

Always depends on std when built with cargo #14

jdub opened this issue Jul 1, 2015 · 3 comments

Comments

@jdub
Copy link

jdub commented Jul 1, 2015

The following lines mean that libc always depends on std when built with cargo...

#![cfg_attr(not(feature = "cargo-build"), no_std)]

...

#[cfg(feature = "cargo-build")] extern crate std as core;
#[cfg(not(feature = "cargo-build"))] extern crate core;

... which doesn't work when using cargo with a no_std crate and an alternative target (without a cross-compiled std crate, but that's ultimately not what I want anyway).

In an attempt to hack around this, I added the following to my Cargo.toml:

[dependencies.libc]
version = "0.1"
features = []
default-features = false

But this is the build command line:

rustc /home/jdub/.cargo/registry/src/github.com-0a35038f75765ae4/libc-0.1.8/rust/src/liblibc/lib.rs --crate-name libc --crate-type lib -g --cfg feature="default" --cfg feature="cargo-build" -C metadata=ef5cbad4ef5c7a1e -C extra-filename=-ef5cbad4ef5c7a1e --out-dir /home/jdub/src/derp/acpica/target/i686-unknown-linux-gnu/debug/deps --emit=dep-info,link --target ../derp/i686-unknown-linux-gnu.json -L dependency=/home/jdub/src/derp/acpica/target/i686-unknown-linux-gnu/debug/deps -L dependency=/home/jdub/src/derp/acpica/target/i686-unknown-linux-gnu/debug/deps -Awarnings

Part of the challenge here is that the libc crate is just a slim wrapper around the Rust's liblibc, so changing things is probably difficult.

Thoughts or suggestions, though? Should I not use the libc crate at all?

@alexcrichton
Copy link
Member

Unfortunately this crate isn't really intended to be used in the #![no_std] use case

@alexcrichton
Copy link
Member

Gah sorry hit the button too soon.

To elaborate, this crate isn't intended to be used as part of the #![no_std] use case, and because Cargo unions features then if anything else depends on this crate without saying default-features = false then the feature will be activated (and this will depend on std).

Stay tuned though, with rust-lang/rfcs#1184 implemented we'll definitely mark this as #![no_std]!

@jdub
Copy link
Author

jdub commented Jul 2, 2015

Thanks for being so helpful with difficult freestanders like me, @alexcrichton. 😄

Susurrus pushed a commit to Susurrus/libc that referenced this issue Mar 26, 2017
dlrobertson pushed a commit to dlrobertson/libc that referenced this issue Oct 31, 2017
Make binutils build (it is probably not fully functional)
bors pushed a commit that referenced this issue Oct 10, 2019
Sync to rust-lang/libc master
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

2 participants