Skip to content

Commit 6c4c196

Browse files
committed
feat!: add wasm feature toggle to let parts of git-pack build on wasm32.
It's a breaking change because we also start using the `dep:` syntax for declaring references to optional dependencies, which will prevent them from being automatically available as features. Besides that, it adds the `wasm` feature toggle to allow compiling to `wasm32` targets.
1 parent f0e40ec commit 6c4c196

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

.github/workflows/wasm.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
name: crates without feature toggles
3333
- run: set +x; for feature in progress fs-walkdir-parallel parallel io-pipe crc32 zlib zlib-rust-backend fast-sha1 rustsha1 cache-efficiency-debug; do (cd git-features && cargo build --features $feature --target ${{ matrix.target }}); done
3434
name: features of git-features
35-
- run: set +x; for name in git-diff; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
35+
- run: set +x; for name in git-diff git-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
3636
name: crates with 'wasm' feature
37-
# - run: cargo build -p git-pack --target ${{ matrix.target }} // TODO: make something like it work
37+
- run: cd git-pack && cargo build --all-features --target ${{ matrix.target }}
38+
name: git-pack with all features (including wasm)

git-pack/Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ doctest = false
1717

1818
## Provide a fixed-size allocation-free LRU cache for packs. It's useful if caching is desired while keeping the memory footprint
1919
## for the LRU-cache itself low.
20-
pack-cache-lru-static = ["uluru"]
20+
pack-cache-lru-static = ["dep:uluru"]
2121
## Provide a hash-map based LRU cache whose eviction is based a memory cap calculated from object data.
22-
pack-cache-lru-dynamic = ["clru"]
22+
pack-cache-lru-dynamic = ["dep:clru"]
2323
## If set, select algorithms may additionally use a full-object cache which is queried before the pack itself.
24-
object-cache-dynamic = ["clru"]
24+
object-cache-dynamic = ["dep:clru"]
2525
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
26-
serde1 = ["serde", "git-object/serde1"]
26+
serde1 = ["dep:serde", "git-object/serde1"]
2727
## Make it possible to compile to the `wasm32-unknown-unknown` target.
2828
wasm = ["git-diff/wasm"]
2929

@@ -35,20 +35,24 @@ git-chunk = { version = "^0.4.1", path = "../git-chunk" }
3535
git-object = { version = "^0.26.1", path = "../git-object" }
3636
git-traverse = { version = "^0.22.1", path = "../git-traverse" }
3737
git-diff = { version = "^0.26.1", path = "../git-diff" }
38-
git-tempfile = { version = "^3.0.0", path = "../git-tempfile" }
3938
git-hashtable = { version = "^0.1.1", path = "../git-hashtable" }
4039

41-
smallvec = "1.3.0"
4240
memmap2 = "0.5.0"
43-
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
41+
smallvec = "1.3.0"
4442
bytesize = "1.0.1"
4543
parking_lot = { version = "0.12.0", default-features = false }
4644
thiserror = "1.0.26"
4745
uluru = { version = "3.0.0", optional = true }
4846
clru = { version = "0.6.1", optional = true }
49-
dashmap = "5.1.0"
5047

48+
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
49+
## If enabled, `cargo doc` will see feature documentation from this manifest.
5150
document-features = { version = "0.2.0", optional = true }
51+
dashmap = "5.1.0"
52+
53+
54+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
55+
git-tempfile = { version = "^3.0.0", path = "../git-tempfile" }
5256

5357
[dev-dependencies]
5458
git-testtools = { path = "../tests/tools"}

git-pack/src/bundle/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod init;
33

44
mod find;
55
///
6+
#[cfg(not(feature = "wasm"))]
67
pub mod write;
78

89
///

git-pack/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
)]
1818
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1919
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
20-
#![cfg(all(target_arch = "wasm32", target_os = "unknown", not(feature = "wasm")))]
21-
compile_error!("the wasm32-unknown-unknown target is not supported by default, and the \"wasm\" feature is required.");
2220

2321
///
2422
pub mod bundle;
2523
/// A bundle of pack data and the corresponding pack index
2624
pub struct Bundle {
2725
/// The pack file corresponding to `index`
28-
pub pack: crate::data::File,
26+
pub pack: data::File,
2927
/// The index file corresponding to `pack`
30-
pub index: crate::index::File,
28+
pub index: index::File,
3129
}
3230

3331
///
@@ -39,7 +37,6 @@ pub mod cache;
3937
pub mod data;
4038

4139
mod find_traits;
42-
4340
pub use find_traits::{Find, FindExt};
4441

4542
///

git-pack/tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rust-version = "1.64"
1313

1414
## Provide a fixed-size allocation-free LRU cache for packs. It's useful if caching is desired while keeping the memory footprint
1515
## for the LRU-cache itself low.
16-
pack-cache-lru-static = ["git-pack/uluru"]
16+
pack-cache-lru-static = ["git-pack/pack-cache-lru-static"]
1717
## Provide a hash-map based LRU cache whose eviction is based a memory cap calculated from object data.
1818
pack-cache-lru-dynamic = ["git-pack/pack-cache-lru-dynamic"]
1919
## If set, select algorithms may additionally use a full-object cache which is queried before the pack itself.

0 commit comments

Comments
 (0)