Skip to content

Commit

Permalink
Merge pull request #168 from grovesNL/nostd-hash
Browse files Browse the repository at this point in the history
Move hashbrown behind `no_std` feature
  • Loading branch information
jackpot51 authored Aug 14, 2023
2 parents 0476d7c + 3905312 commit 618896f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -33,6 +33,7 @@ features = ["hardcoded-data"]
default = ["std", "swash"]
no_std = [
"rustybuzz/libm",
"hashbrown",
]
std = [
"fontdb/memmap",
Expand Down
16 changes: 8 additions & 8 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/font/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V> = hashbrown::HashMap<K, V, BuildHasherDefault<rustc_hash::FxHasher>>;
type BuildHasher = core::hash::BuildHasherDefault<rustc_hash::FxHasher>;

#[cfg(feature = "std")]
type HashMap<K, V> = std::collections::HashMap<K, V, BuildHasher>;
#[cfg(not(feature = "std"))]
type HashMap<K, V> = hashbrown::HashMap<K, V, BuildHasher>;

// re-export fontdb and rustybuzz
pub use fontdb;
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 618896f

Please sign in to comment.