Skip to content

Commit

Permalink
build: gate regex API on 'use_std' feature
Browse files Browse the repository at this point in the history
This commit adds a new 'use_std' feature and enables it by default.
This permits us to one day add support for building regex without
'use_std' (but with 'alloc', probably) by avoiding the introduction
of incompatibilities. Namely, this setup ensures that all of today's
uses of '--no-default-features' won't compile without also adding the
'use_std' feature.

Closes #457
  • Loading branch information
BurntSushi committed May 1, 2018
1 parent c1b1289 commit 1a8f5e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ quickcheck = { version = "0.6", default-features = false }
rand = "0.4"

[features]
# We don't enable any features by default currently, but if the compiler
# supports a specific type of feature, then regex's build.rs might enable
# some default features.
default = []
default = ["use_std"]
# The 'use_std' feature permits the regex crate to use the standard library.
# This is intended to support future use cases where the regex crate may be
# able to compile without std, and instead just rely on 'core' and 'alloc'
# (for example). Currently, this isn't supported, and removing the 'use_std'
# feature will prevent regex from compiling.
use_std = []
# A blanket feature that governs whether unstable features are enabled or not.
# Unstable features are disabled by default, and typically rely on unstable
# features in rustc itself.
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
let version = String::from_utf8(output).unwrap();

// If we're using nightly Rust, then we can enable vector optimizations.
// Note that these aren't actually activated unless the `nightly` feature
// Note that these aren't actually activated unless the `unstable` feature
// is enabled.
//
// We also don't activate these if we've explicitly disabled auto
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,17 @@ extern crate quickcheck;
extern crate regex_syntax as syntax;
extern crate utf8_ranges;

#[cfg(feature = "use_std")]
pub use error::Error;
#[cfg(feature = "use_std")]
pub use re_builder::unicode::*;
#[cfg(feature = "use_std")]
pub use re_builder::set_unicode::*;
#[cfg(feature = "use_std")]
pub use re_set::unicode::*;
#[cfg(feature = "use_std")]
pub use re_trait::Locations;
#[cfg(feature = "use_std")]
pub use re_unicode::{
Regex, Match, Captures,
CaptureNames, Matches, CaptureMatches, SubCaptureMatches,
Expand Down Expand Up @@ -629,6 +635,7 @@ When the `s` flag is enabled, `.` matches any byte.
In general, one should expect performance on `&[u8]` to be roughly similar to
performance on `&str`.
*/
#[cfg(feature = "use_std")]
pub mod bytes {
pub use re_builder::bytes::*;
pub use re_builder::set_bytes::*;
Expand Down Expand Up @@ -664,6 +671,7 @@ mod vector;
/// testing different matching engines and supporting the `regex-debug` CLI
/// utility.
#[doc(hidden)]
#[cfg(feature = "use_std")]
pub mod internal {
pub use compile::Compiler;
pub use exec::{Exec, ExecBuilder};
Expand Down

0 comments on commit 1a8f5e6

Please sign in to comment.