From 6d46b6fa5fc8cbb468e5ec0f9b72e2af8414d9ac Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 20 Jan 2016 16:39:37 -0800 Subject: [PATCH] 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. --- .travis.yml | 4 ++++ Cargo.toml | 3 ++- README.md | 9 +++++++++ src/lib.rs | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5220025..d6d3ab58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: required dist: trusty rust: - 1.0.0 + - stable - beta - nightly services: @@ -10,8 +11,11 @@ services: script: - if [[ $TRAVIS_RUST_VERSION = nightly* ]]; then sh ci/run-travis.sh; + elif [[ $TRAVIS_RUST_VERSION = "1.0.0" ]]; then + cargo build; else cargo build; + cargo build --no-default-features; fi os: - linux diff --git a/Cargo.toml b/Cargo.toml index 067d0785..28e5b335 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ other common platform libraries. """ [features] -default = [] +default = ["use_std"] +use_std = [] diff --git a/README.md b/README.md index 801b73d3..69ebadaf 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,15 @@ Next, add this to your crate root: extern crate libc; ``` +Currently libc by default links to the standard library, but if you would +instead like to use libc in a `#![no_std]` situation or crate you can request +this via: + +```toml +[dependencies] +libc = { version = "0.2", default-features = false } +``` + ## What is libc? The primary purpose of this crate is to provide all of the definitions necessary diff --git a/src/lib.rs b/src/lib.rs index bcb83fcb..c9d7701a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,9 @@ reason = "use `libc` from crates.io", issue = "27783"))] -#[cfg(all(not(stdbuild), not(dox)))] +#![cfg_attr(not(feature = "use_std"), no_std)] + +#[cfg(all(not(stdbuild), not(dox), feature = "use_std"))] extern crate std as core; #[macro_use] mod macros;