Skip to content

Commit 639e60a

Browse files
committed
Add a default-on std feature
This adds a `std` Cargo feature which disables `#![no_std]` builds of libc, but is 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.
1 parent af77843 commit 639e60a

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ services:
1010
script:
1111
- if [[ $TRAVIS_RUST_VERSION = nightly* ]]; then
1212
sh ci/run-travis.sh;
13+
elif [[ $TRAVIS_RUST_VERSION = beta* ]]; then
14+
cargo build;
15+
cargo build --no-default-features;
1316
else
1417
cargo build;
1518
fi

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ other common platform libraries.
1414
"""
1515

1616
[features]
17-
default = []
17+
default = ["std"]
18+
std = []

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ Next, add this to your crate root:
2424
extern crate libc;
2525
```
2626

27+
Currently libc by default links to the standard library, but if you would
28+
instead like to use libc in a `#![no_std]` situation or crate you can request
29+
this via:
30+
31+
```toml
32+
[dependencies]
33+
libc = { version = "0.2", features = ["no-std"] }
34+
```
35+
2736
## What is libc?
2837

2938
The primary purpose of this crate is to provide all of the definitions necessary

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
reason = "use `libc` from crates.io",
8383
issue = "27783"))]
8484

85-
#[cfg(all(not(stdbuild), not(dox)))]
85+
#![cfg_attr(not(feature = "std"), no_std)]
86+
87+
#[cfg(all(not(stdbuild), not(dox), feature = "std"))]
8688
extern crate std as core;
8789

8890
#[macro_use] mod macros;

0 commit comments

Comments
 (0)