From 14d0ceb81bef003a0d8ab1cdcc9c3e40b2fb861b Mon Sep 17 00:00:00 2001 From: grovesNL Date: Wed, 9 Aug 2023 10:19:24 -0230 Subject: [PATCH 1/3] Move hashbrown behind `no_std` feature --- Cargo.toml | 3 ++- src/font/system.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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/src/font/system.rs b/src/font/system.rs index 1152cd2..7d7e786 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 = "no_std")] +type HashMap = hashbrown::HashMap; +#[cfg(not(feature = "no_std"))] +type HashMap = std::collections::HashMap; // re-export fontdb and rustybuzz pub use fontdb; From c4d107563a241e30a0c96c959d9509f697f20524 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Wed, 9 Aug 2023 11:40:51 -0230 Subject: [PATCH 2/3] Require either `std` or `no_std` to be specified --- src/font/system.rs | 6 +++--- src/lib.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/font/system.rs b/src/font/system.rs index 7d7e786..299bb99 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -7,10 +7,10 @@ use core::ops::{Deref, DerefMut}; type BuildHasher = core::hash::BuildHasherDefault; -#[cfg(feature = "no_std")] -type HashMap = hashbrown::HashMap; -#[cfg(not(feature = "no_std"))] +#[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; From 3905312f5f727e95505e16e5b49d2da42547f745 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Wed, 9 Aug 2023 11:42:12 -0230 Subject: [PATCH 3/3] Add `no_std` to CI and add `std` per feature --- ci.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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