Skip to content

Commit 560342b

Browse files
authored
Configure WASM tests an try isatty on wasi (#155)
1 parent 02fa5c0 commit 560342b

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.wasm32-wasi]
2+
runner = ["./scripts/wasmtime-wrapper.sh"]

.github/workflows/ci.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ jobs:
8080
env:
8181
CARGO_BUILD_TARGET: ${{ matrix.target }}
8282
run: make test
83-
wasm:
84-
name: Wasm
83+
wasm-check:
84+
name: WASM Check
8585
strategy:
8686
fail-fast: false
8787
matrix:
88-
target: [wasm32-unknown-unknown, wasm32-wasi]
88+
target: [wasm32-unknown-unknown]
8989
runs-on: ubuntu-latest
9090
steps:
9191
- name: Install rust
@@ -101,6 +101,33 @@ jobs:
101101
env:
102102
CARGO_BUILD_TARGET: ${{ matrix.target }}
103103
run: make check
104+
wasi:
105+
name: WASI
106+
strategy:
107+
fail-fast: false
108+
matrix:
109+
target: [wasm32-wasi]
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Install rust
113+
uses: actions-rs/toolchain@v1
114+
with:
115+
profile: minimal
116+
toolchain: stable
117+
target: ${{ matrix.target }}
118+
override: true
119+
- name: Checkout
120+
uses: actions/checkout@v3
121+
- name: Install WasmTime
122+
run: |
123+
curl https://wasmtime.dev/install.sh -sSf | bash
124+
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v4.0.0/wasmtime-v4.0.0-x86_64-linux.tar.xz
125+
tar xvf wasmtime-v4.0.0-x86_64-linux.tar.xz
126+
echo `pwd`/wasmtime-v4.0.0-x86_64-linux >> $GITHUB_PATH
127+
- name: Test
128+
env:
129+
CARGO_BUILD_TARGET: ${{ matrix.target }}
130+
run: make test
104131
nightly:
105132
name: Nightly Tests
106133
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ features = [
3535
]
3636

3737
[dev-dependencies]
38-
proptest = "1.0.0"
38+
# Pick a setup for proptest that works with wasi
39+
proptest = { version = "1.0.0", default-features = false, features = ["std", "bit-set", "break-dead-code"] }
3940
regex = "1.4.2"
4041

4142
## These are currently disabled. If you want to play around with the benchmarks

scripts/wasmtime-wrapper.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
cd $SCRIPT_DIR/..
4+
wasmtime run --env INSTA_WORKSPACE_ROOT=/ --mapdir "/::$(pwd)" -- "$@"

src/wasm_term.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ pub const DEFAULT_WIDTH: u16 = 80;
1010

1111
#[inline]
1212
pub fn is_a_terminal(_out: &Term) -> bool {
13-
false
13+
#[cfg(target = "wasm32-wasi")]
14+
{
15+
unsafe { libc::isatty(out.as_raw_fd()) != 0 }
16+
}
17+
#[cfg(not(target = "wasm32-wasi"))]
18+
{
19+
false
20+
}
1421
}
1522

1623
#[inline]
1724
pub fn is_a_color_terminal(_out: &Term) -> bool {
25+
// We currently never report color terminals. For discussion see
26+
// the issue in the WASI repo: https://github.com/WebAssembly/WASI/issues/162
1827
false
1928
}
2029

0 commit comments

Comments
 (0)