From a98dab16a727fedcd63b3f3c619a79fe9bc0c4e3 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Sun, 2 Mar 2025 11:40:20 +0100 Subject: [PATCH 1/3] Add `nighlty` feature for wasip2 support --- .github/workflows/ci.yml | 48 ++++++++++++++++---------------- README.md | 2 +- examples/Cargo.toml | 3 ++ file-id/Cargo.toml | 3 ++ file-id/README.md | 2 ++ file-id/bin/file_id.rs | 2 +- file-id/src/lib.rs | 13 +++++++++ notify-debouncer-full/Cargo.toml | 1 + notify-debouncer-full/README.md | 2 ++ notify-debouncer-mini/Cargo.toml | 1 + notify/Cargo.toml | 1 + 11 files changed, 52 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76e00eba..8f64de5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,27 +151,27 @@ jobs: - name: Build for Android (arm) run: cargo ndk --target armv7-linux-androideabi build --verbose - # # WebAssembly System Interface (WASI) - # wasi: - # name: WASI - # runs-on: ubuntu-latest - # needs: quality - # steps: - # - uses: actions/checkout@v4 - - # - name: Remove rust-toolchain.toml - # run: rm -f rust-toolchain.toml - - # - name: Install Rust - # uses: dtolnay/rust-toolchain@nightly - # with: - # targets: wasm32-wasip2 - - # - name: Cache dependencies - # uses: Swatinem/rust-cache@v2 - - # - name: Build for WASI - # run: cargo build --target wasm32-wasip2 --verbose - - # - name: Build examples for WASI - # run: cargo build --examples --target wasm32-wasip2 --verbose + # WebAssembly System Interface (WASI) + wasi: + name: WASI + runs-on: ubuntu-latest + needs: quality + steps: + - uses: actions/checkout@v4 + + - name: Remove rust-toolchain.toml + run: rm -f rust-toolchain.toml + + - name: Install Rust + uses: dtolnay/rust-toolchain@nightly + with: + targets: wasm32-wasip2 + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Build for WASI + run: cargo build --target wasm32-wasip2 --features nightly --verbose + + - name: Build examples for WASI + run: cargo build --examples --target wasm32-wasip2 --features nightly --verbose diff --git a/README.md b/README.md index abbb3a8a..8ccfcf96 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ _Cross-platform filesystem notification library for Rust._ - [Notify Types Documentation][notify-types-docs] - [Mini Debouncer Documentation][debouncer-mini-docs] - [Full Debouncer Documentation][debouncer-full-docs] -- [File ID][file-id-docs] +- [File ID Documentation][file-id-docs] - [Examples][examples] - [Changelog][changelog] - [Upgrading notify from v4](UPGRADING_V4_TO_V5.md) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d6e08ce5..5e864cf6 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -5,6 +5,9 @@ publish = false edition = "2021" license = "MIT OR Apache-2.0" +[features] +nightly = ["tempfile/nightly"] + [dev-dependencies] notify = { workspace = true } notify-debouncer-mini = { workspace = true } diff --git a/file-id/Cargo.toml b/file-id/Cargo.toml index fa615f63..f78fd028 100644 --- a/file-id/Cargo.toml +++ b/file-id/Cargo.toml @@ -13,6 +13,9 @@ edition.workspace = true homepage.workspace = true repository.workspace = true +[features] +nightly = ["tempfile/nightly"] + [[bin]] name = "file-id" path = "bin/file_id.rs" diff --git a/file-id/README.md b/file-id/README.md index 4d47e79a..6c8d113c 100644 --- a/file-id/README.md +++ b/file-id/README.md @@ -21,4 +21,6 @@ println!("{file_id:?}"); - `serde` for serde support, off by default +- `nightly` for wasip2 support, off by default + [docs]: https://docs.rs/file-id diff --git a/file-id/bin/file_id.rs b/file-id/bin/file_id.rs index 9f9c900d..c8be6941 100644 --- a/file-id/bin/file_id.rs +++ b/file-id/bin/file_id.rs @@ -8,7 +8,7 @@ fn main() { print_file_id(&path); } -#[cfg(target_family = "unix")] +#[cfg(any(target_family = "unix", target_family = "wasm"))] fn print_file_id(path: &str) { print_result(file_id::get_file_id(path)); } diff --git a/file-id/src/lib.rs b/file-id/src/lib.rs index cd92136f..edff863c 100644 --- a/file-id/src/lib.rs +++ b/file-id/src/lib.rs @@ -27,6 +27,9 @@ //! let file_id = file_id::get_high_res_file_id(file.path()).unwrap(); //! println!("{file_id:?}"); //! ``` + +#![cfg_attr(feature = "nightly", feature(wasip2, wasi_ext))] + use std::{fs, io, path::Path}; #[cfg(feature = "serde")] @@ -122,6 +125,16 @@ pub fn get_file_id(path: impl AsRef) -> io::Result { Ok(FileId::new_inode(metadata.dev(), metadata.ino())) } +/// Get the `FileId` for the file or directory at `path` +#[cfg(target_family = "wasm")] +pub fn get_file_id(path: impl AsRef) -> io::Result { + use std::os::wasi::fs::MetadataExt; + + let metadata = fs::metadata(path.as_ref())?; + + Ok(FileId::new_inode(metadata.dev(), metadata.ino())) +} + /// Get the `FileId` for the file or directory at `path` #[cfg(target_family = "windows")] pub fn get_file_id(path: impl AsRef) -> io::Result { diff --git a/notify-debouncer-full/Cargo.toml b/notify-debouncer-full/Cargo.toml index 07c7510e..631eeae0 100644 --- a/notify-debouncer-full/Cargo.toml +++ b/notify-debouncer-full/Cargo.toml @@ -20,6 +20,7 @@ crossbeam-channel = ["dep:crossbeam-channel", "notify/crossbeam-channel"] macos_fsevent = ["notify/macos_fsevent"] macos_kqueue = ["notify/macos_kqueue"] serialization-compat-6 = ["notify/serialization-compat-6"] +nightly = ["file-id/nightly", "tempfile/nightly"] [dependencies] notify.workspace = true diff --git a/notify-debouncer-full/README.md b/notify-debouncer-full/README.md index 19a49bc7..c644696a 100644 --- a/notify-debouncer-full/README.md +++ b/notify-debouncer-full/README.md @@ -18,5 +18,7 @@ A debouncer for [notify] that is optimized for ease of use. - `serialization-compat-6` passed down to notify, off by default +- `nightly` passed down to file-id, off by default + [docs]: https://docs.rs/notify-debouncer-full [notify]: https://crates.io/crates/notify diff --git a/notify-debouncer-mini/Cargo.toml b/notify-debouncer-mini/Cargo.toml index 3a5c5a71..c6b45dd1 100644 --- a/notify-debouncer-mini/Cargo.toml +++ b/notify-debouncer-mini/Cargo.toml @@ -19,6 +19,7 @@ crossbeam-channel = ["dep:crossbeam-channel", "notify/crossbeam-channel"] macos_fsevent = ["notify/macos_fsevent"] macos_kqueue = ["notify/macos_kqueue"] serialization-compat-6 = ["notify/serialization-compat-6"] +nightly = ["tempfile/nightly"] [dependencies] notify.workspace = true diff --git a/notify/Cargo.toml b/notify/Cargo.toml index 0bf6de82..c157df67 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -23,6 +23,7 @@ serde = ["notify-types/serde"] macos_kqueue = ["kqueue", "mio"] macos_fsevent = ["fsevent-sys"] serialization-compat-6 = ["notify-types/serialization-compat-6"] +nightly = ["tempfile/nightly"] [dependencies] notify-types.workspace = true From 24877ccaf5e52e7c9e67ebfa4a8b035d204d6d5f Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Sun, 2 Mar 2025 12:38:44 +0100 Subject: [PATCH 2/3] Remove `nightly` feature --- .github/workflows/ci.yml | 23 +++++++++++++++++++++-- examples/Cargo.toml | 10 ++++++---- file-id/Cargo.toml | 10 +++++----- file-id/README.md | 2 -- file-id/src/lib.rs | 2 +- notify-debouncer-full/Cargo.toml | 8 ++++++-- notify-debouncer-full/README.md | 2 -- notify-debouncer-mini/Cargo.toml | 8 ++++++-- notify/Cargo.toml | 8 ++++++-- 9 files changed, 51 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f64de5f..738c8528 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,9 +169,28 @@ jobs: - name: Cache dependencies uses: Swatinem/rust-cache@v2 + + # - name: Install wasmtime + # uses: taiki-e/install-action@v2 + # with: + # tool: wasmtime + + # - name: Install cargo-wasi + # uses: taiki-e/install-action@v2 + # with: + # tool: cargo-wasi + + # - name: Build for WASI + # run: cargo wasi build --features nightly --verbose + + # - name: Build examples for WASI + # run: cargo wasi build --features nightly --examples --verbose + + # - name: Run tests in WASI environment + # run: cargo wasi test --features nightly --verbose - name: Build for WASI - run: cargo build --target wasm32-wasip2 --features nightly --verbose + run: cargo build --target wasm32-wasip2 --verbose - name: Build examples for WASI - run: cargo build --examples --target wasm32-wasip2 --features nightly --verbose + run: cargo build --examples --target wasm32-wasip2 --verbose diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5e864cf6..e7f21180 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -5,18 +5,20 @@ publish = false edition = "2021" license = "MIT OR Apache-2.0" -[features] -nightly = ["tempfile/nightly"] - [dev-dependencies] notify = { workspace = true } notify-debouncer-mini = { workspace = true } notify-debouncer-full = { workspace = true } futures = { workspace = true } -tempfile = { workspace = true } log = { workspace = true } env_logger = { workspace = true } +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] +tempfile = { workspace = true } + +[target.'cfg(target_family = "wasm")'.dev-dependencies] +tempfile = { workspace = true, features = ["nightly"] } + [[example]] name = "async_monitor" path = "async_monitor.rs" diff --git a/file-id/Cargo.toml b/file-id/Cargo.toml index f78fd028..ff1d1ed1 100644 --- a/file-id/Cargo.toml +++ b/file-id/Cargo.toml @@ -13,9 +13,6 @@ edition.workspace = true homepage.workspace = true repository.workspace = true -[features] -nightly = ["tempfile/nightly"] - [[bin]] name = "file-id" path = "bin/file_id.rs" @@ -26,5 +23,8 @@ serde = { workspace = true, optional = true } [target.'cfg(windows)'.dependencies] windows-sys = { workspace = true, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] } -[dev-dependencies] -tempfile.workspace = true +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] +tempfile = { workspace = true } + +[target.'cfg(target_family = "wasm")'.dev-dependencies] +tempfile = { workspace = true, features = ["nightly"] } diff --git a/file-id/README.md b/file-id/README.md index 6c8d113c..4d47e79a 100644 --- a/file-id/README.md +++ b/file-id/README.md @@ -21,6 +21,4 @@ println!("{file_id:?}"); - `serde` for serde support, off by default -- `nightly` for wasip2 support, off by default - [docs]: https://docs.rs/file-id diff --git a/file-id/src/lib.rs b/file-id/src/lib.rs index edff863c..acd76ffa 100644 --- a/file-id/src/lib.rs +++ b/file-id/src/lib.rs @@ -28,7 +28,7 @@ //! println!("{file_id:?}"); //! ``` -#![cfg_attr(feature = "nightly", feature(wasip2, wasi_ext))] +#![cfg_attr(target_family = "wasm", feature(wasip2, wasi_ext))] use std::{fs, io, path::Path}; diff --git a/notify-debouncer-full/Cargo.toml b/notify-debouncer-full/Cargo.toml index 631eeae0..ece7a461 100644 --- a/notify-debouncer-full/Cargo.toml +++ b/notify-debouncer-full/Cargo.toml @@ -20,7 +20,6 @@ crossbeam-channel = ["dep:crossbeam-channel", "notify/crossbeam-channel"] macos_fsevent = ["notify/macos_fsevent"] macos_kqueue = ["notify/macos_kqueue"] serialization-compat-6 = ["notify/serialization-compat-6"] -nightly = ["file-id/nightly", "tempfile/nightly"] [dependencies] notify.workspace = true @@ -36,4 +35,9 @@ rstest.workspace = true serde.workspace = true deser-hjson.workspace = true rand.workspace = true -tempfile.workspace = true + +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] +tempfile = { workspace = true } + +[target.'cfg(target_family = "wasm")'.dev-dependencies] +tempfile = { workspace = true, features = ["nightly"] } diff --git a/notify-debouncer-full/README.md b/notify-debouncer-full/README.md index c644696a..19a49bc7 100644 --- a/notify-debouncer-full/README.md +++ b/notify-debouncer-full/README.md @@ -18,7 +18,5 @@ A debouncer for [notify] that is optimized for ease of use. - `serialization-compat-6` passed down to notify, off by default -- `nightly` passed down to file-id, off by default - [docs]: https://docs.rs/notify-debouncer-full [notify]: https://crates.io/crates/notify diff --git a/notify-debouncer-mini/Cargo.toml b/notify-debouncer-mini/Cargo.toml index c6b45dd1..177920f5 100644 --- a/notify-debouncer-mini/Cargo.toml +++ b/notify-debouncer-mini/Cargo.toml @@ -19,11 +19,15 @@ crossbeam-channel = ["dep:crossbeam-channel", "notify/crossbeam-channel"] macos_fsevent = ["notify/macos_fsevent"] macos_kqueue = ["notify/macos_kqueue"] serialization-compat-6 = ["notify/serialization-compat-6"] -nightly = ["tempfile/nightly"] [dependencies] notify.workspace = true notify-types.workspace = true crossbeam-channel = { workspace = true, optional = true } log.workspace = true -tempfile.workspace = true + +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] +tempfile = { workspace = true } + +[target.'cfg(target_family = "wasm")'.dev-dependencies] +tempfile = { workspace = true, features = ["nightly"] } diff --git a/notify/Cargo.toml b/notify/Cargo.toml index c157df67..d8eea551 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -23,7 +23,6 @@ serde = ["notify-types/serde"] macos_kqueue = ["kqueue", "mio"] macos_fsevent = ["fsevent-sys"] serialization-compat-6 = ["notify-types/serialization-compat-6"] -nightly = ["tempfile/nightly"] [dependencies] notify-types.workspace = true @@ -52,6 +51,11 @@ mio.workspace = true [dev-dependencies] serde_json.workspace = true -tempfile.workspace = true nix.workspace = true insta.workspace = true + +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] +tempfile = { workspace = true } + +[target.'cfg(target_family = "wasm")'.dev-dependencies] +tempfile = { workspace = true, features = ["nightly"] } From 0c75cbaa992346fc9dd98fc4ac10227feacecff9 Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Sun, 2 Mar 2025 12:42:14 +0100 Subject: [PATCH 3/3] Run wasi tests --- .github/workflows/ci.yml | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 738c8528..54057747 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,27 +170,21 @@ jobs: - name: Cache dependencies uses: Swatinem/rust-cache@v2 - # - name: Install wasmtime - # uses: taiki-e/install-action@v2 - # with: - # tool: wasmtime - - # - name: Install cargo-wasi - # uses: taiki-e/install-action@v2 - # with: - # tool: cargo-wasi - - # - name: Build for WASI - # run: cargo wasi build --features nightly --verbose - - # - name: Build examples for WASI - # run: cargo wasi build --features nightly --examples --verbose - - # - name: Run tests in WASI environment - # run: cargo wasi test --features nightly --verbose + - name: Install wasmtime + uses: taiki-e/install-action@v2 + with: + tool: wasmtime - name: Build for WASI run: cargo build --target wasm32-wasip2 --verbose - name: Build examples for WASI run: cargo build --examples --target wasm32-wasip2 --verbose + + - name: Run tests in WASI environment + run: | + cargo test --no-run --target wasm32-wasip2 --verbose + find target/wasm32-wasip2/debug/deps -type f -name "*.wasm" | while read -r test_file; do + echo "Running test: $test_file" + wasmtime run "$test_file" --dir=. + done