Skip to content

Commit 0d4b804

Browse files
committed
CI validates WASM support
For now failure is allowed as no work was done, but this should confirm the crate can at least be compiled to that target. We try different targets, including WASI, for good measure, and already build crates that are naturally working.
1 parent 109f434 commit 0d4b804

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

.github/workflows/wasm.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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: cargo build -p git-pack --target ${{ matrix.target }} // TODO: make something like it work

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)