Skip to content

Commit 6d46b6f

Browse files
committed
Add a default-on "use_std" feature
This adds a `use_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 379e92f commit 6d46b6f

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ sudo: required
33
dist: trusty
44
rust:
55
- 1.0.0
6+
- stable
67
- beta
78
- nightly
89
services:
910
- docker
1011
script:
1112
- if [[ $TRAVIS_RUST_VERSION = nightly* ]]; then
1213
sh ci/run-travis.sh;
14+
elif [[ $TRAVIS_RUST_VERSION = "1.0.0" ]]; then
15+
cargo build;
1316
else
1417
cargo build;
18+
cargo build --no-default-features;
1519
fi
1620
os:
1721
- linux

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 = ["use_std"]
18+
use_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", default-features = false }
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 = "use_std"), no_std)]
86+
87+
#[cfg(all(not(stdbuild), not(dox), feature = "use_std"))]
8688
extern crate std as core;
8789

8890
#[macro_use] mod macros;

0 commit comments

Comments
 (0)