diff --git a/.github/workflows/build_test_wasm.yml b/.github/workflows/build_test_wasm.yml new file mode 100644 index 0000000..8b2d5a2 --- /dev/null +++ b/.github/workflows/build_test_wasm.yml @@ -0,0 +1,40 @@ +name: Wasm (in-memory only) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main, next ] + +env: + RUST_BACKTRACE: full + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + toolchain: [stable] + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + override: true + - name: Add target + run: rustup target add wasm32-unknown-unknown + - uses: extractions/setup-just@v1 + - uses: hustcer/setup-nu@v3.8 + with: + version: '0.85' + env: + GITHUB_TOKEN: ${{ secrets.PAT_GLOBAL }} + - name: Just version + run: just --version + - name: Build + run: just build_wasm + # TODO + # - name: Test + # run: just test_wasm \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 9c06756..d91f61b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,20 +29,26 @@ tokio = { version = "1", features = ["sync"], optional = true } # TODO: channels with futures # TODO: channels crossbeam -[dev-dependencies] +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] assert_fs = "1.1" -serial_test = { version = "3.0", features = ["file_locks"] } shortcut_assert_fs = { version = "0.1.0" } +serial_test = { version = "3.0", features = ["file_locks"] } +criterion = { version = "0.5.1" } + +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +wasm-bindgen-test = "0.3.0" + +[dev-dependencies] skeptic = "0.13" tokio = { version = "1.37", features = ["test-util","macros"] } bincode = { version = "2.0.0-rc.3", features = ["serde"] } -criterion = { version = "0.5.1" } doc-comment = "0.3.3" -uuid = { version = "1", features = ["serde", "v4"] } +uuid = { version = "1", features = ["serde", "v4", "js"] } chrono = { version = "0.4", features = ["serde"] } rand = "0.8" once_cell = "1.19" + [features] default = [] diff --git a/justfile b/justfile index d6be4ee..620273c 100644 --- a/justfile +++ b/justfile @@ -17,6 +17,9 @@ build_all *args: just build_default {{args}}; just build_with_optional {{args}} +build_wasm: + cargo build --target wasm32-unknown-unknown + test_no_default *args: cargo test --no-default-features {{args}} -- --nocapture @@ -31,6 +34,8 @@ test_all *args: just test_default {{args}}; just test_with_optional {{args}} +test_wasm: + cargo test --target wasm32-unknown-unknown # List all available devices test_mobile_all_devices: diff --git a/tests/convert_all.rs b/tests/convert_all.rs index 3ab8f2b..e4c285b 100644 --- a/tests/convert_all.rs +++ b/tests/convert_all.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/util.rs b/tests/create.rs similarity index 96% rename from tests/util.rs rename to tests/create.rs index f75c76c..edb1037 100644 --- a/tests/util.rs +++ b/tests/create.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] use native_db::*; use shortcut_assert_fs::TmpFs; diff --git a/tests/modules.rs b/tests/modules.rs index 907800e..9769bd4 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] mod custom_type; mod macro_def; mod migrate; diff --git a/tests/native_model.rs b/tests/native_model.rs index 8f7fb94..2583f8c 100644 --- a/tests/native_model.rs +++ b/tests/native_model.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] use bincode; use bincode::{config, Decode, Encode}; use native_db::*; diff --git a/tests/scan.rs b/tests/scan.rs index 0a02f36..8cc3d8f 100644 --- a/tests/scan.rs +++ b/tests/scan.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] // TODO: refactor and move to query/ folder use native_db::*; diff --git a/tests/simple_multithreads.rs b/tests/simple_multithreads.rs index b1be3cc..842aea4 100644 --- a/tests/simple_multithreads.rs +++ b/tests/simple_multithreads.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/snapshot.rs b/tests/snapshot.rs index 226422f..e3b1c1b 100644 --- a/tests/snapshot.rs +++ b/tests/snapshot.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/transaction.rs b/tests/transaction.rs index 40ad663..7abab12 100644 --- a/tests/transaction.rs +++ b/tests/transaction.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; diff --git a/tests/wasm.rs b/tests/wasm.rs new file mode 100644 index 0000000..c5f225c --- /dev/null +++ b/tests/wasm.rs @@ -0,0 +1,12 @@ +#![cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; + +#[wasm_bindgen_test] +fn pass() { + assert_eq!(1, 1); +} + +#[wasm_bindgen_test] +fn fail() { + assert_eq!(1, 2); +} \ No newline at end of file diff --git a/tests/watch_tokio.rs b/tests/watch_tokio.rs index 52eb24f..6671a4b 100644 --- a/tests/watch_tokio.rs +++ b/tests/watch_tokio.rs @@ -1,3 +1,4 @@ +#![cfg(not(target_arch = "wasm32"))] #![cfg(feature = "tokio")] use native_db::watch::Event;