Skip to content

Commit

Permalink
Remove cargo-wasi and update WASI target (#782)
Browse files Browse the repository at this point in the history
* Remove cargo-wasi and update WASI target

* Remove cargo-wasi invocation I reintroduced

* Use CARGO_MANIFEST_DIR

* Smaller diff with main
  • Loading branch information
jeffcharles authored Oct 18, 2024
1 parent f2faf17 commit 6eef581
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://doc.rust-lang.org/cargo/reference/config.html
# Disable reference-types since Wizer (as of version 7.0.0) does not support
# reference-types.
[target.wasm32-wasi]
[target.wasm32-wasip1]
rustflags = [
"-C",
"target-feature=+simd128",
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: engine
path: target/wasm32-wasi/release/javy_core.wasm
path: target/wasm32-wasip1/release/javy_core.wasm

- name: Upload quickjs_provider to artifacts
uses: actions/upload-artifact@v4
with:
name: provider
path: target/wasm32-wasi/release/javy_quickjs_provider.wasm
path: target/wasm32-wasip1/release/javy_quickjs_provider.wasm

- name: Wizen and archive wizened quickjs_provider
run: |
wizer target/wasm32-wasi/release/javy_quickjs_provider.wasm --allow-wasi --init-func initialize_runtime --wasm-bulk-memory true -o target/wasm32-wasi/release/javy_quickjs_provider_wizened.wasm
gzip -k -f target/wasm32-wasi/release/javy_quickjs_provider_wizened.wasm && mv target/wasm32-wasi/release/javy_quickjs_provider_wizened.wasm.gz javy-quickjs_provider.wasm.gz
wizer target/wasm32-wasip1/release/javy_quickjs_provider.wasm --allow-wasi --init-func initialize_runtime --wasm-bulk-memory true -o target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm
gzip -k -f target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm && mv target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm.gz javy-quickjs_provider.wasm.gz
- name: Upload archived quickjs_provider to artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -133,12 +133,12 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: engine
path: target/wasm32-wasi/release/
path: target/wasm32-wasip1/release/

- uses: actions/download-artifact@v4
with:
name: provider
path: target/wasm32-wasi/release/
path: target/wasm32-wasip1/release/

- name: Build CLI ${{ matrix.os }}
run: cargo build --release --target ${{ matrix.target }} --package javy-cli
Expand Down
27 changes: 12 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@ jobs:
with:
os: macos

- name: Install cargo-wasi
run: cargo install cargo-wasi

- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack

- name: Compile core
run: cargo build -p javy-core --release --target=wasm32-wasi
run: cargo build -p javy-core --release --target=wasm32-wasip1

- name: Test
env:
CARGO_TARGET_WASM32_WASI_RUNNER: wasmtime --dir=.
run: cargo hack wasi test --workspace --exclude=javy-cli --exclude=javy-config --exclude=javy-runner --each-feature -- --nocapture
env:
CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime --dir=.
run: cargo hack test --target=wasm32-wasip1 --workspace --exclude=javy-cli --exclude=javy-config --exclude=javy-runner --each-feature -- --nocapture

- name: Test Config
run: cargo test --package=javy-config
Expand All @@ -50,24 +47,24 @@ jobs:
--exclude=javy-cli \
--exclude=javy-runner \
--exclude=javy-fuzz \
--target=wasm32-wasi --all-targets -- -D warnings
# We need to specify a different job for linting `javy-runner` given that
# it depends on Wasmtime and Cranelift cannot be compiled to `wasm32-wasi`
--target=wasm32-wasip1 --all-targets -- -D warnings
# We need to specify a different job for linting `javy-runner` given that
# it depends on Wasmtime and Cranelift cannot be compiled to `wasm32-wasip1`
- name: Lint Runner
run: cargo clippy --package=javy-runner -- -D warnings

- name: Upload core binary to artifacts
uses: actions/upload-artifact@v4
with:
name: engine
path: target/wasm32-wasi/release/javy_core.wasm
path: target/wasm32-wasip1/release/javy_core.wasm

- name: Upload quickjs_provider to artifacts
uses: actions/upload-artifact@v4
with:
name: provider
path: target/wasm32-wasi/release/javy_quickjs_provider.wasm
path: target/wasm32-wasip1/release/javy_quickjs_provider.wasm

cli:
name: test_cli
Expand All @@ -83,12 +80,12 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: engine
path: target/wasm32-wasi/release/
path: target/wasm32-wasip1/release/

- uses: actions/download-artifact@v4
with:
name: provider
path: target/wasm32-wasi/release/
path: target/wasm32-wasip1/release/

- name: Test CLI
run: CARGO_PROFILE_RELEASE_LTO=off cargo test --package=javy-cli --release -- --nocapture
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cli-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:

- name: Test `experimental_event_loop`
run: |
cargo build --package=javy-core --target=wasm32-wasi --release --features=experimental_event_loop
cargo build --package=javy-core --target=wasm32-wasip1 --release --features=experimental_event_loop
cargo test --package=javy-cli --features=experimental_event_loop --release -- --nocapture
2 changes: 1 addition & 1 deletion .github/workflows/wpt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: WPT
run: |
cargo build --package=javy-core --release --target=wasm32-wasi --features=experimental_event_loop
cargo build --package=javy-core --release --target=wasm32-wasip1 --features=experimental_event_loop
CARGO_PROFILE_RELEASE_LTO=off cargo build --package=javy-cli --release
npm install --prefix wpt
npm test --prefix wpt
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ cli: core
CARGO_PROFILE_RELEASE_LTO=off cargo build --package=javy-cli --release

core:
cargo build --package=javy-core --release --target=wasm32-wasi --features=$(CORE_FEATURES)
cargo build --package=javy-core --release --target=wasm32-wasip1 --features=$(CORE_FEATURES)

docs:
cargo doc --package=javy-cli --open
cargo doc --package=javy-core --open --target=wasm32-wasi
cargo doc --package=javy-core --open --target=wasm32-wasip1

test-javy:
CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=." cargo wasi test --package=javy --features json,messagepack -- --nocapture
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime --dir=." cargo test --package=javy --target=wasm32-wasip1 --features json,messagepack -- --nocapture

test-core:
cargo wasi test --package=javy-core -- --nocapture
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime" cargo test --package=javy-core --target=wasm32-wasip1 -- --nocapture

# Test in release mode to skip some debug assertions
# Note: to make this faster, the engine should be optimized beforehand (wasm-strip + wasm-opt).
Expand Down Expand Up @@ -53,11 +53,11 @@ fmt: fmt-javy fmt-core fmt-cli

fmt-javy:
cargo fmt --package=javy -- --check
cargo clippy --package=javy --target=wasm32-wasi --all-targets -- -D warnings
cargo clippy --package=javy --target=wasm32-wasip1 --all-targets -- -D warnings

fmt-core:
cargo fmt --package=javy-core -- --check
cargo clippy --package=javy-core --target=wasm32-wasi --all-targets -- -D warnings
cargo clippy --package=javy-core --target=wasm32-wasip1 --all-targets -- -D warnings

# Use `--release` on CLI clippy to align with `test-cli`.
# This reduces the size of the target directory which improves CI stability.
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl FunctionCase {
let qjs_provider = Module::new(
&self.engine,
fs::read(Path::new(
"../../target/wasm32-wasi/release/javy_quickjs_provider_wizened.wasm",
"../../target/wasm32-wasip1/release/javy_quickjs_provider_wizened.wasm",
))?,
)?;
let instance = linker.instantiate(store.as_context_mut(), &qjs_provider)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn copy_javy_core() -> Result<()> {
.unwrap()
.parent()
.unwrap()
.join("target/wasm32-wasi/release");
.join("target/wasm32-wasip1/release");
let engine_path = module_path.join("javy_core.wasm");
let quickjs_provider_path = module_path.join("javy_quickjs_provider.wasm");
let quickjs_provider_wizened_path = module_path.join("javy_quickjs_provider_wizened.wasm");
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/dylib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn provider_module() -> Result<Vec<u8>> {
lib_path.pop();
lib_path = lib_path.join(
Path::new("target")
.join("wasm32-wasi")
.join("wasm32-wasip1")
.join("release")
.join("javy_quickjs_provider_wizened.wasm"),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/javy/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

cargo publish --target=wasm32-wasi
cargo publish --target=wasm32-wasip1
2 changes: 1 addition & 1 deletion crates/javy/tests/262.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#[cfg(feature = "json")]
javy_test_macros::t262!(path = "crates/javy/test262");
javy_test_macros::t262!(path = "./test262");
17 changes: 11 additions & 6 deletions crates/test-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use anyhow::bail;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use std::path::{Path, PathBuf};
use std::{env, path::PathBuf};
use syn::{meta::ParseNestedMeta, parse_macro_input, Ident, LitBool, LitStr, Result, ReturnType};

struct Config262 {
Expand All @@ -23,8 +23,10 @@ struct Config262 {

impl Config262 {
fn validate(&self) -> anyhow::Result<()> {
let path: Box<Path> = self.root.clone().into();
if path.is_dir() {
if PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.join(&self.root)
.is_dir()
{
Ok(())
} else {
bail!("Invalid path")
Expand Down Expand Up @@ -116,10 +118,13 @@ fn gen_tests(
harness_str: &String,
prefix: &'static str,
) -> proc_macro2::TokenStream {
let parse_dir = std::fs::read_dir(dir).expect("parse directory to be available");
let package_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let parse_dir =
std::fs::read_dir(package_path.join(dir)).expect("parse directory to be available");
let spec = parse_dir.filter_map(|e| e.ok()).map(move |entry| {
let path = entry.path();
let path_str = path.clone().into_os_string().into_string().unwrap();
let path = path.strip_prefix(&package_path).unwrap();
let path_str = path.to_str().unwrap();
let name = path.file_stem().unwrap().to_str().unwrap();
let name = name.replace('.', "_");
let name = name.replace('-', "_");
Expand Down Expand Up @@ -299,7 +304,7 @@ fn expand_cli_tests(test_config: &CliTestConfig, func: syn::ItemFn) -> Result<To
root.pop();
root = root.join(
std::path::Path::new("target")
.join("wasm32-wasi")
.join("wasm32-wasip1")
.join("release")
.join("javy_quickjs_provider_wizened.wasm"),
);
Expand Down
2 changes: 1 addition & 1 deletion docs/docs-contributing-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We anticipate most changes will be to the `javy-cli` and `javy` crates.
### `javy`

The entrypoint for working with Javy as a library for third parties. This crate
is intended to compile to `wasm32-wasi` and provide ergonomic APIs for
is intended to compile to `wasm32-wasip1` and provide ergonomic APIs for
configuring a QuickJS-based runtime. If there is a configuration option for
QuickJS that would be helpful, this is the place to add it.

Expand Down
6 changes: 3 additions & 3 deletions docs/docs-contributing-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- On Ubuntu, `sudo apt-get install curl pkg-config libssl-dev clang`
- [rustup](https://rustup.rs/)
- Stable Rust, installed via `rustup install stable && rustup default stable`
- wasm32-wasi, can be installed via `rustup target add wasm32-wasi`
- wasm32-wasip1, can be installed via `rustup target add wasm32-wasip1`
- cmake, depending on your operating system and architecture, it might not be
installed by default. On MacOS it can be installed with `homebrew` via `brew
install cmake`. On Ubuntu, `sudo apt-get install cmake`.
Expand All @@ -15,14 +15,14 @@
In the repository root, run:

```
$ cargo build -p javy-core --target=wasm32-wasi -r
$ cargo build -p javy-core --target=wasm32-wasip1 -r
$ cargo build -p javy-cli -r
```

Alternatively if you want to install the `javy` binary globally, at the
repository root, run:
```
$ cargo build -p javy-core --target=wasm32-wasi -r
$ cargo build -p javy-core --target=wasm32-wasip1 -r
$ cargo install --path crates/cli
```

Expand Down
4 changes: 1 addition & 3 deletions docs/docs-contributing-developing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Development requirements

- `wasmtime-cli`, can be installed via `cargo install wasmtime-cli` (required for
`cargo-wasi`)
- `cargo-wasi`, can be installed via `cargo install cargo-wasi`
- `wasmtime-cli`, can be installed via `cargo install wasmtime-cli`
- `cargo-hack`, can be installed via `cargo +stable install cargo-hack --locked`
2 changes: 1 addition & 1 deletion docs/docs-contributing-testing-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ cargo +stable install cargo-hack --locked

3. Run tests, eg:
```
CARGO_TARGET_WASM32_WASI_RUNNER="wasmtime --dir=." cargo hack wasi test --workspace --exclude=javy-cli --exclude=javy-config --each-feature -- --nocapture
CARGO_TARGET_WASM32_WASIP1_RUNNER="wasmtime --dir=." cargo hack test --target=wasm32-wasip1 --workspace --exclude=javy-cli --exclude=javy-config --each-feature -- --nocapture
```
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "stable"
components = ["clippy", "rustfmt"]
targets = ["wasm32-wasi"]
targets = ["wasm32-wasip1"]
profile = "default"

0 comments on commit 6eef581

Please sign in to comment.