From 7c3f757cdc83b4035d81f0d521b4b80b9080155e Mon Sep 17 00:00:00 2001 From: Gerd Zellweger Date: Tue, 29 Sep 2015 21:20:33 +0200 Subject: [PATCH] Reinstantiate no_std cargo feature flag. The feature was removed in d4c189a due to heavy refactoring of libcore before rust 1.0. --- .travis.yml | 2 ++ README.md | 2 ++ phf/Cargo.toml | 3 +++ phf/src/lib.rs | 10 ++++++++++ phf_shared/Cargo.toml | 3 +++ phf_shared/src/lib.rs | 7 +++++++ 6 files changed, 27 insertions(+) diff --git a/.travis.yml b/.travis.yml index 851721fe..3007525c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,3 +10,5 @@ script: - (test $TRAVIS_RUST_VERSION != "nightly" || (cd phf_macros && cargo bench)) - (cd phf_codegen && cargo test) - (cd phf_codegen/test && cargo test) +- (cd phf_shared && cargo build --features core) +- (cd phf && cargo build --features core) \ No newline at end of file diff --git a/README.md b/README.md index 5a3b73de..200ce24c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ PHF data structures can be constucted via either the compiler plugins in the Compiler plugins are not a stable part of Rust at the moment, so `phf_macros` can only be used with nightlies. +The `phf/core` feature will compile the `phf` crate with a dependency on libcore instead of libstd, enabling use in environments where libstd will not work. + phf_macros =========== diff --git a/phf/Cargo.toml b/phf/Cargo.toml index 787e7779..0ae8781d 100644 --- a/phf/Cargo.toml +++ b/phf/Cargo.toml @@ -12,6 +12,9 @@ name = "phf" path = "src/lib.rs" test = false +[features] +core = ["phf_shared/core"] + [dependencies] debug-builders = "0.1" phf_shared = { version = "=0.7.5", path = "../phf_shared" } diff --git a/phf/src/lib.rs b/phf/src/lib.rs index 70eef521..c4ce6702 100644 --- a/phf/src/lib.rs +++ b/phf/src/lib.rs @@ -5,10 +5,20 @@ //! the documentation of those crates for more details. #![doc(html_root_url="https://sfackler.github.io/rust-phf/doc/v0.7.5")] #![warn(missing_docs)] +#![cfg_attr(feature = "core", feature(no_std))] +#![cfg_attr(feature = "core", no_std)] extern crate debug_builders; extern crate phf_shared; +#[cfg(feature = "core")] +mod std { + pub use core::{borrow, fmt, iter, option, ops, slice}; + pub mod prelude { + pub use core::prelude as v1; + } +} + pub use phf_shared::PhfHash; #[doc(inline)] pub use map::Map; diff --git a/phf_shared/Cargo.toml b/phf_shared/Cargo.toml index acb5914d..f8e02389 100644 --- a/phf_shared/Cargo.toml +++ b/phf_shared/Cargo.toml @@ -11,3 +11,6 @@ documentation = "https://sfackler.github.io/rust-phf/doc/v0.7.5/phf_shared" name = "phf_shared" path = "src/lib.rs" test = false + +[features] +core = [] \ No newline at end of file diff --git a/phf_shared/src/lib.rs b/phf_shared/src/lib.rs index 9706dea4..0f17e8f4 100644 --- a/phf_shared/src/lib.rs +++ b/phf_shared/src/lib.rs @@ -1,4 +1,11 @@ #![doc(html_root_url="http://sfackler.github.io/rust-phf/doc/v0.7.5")] +#![cfg_attr(feature = "core", feature(no_std, core_slice_ext, core_str_ext))] +#![cfg_attr(feature = "core", no_std)] + +#[cfg(feature = "core")] +mod std { + pub use core::{slice, str, hash}; +} use std::hash::{Hasher, Hash, SipHasher};