Skip to content

Commit

Permalink
cargo: require 'std' when enabling 'unicode'
Browse files Browse the repository at this point in the history
The comment in the src/lib.rs diff should explain things for the most
part here. The main reason for this commit is to avoid a backcompat
hazard after 1.0 is released when and if we want to drop the 'once_cell'
dependency.
  • Loading branch information
BurntSushi committed Sep 7, 2022
1 parent 6df1c9d commit 72024a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ and Unicode support.
* `unicode` - **Enabled** by default. This provides APIs that require sizable
Unicode data compiled into the binary. This includes, but is not limited to,
grapheme/word/sentence segmenters. When this is disabled, basic support such
as UTF-8 decoding is still included.
as UTF-8 decoding is still included. Note that currently, enabling this
feature also requires enabling the `std` feature. It is expected that this
limitation will be lifted at some point.
* `serde` - Enables implementations of serde traits for `BStr`, and also
`BString` when `alloc` is enabled.

Expand Down
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,30 @@ and Unicode support.
* `unicode` - **Enabled** by default. This provides APIs that require sizable
Unicode data compiled into the binary. This includes, but is not limited to,
grapheme/word/sentence segmenters. When this is disabled, basic support such
as UTF-8 decoding is still included.
as UTF-8 decoding is still included. Note that currently, enabling this
feature also requires enabling the `std` feature. It is expected that this
limitation will be lifted at some point.
* `serde` - Enables implementations of serde traits for `BStr`, and also
`BString` when `alloc` is enabled.
*/

#![cfg_attr(not(any(feature = "std", test)), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

// Why do we do this? Well, in order for us to use once_cell's 'Lazy' type to
// load DFAs, it requires enabling its 'std' feature. Yet, there is really
// nothing about our 'unicode' feature that requires 'std'. We could declare
// that 'unicode = [std, ...]', which would be fine, but once regex-automata
// 0.3 is a thing, I believe we can drop once_cell altogether and thus drop
// the need for 'std' to be enabled when 'unicode' is enabled. But if we make
// 'unicode' also enable 'std', then it would be a breaking change to remove
// 'std' from that list.
//
// So, for right now, we force folks to explicitly say they want 'std' if they
// want 'unicode'. In the future, we should be able to relax this.
#[cfg(all(feature = "unicode", not(feature = "std")))]
compile_error!("enabling 'unicode' requires enabling 'std'");

#[cfg(feature = "alloc")]
extern crate alloc;

Expand Down

0 comments on commit 72024a8

Please sign in to comment.