diff --git a/Cargo.toml b/Cargo.toml index 84c950f..614b66a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ unicode-linebreak = "0.1.4" unicode-script = "0.5.5" unicode-segmentation = "1.10.0" rangemap = "1.2.0" -hashbrown = { version = "0.14.0", default-features = false } +hashbrown = { version = "0.14.0", optional = true, default-features = false } rustc-hash = { version = "1.1.0", default-features = false } [dependencies.unicode-bidi] @@ -33,6 +33,7 @@ features = ["hardcoded-data"] default = ["std", "swash"] no_std = [ "rustybuzz/libm", + "hashbrown", ] std = [ "fontdb/memmap", diff --git a/ci.sh b/ci.sh index c867b6c..b746320 100755 --- a/ci.sh +++ b/ci.sh @@ -13,20 +13,20 @@ cargo fmt --check echo Build with default features build -echo Build with no default features -build --no-default-features +echo Build with only no_std feature +build --no-default-features --features no_std echo Build with only std feature build --no-default-features --features std -echo Build with only swash feature -build --no-default-features --features swash +echo Build with only std and swash features +build --no-default-features --features std,swash -echo Build with only syntect feature -build --no-default-features --features syntect +echo Build with only std and syntect features +build --no-default-features --features std,syntect -echo Build with only vi feature -build --no-default-features --features vi +echo Build with only std and vi features +build --no-default-features --features std,vi echo Build with all features build --all-features diff --git a/src/font/system.rs b/src/font/system.rs index 1152cd2..299bb99 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -3,10 +3,14 @@ use alloc::string::String; use alloc::sync::Arc; use alloc::vec::Vec; use core::fmt; -use core::hash::BuildHasherDefault; use core::ops::{Deref, DerefMut}; -type HashMap = hashbrown::HashMap>; +type BuildHasher = core::hash::BuildHasherDefault; + +#[cfg(feature = "std")] +type HashMap = std::collections::HashMap; +#[cfg(not(feature = "std"))] +type HashMap = hashbrown::HashMap; // re-export fontdb and rustybuzz pub use fontdb; diff --git a/src/lib.rs b/src/lib.rs index 3a16321..ac684b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,9 +91,11 @@ // Ensure numbers are readable #![warn(clippy::unreadable_literal)] #![cfg_attr(not(feature = "std"), no_std)] - extern crate alloc; +#[cfg(not(any(feature = "std", feature = "no_std")))] +compile_error!("Either the `std` or `no_std` feature must be enabled"); + pub use self::attrs::*; mod attrs;