Skip to content

Commit 4bc19d1

Browse files
committed
Merge branch 'git-pack-wasm'
2 parents f86b780 + 6c4c196 commit 4bc19d1

File tree

8 files changed

+69
-18
lines changed

8 files changed

+69
-18
lines changed

.github/workflows/wasm.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: WASM
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags-ignore: [ '*' ]
7+
paths:
8+
- '.github/**'
9+
- 'git-pack/**'
10+
- '*.toml'
11+
pull_request:
12+
branches: [ main ]
13+
paths:
14+
- '.github/**'
15+
- 'git-pack/**'
16+
- '*.toml'
17+
18+
jobs:
19+
wasm:
20+
name: WebAssembly
21+
runs-on: ubuntu-latest
22+
continue-on-error: true
23+
strategy:
24+
matrix:
25+
target: [ wasm32-unknown-unknown, wasm32-wasi ]
26+
steps:
27+
- uses: actions/checkout@master
28+
- name: Install Rust
29+
run: rustup update stable && rustup default stable && rustup target add ${{ matrix.target }}
30+
- uses: Swatinem/rust-cache@v2
31+
- run: set +x; for name in git-actor git-attributes git-bitmap git-chunk git-command git-commitgraph git-date git-glob git-hash git-hashtable git-mailmap git-object git-packetline git-path git-pathspec git-quote git-refspec git-revision git-traverse git-validate; do (cd $name && cargo build --target ${{ matrix.target }}); done
32+
name: crates without feature toggles
33+
- 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
34+
name: features of git-features
35+
- run: set +x; for name in git-diff git-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
36+
name: crates with 'wasm' feature
37+
- run: cd git-pack && cargo build --all-features --target ${{ matrix.target }}
38+
name: git-pack with all features (including wasm)

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-diff/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ rust-version = "1.64"
1111
autotests = false
1212

1313
[features]
14+
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
1415
serde1 = ["serde", "git-hash/serde1", "git-object/serde1"]
16+
## Make it possible to compile to the `wasm32-unknown-unknown` target.
17+
wasm = ["dep:getrandom"]
1518

1619
[lib]
1720
doctest = false
@@ -22,3 +25,4 @@ git-object = { version = "^0.26.1", path = "../git-object" }
2225
thiserror = "1.0.32"
2326
imara-diff = "0.1.3"
2427
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
28+
getrandom = { version = "0.2.8", optional = true, default-features = false, features = ["js"] }

git-pack/Cargo.toml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ 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"]
27+
## Make it possible to compile to the `wasm32-unknown-unknown` target.
28+
wasm = ["git-diff/wasm"]
2729

2830
[dependencies]
2931
git-features = { version = "^0.26.4", path = "../git-features", features = ["crc32", "rustsha1", "progress", "zlib"] }
@@ -33,20 +35,24 @@ git-chunk = { version = "^0.4.1", path = "../git-chunk" }
3335
git-object = { version = "^0.26.1", path = "../git-object" }
3436
git-traverse = { version = "^0.22.1", path = "../git-traverse" }
3537
git-diff = { version = "^0.26.1", path = "../git-diff" }
36-
git-tempfile = { version = "^3.0.0", path = "../git-tempfile" }
3738
git-hashtable = { version = "^0.1.1", path = "../git-hashtable" }
3839

39-
smallvec = "1.3.0"
4040
memmap2 = "0.5.0"
41-
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
41+
smallvec = "1.3.0"
4242
bytesize = "1.0.1"
4343
parking_lot = { version = "0.12.0", default-features = false }
4444
thiserror = "1.0.26"
4545
uluru = { version = "3.0.0", optional = true }
4646
clru = { version = "0.6.1", optional = true }
47-
dashmap = "5.1.0"
4847

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.
4950
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" }
5056

5157
[dev-dependencies]
5258
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub mod bundle;
2323
/// A bundle of pack data and the corresponding pack index
2424
pub struct Bundle {
2525
/// The pack file corresponding to `index`
26-
pub pack: crate::data::File,
26+
pub pack: data::File,
2727
/// The index file corresponding to `pack`
28-
pub index: crate::index::File,
28+
pub index: index::File,
2929
}
3030

3131
///
@@ -37,7 +37,6 @@ pub mod cache;
3737
pub mod data;
3838

3939
mod find_traits;
40-
4140
pub use find_traits::{Find, FindExt};
4241

4342
///

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.

git-path/src/convert.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn try_into_bstr<'a>(path: impl Into<Cow<'a, Path>>) -> Result<Cow<'a, BStr>
5454
use std::os::wasi::ffi::OsStringExt;
5555
path.into_os_string().into_vec().into()
5656
};
57-
#[cfg(not(unix))]
57+
#[cfg(not(any(unix, target_os = "wasi")))]
5858
let p: BString = path.into_os_string().into_string().map_err(|_| Utf8Error)?.into();
5959
p
6060
}),
@@ -69,7 +69,7 @@ pub fn try_into_bstr<'a>(path: impl Into<Cow<'a, Path>>) -> Result<Cow<'a, BStr>
6969
use std::os::wasi::ffi::OsStrExt;
7070
path.as_os_str().as_bytes().into()
7171
};
72-
#[cfg(not(unix))]
72+
#[cfg(not(any(unix, target_os = "wasi")))]
7373
let p: &BStr = path.to_str().ok_or(Utf8Error)?.as_bytes().into();
7474
p
7575
}),
@@ -94,11 +94,11 @@ pub fn try_from_byte_slice(input: &[u8]) -> Result<&Path, Utf8Error> {
9494
OsStr::from_bytes(input).as_ref()
9595
};
9696
#[cfg(target_os = "wasi")]
97-
let p = {
97+
let p: &Path = {
9898
use std::os::wasi::ffi::OsStrExt;
9999
OsStr::from_bytes(input).as_ref()
100100
};
101-
#[cfg(not(unix))]
101+
#[cfg(not(any(unix, target_os = "wasi")))]
102102
let p = Path::new(std::str::from_utf8(input).map_err(|_| Utf8Error)?);
103103
Ok(p)
104104
}
@@ -126,11 +126,11 @@ pub fn try_from_bstring(input: impl Into<BString>) -> Result<PathBuf, Utf8Error>
126126
std::ffi::OsString::from_vec(input.into()).into()
127127
};
128128
#[cfg(target_os = "wasi")]
129-
let p = {
129+
let p: PathBuf = {
130130
use std::os::wasi::ffi::OsStringExt;
131131
std::ffi::OsString::from_vec(input.into()).into()
132132
};
133-
#[cfg(not(unix))]
133+
#[cfg(not(any(unix, target_os = "wasi")))]
134134
let p = {
135135
use bstr::ByteVec;
136136
PathBuf::from(

0 commit comments

Comments
 (0)