Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wasm support #79

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/build_test_wasm.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/convert_all.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions tests/util.rs → tests/create.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
use native_db::*;
use shortcut_assert_fs::TmpFs;

Expand Down
1 change: 1 addition & 0 deletions tests/modules.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
mod custom_type;
mod macro_def;
mod migrate;
Expand Down
1 change: 1 addition & 0 deletions tests/native_model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
use bincode;
use bincode::{config, Decode, Encode};
use native_db::*;
Expand Down
1 change: 1 addition & 0 deletions tests/scan.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
// TODO: refactor and move to query/ folder

use native_db::*;
Expand Down
2 changes: 2 additions & 0 deletions tests/simple_multithreads.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 2 additions & 0 deletions tests/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use native_db::*;
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};
Expand Down
12 changes: 12 additions & 0 deletions tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions tests/watch_tokio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
#![cfg(feature = "tokio")]

use native_db::watch::Event;
Expand Down
Loading