Skip to content

preliminary wasm32 support for git-pack #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: WASM

on:
push:
branches: [ main ]
tags-ignore: [ '*' ]
paths:
- '.github/**'
- 'git-pack/**'
- '*.toml'
pull_request:
branches: [ main ]
paths:
- '.github/**'
- 'git-pack/**'
- '*.toml'

jobs:
wasm:
name: WebAssembly
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
target: [ wasm32-unknown-unknown, wasm32-wasi ]
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable && rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- 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
name: crates without feature toggles
- 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
name: features of git-features
- run: set +x; for name in git-diff git-pack; do (cd $name && cargo build --features wasm --target ${{ matrix.target }}); done
name: crates with 'wasm' feature
- run: cd git-pack && cargo build --all-features --target ${{ matrix.target }}
name: git-pack with all features (including wasm)
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions git-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ rust-version = "1.64"
autotests = false

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

[lib]
doctest = false
Expand All @@ -22,3 +25,4 @@ git-object = { version = "^0.26.1", path = "../git-object" }
thiserror = "1.0.32"
imara-diff = "0.1.3"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
getrandom = { version = "0.2.8", optional = true, default-features = false, features = ["js"] }
22 changes: 14 additions & 8 deletions git-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ doctest = false

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

[dependencies]
git-features = { version = "^0.26.4", path = "../git-features", features = ["crc32", "rustsha1", "progress", "zlib"] }
Expand All @@ -33,20 +35,24 @@ git-chunk = { version = "^0.4.1", path = "../git-chunk" }
git-object = { version = "^0.26.1", path = "../git-object" }
git-traverse = { version = "^0.22.1", path = "../git-traverse" }
git-diff = { version = "^0.26.1", path = "../git-diff" }
git-tempfile = { version = "^3.0.0", path = "../git-tempfile" }
git-hashtable = { version = "^0.1.1", path = "../git-hashtable" }

smallvec = "1.3.0"
memmap2 = "0.5.0"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
smallvec = "1.3.0"
bytesize = "1.0.1"
parking_lot = { version = "0.12.0", default-features = false }
thiserror = "1.0.26"
uluru = { version = "3.0.0", optional = true }
clru = { version = "0.6.1", optional = true }
dashmap = "5.1.0"

serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
## If enabled, `cargo doc` will see feature documentation from this manifest.
document-features = { version = "0.2.0", optional = true }
dashmap = "5.1.0"


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
git-tempfile = { version = "^3.0.0", path = "../git-tempfile" }

[dev-dependencies]
git-testtools = { path = "../tests/tools"}
Expand Down
1 change: 1 addition & 0 deletions git-pack/src/bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod init;

mod find;
///
#[cfg(not(feature = "wasm"))]
pub mod write;

///
Expand Down
5 changes: 2 additions & 3 deletions git-pack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub mod bundle;
/// A bundle of pack data and the corresponding pack index
pub struct Bundle {
/// The pack file corresponding to `index`
pub pack: crate::data::File,
pub pack: data::File,
/// The index file corresponding to `pack`
pub index: crate::index::File,
pub index: index::File,
}

///
Expand All @@ -37,7 +37,6 @@ pub mod cache;
pub mod data;

mod find_traits;

pub use find_traits::{Find, FindExt};

///
Expand Down
2 changes: 1 addition & 1 deletion git-pack/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = "1.64"

## Provide a fixed-size allocation-free LRU cache for packs. It's useful if caching is desired while keeping the memory footprint
## for the LRU-cache itself low.
pack-cache-lru-static = ["git-pack/uluru"]
pack-cache-lru-static = ["git-pack/pack-cache-lru-static"]
## Provide a hash-map based LRU cache whose eviction is based a memory cap calculated from object data.
pack-cache-lru-dynamic = ["git-pack/pack-cache-lru-dynamic"]
## If set, select algorithms may additionally use a full-object cache which is queried before the pack itself.
Expand Down
12 changes: 6 additions & 6 deletions git-path/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn try_into_bstr<'a>(path: impl Into<Cow<'a, Path>>) -> Result<Cow<'a, BStr>
use std::os::wasi::ffi::OsStringExt;
path.into_os_string().into_vec().into()
};
#[cfg(not(unix))]
#[cfg(not(any(unix, target_os = "wasi")))]
let p: BString = path.into_os_string().into_string().map_err(|_| Utf8Error)?.into();
p
}),
Expand All @@ -69,7 +69,7 @@ pub fn try_into_bstr<'a>(path: impl Into<Cow<'a, Path>>) -> Result<Cow<'a, BStr>
use std::os::wasi::ffi::OsStrExt;
path.as_os_str().as_bytes().into()
};
#[cfg(not(unix))]
#[cfg(not(any(unix, target_os = "wasi")))]
let p: &BStr = path.to_str().ok_or(Utf8Error)?.as_bytes().into();
p
}),
Expand All @@ -94,11 +94,11 @@ pub fn try_from_byte_slice(input: &[u8]) -> Result<&Path, Utf8Error> {
OsStr::from_bytes(input).as_ref()
};
#[cfg(target_os = "wasi")]
let p = {
let p: &Path = {
use std::os::wasi::ffi::OsStrExt;
OsStr::from_bytes(input).as_ref()
};
#[cfg(not(unix))]
#[cfg(not(any(unix, target_os = "wasi")))]
let p = Path::new(std::str::from_utf8(input).map_err(|_| Utf8Error)?);
Ok(p)
}
Expand Down Expand Up @@ -126,11 +126,11 @@ pub fn try_from_bstring(input: impl Into<BString>) -> Result<PathBuf, Utf8Error>
std::ffi::OsString::from_vec(input.into()).into()
};
#[cfg(target_os = "wasi")]
let p = {
let p: PathBuf = {
use std::os::wasi::ffi::OsStringExt;
std::ffi::OsString::from_vec(input.into()).into()
};
#[cfg(not(unix))]
#[cfg(not(any(unix, target_os = "wasi")))]
let p = {
use bstr::ByteVec;
PathBuf::from(
Expand Down