Skip to content

Commit

Permalink
Configure WASM tests an try isatty on wasi (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Jan 16, 2023
1 parent 02fa5c0 commit 560342b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-wasi]
runner = ["./scripts/wasmtime-wrapper.sh"]
33 changes: 30 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ jobs:
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
run: make test
wasm:
name: Wasm
wasm-check:
name: WASM Check
strategy:
fail-fast: false
matrix:
target: [wasm32-unknown-unknown, wasm32-wasi]
target: [wasm32-unknown-unknown]
runs-on: ubuntu-latest
steps:
- name: Install rust
Expand All @@ -101,6 +101,33 @@ jobs:
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
run: make check
wasi:
name: WASI
strategy:
fail-fast: false
matrix:
target: [wasm32-wasi]
runs-on: ubuntu-latest
steps:
- name: Install rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Checkout
uses: actions/checkout@v3
- name: Install WasmTime
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v4.0.0/wasmtime-v4.0.0-x86_64-linux.tar.xz
tar xvf wasmtime-v4.0.0-x86_64-linux.tar.xz
echo `pwd`/wasmtime-v4.0.0-x86_64-linux >> $GITHUB_PATH
- name: Test
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
run: make test
nightly:
name: Nightly Tests
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ features = [
]

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

## These are currently disabled. If you want to play around with the benchmarks
Expand Down
4 changes: 4 additions & 0 deletions scripts/wasmtime-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_DIR/..
wasmtime run --env INSTA_WORKSPACE_ROOT=/ --mapdir "/::$(pwd)" -- "$@"
11 changes: 10 additions & 1 deletion src/wasm_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ pub const DEFAULT_WIDTH: u16 = 80;

#[inline]
pub fn is_a_terminal(_out: &Term) -> bool {
false
#[cfg(target = "wasm32-wasi")]
{
unsafe { libc::isatty(out.as_raw_fd()) != 0 }
}
#[cfg(not(target = "wasm32-wasi"))]
{
false
}
}

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

Expand Down

0 comments on commit 560342b

Please sign in to comment.