Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a default-on std feature #146
Conversation
This comment has been minimized.
This comment has been minimized.
|
r? @brson |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
cargo features are additive, so this does not work under the cargo scheme. If any dependency activates "no-std", the whole project will have it (for libc). cargo features can't turn things off. Could this instead use a positive feature "use-std" that is enabled by default? The unioning of cargo features will work correctly then. |
alexcrichton
force-pushed the
alexcrichton:no-std
branch
from
3138084
to
aa41fbe
Jan 21, 2016
This comment has been minimized.
This comment has been minimized.
|
For this library specifically I think that this is an additive feature (because the API will not change based on it or not) as it's adding a feature, but for libraries in general I think that they're going to provide a more full suite of functionality with std than without. Along those lines I'd be interested in starting to pioneer a convention for libraries with I also think that it makes more sense to "turn off the standard library" than "enable turning off the standard library", e.g. cc @rust-lang/libs, this is at the very least a backwards compatibility hazard as once we've decided a name/interface for this it can't be changed. Thoughts? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
My bad! I did actually assume it would change its functionality depending on std / no std (this is the use case I've been thinking about). Very interested in that we have a common way to do this across crates. |
This comment has been minimized.
This comment has been minimized.
|
If I understand @bluss's concern, it 'no-std' is a convention, then it will be impossible to selectively turn off for specific crates; activating the cargo 'no-std' feature anywhere will turn it off for all crates. Is that right?
I don't understand what this comment means. What does 'disable-features = false' do?
Can you spell out why this is? Also, what do you do to disable a feature, either project-wide or per-crate? |
This comment has been minimized.
This comment has been minimized.
|
You have a library D version "1" which supports core and/or std. D has the feature flag "use-std". We have application A, with dependencies B and C.
To build A, cargo has to build B, C, D. To build D, it unions all the features needed, so it builds D with "use-std". For this reason we can't use features to subtract, we must only add, since cargo treats them as additive (adding a feature flag must not break those that depend on the crate as it was without the feature flag). Having default features is like having all deps specifying they depend on the default features automatically. Specifying features is something you do in the dependencies section. For example. [dependencies]
D = { version = "1", features = ["use-std"] }
E = { version = "1", default-features = false }Edit: Note that since libc neither "adds" nor "subtracts", I don't think it matters for this package.. An example of adding would be to implement the trait "Read" when possible (when std is available). |
This comment has been minimized.
This comment has been minimized.
Yeah this is correct
Oops, that actually does nothing, I meant I that I would want to concretely propose that |
alexcrichton
force-pushed the
alexcrichton:no-std
branch
2 times, most recently
from
639e60a
to
fd755bb
Jan 22, 2016
This comment has been minimized.
This comment has been minimized.
|
In this case the only reason we need a Cargo feature is to allow libc to work on older Rust versions that don't support |
Stebalien
reviewed
Jan 22, 2016
| [dependencies] | ||
| libc = { version = "0.2", features = ["no-std"] } | ||
| ``` | ||
|
|
This comment has been minimized.
This comment has been minimized.
alexcrichton
changed the title
Add a no-std feature
Add a std feature
Jan 22, 2016
alexcrichton
changed the title
Add a std feature
Add a default-on std feature
Jan 22, 2016
alexcrichton
force-pushed the
alexcrichton:no-std
branch
from
fd755bb
to
b1a6f45
Jan 22, 2016
This comment has been minimized.
This comment has been minimized.
|
@Amanieu yes that's correct, it's currently expected that this crate works with versions like Rust 1.5 and below, so switching the defaults would be a bit of a breaking change for |
alexcrichton
force-pushed the
alexcrichton:no-std
branch
from
b1a6f45
to
4e5b983
Jan 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Instead of having |
This comment has been minimized.
This comment has been minimized.
|
That's a troubling thought. It seems cargo needs a new feature for this. |
This comment has been minimized.
This comment has been minimized.
|
@tbu- ah yes that's a good point, but it also only applies in the case where existing APIs are hidden behind a feature. If a default-on feature is used to gate just-newly-added APIs then it wouldn't cause breakage. There is currently not a Cargo issue for disabling a feature (or just disabling a default feature), but it seems like it may be interesting to add. |
This comment has been minimized.
This comment has been minimized.
|
It's not clear to me we've arrived at the solution. This is a big convention to set. Is everybody comfortable with this: 'std' is the feature that enables linking to std, enabled by default, and you turn on no_std by disabling all default features? |
This comment has been minimized.
This comment has been minimized.
|
Yeah I agree, I would like to talk about this during libs triage. |
This comment has been minimized.
This comment has been minimized.
|
I'm having trouble following the thrust of this thread. On the one hand, we seem to be talking about a hack in libc to get backwards-compatibility with older versions of rustc. On the other hand, we seem to be talking about a general convention. Is the latter also just about backcompat? I feel like we continually run into issues like this and we should seriously consider a first-class way to straddle versions via |
This comment has been minimized.
This comment has been minimized.
|
Yes, there are two issues here, but the question for the libs team (in my mind) is about the feature naming/semantics itself. To recap, the first issue is that it would be a breaking change right now to make libc The second issue is that there are many use cases throughout our crates of having a "libcore mode". For example the log crate recently picked this up. The idea is that you can provide what is a likely stripped down set of functionality without std, but you can still provide the core set of utilities. I'm thinking that we want to have features called
As @tbu- mentioned, however, there is a backwards-compatibility hazard. Once the set of default features have been decided, then the existing API of the crate must always be available with @aturon I agree that straddling versions with some sort of cfg to just always support |
This comment has been minimized.
This comment has been minimized.
Gankro
commented
Feb 2, 2016
|
@alexcrichton just have the build script detect the rustc version, and branch on that!
|
alexcrichton
force-pushed the
alexcrichton:no-std
branch
from
4e5b983
to
d55f631
Feb 11, 2016
alexcrichton
force-pushed the
alexcrichton:no-std
branch
from
d55f631
to
6d46b6f
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this during triage today and the conclusion was to take this strategy with the name "use_std" (to mirror the log crate). I've pushed a commit with these changes and I'll merge when CI is green! |
alexcrichton commentedJan 21, 2016
This adds a
stdCargo feature which disables#![no_std]builds of libc, butis enabled by default. The library will currently continue to link to the
standard library to maintain backwards compatibility with the 0.2 series and
older Rust compilers for now, but this default can possible be changed in the
future.