diff --git a/.github/workflows/build_wasm.yml b/.github/workflows/build_wasm.yml new file mode 100644 index 00000000..ea96797e --- /dev/null +++ b/.github/workflows/build_wasm.yml @@ -0,0 +1,35 @@ +name: 'Build WebAssembly' + +on: + push: + tags: [ '*' ] + + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v4 + + - name: 'Install wasm-pack' + run: | + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + export PATH="$HOME/.cargo/bin:$PATH" + + - name: 'Build WebAssembly' + run: | + rustup target add wasm32-unknown-unknown + pushd ./crates/lib + wasm-pack build --release --target web --out-name index + popd + mkdir -p artifacts + find crates/lib/pkg -type f \( -name "*.js" -o -name "*.d.ts" -o -name "*.wasm" \) -exec cp {} artifacts \; + + - name: 'Upload Artifacts' + uses: actions/upload-artifact@v4 + with: + name: 'wasm' + path: artifacts/* diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d40fba6f..787957d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,7 @@ jobs: rustup component add clippy cargo clippy --features=macro -- -D warnings - boostrap: + bootstrap: runs-on: ubuntu-latest steps: - name: Checkout diff --git a/Cargo.toml b/Cargo.toml index 2598e479..caa3e734 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ lto = true codegen-units = 1 panic = 'abort' strip = true + diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index 85652ea2..9b7913fb 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -21,9 +21,10 @@ required-features = ["commandline"] [lib] name = "grass" path = "src/lib.rs" -# crate-type = ["cdylib", "rlib"] +crate-type = ["cdylib", "rlib"] bench = false + [package.metadata.docs.rs] # To build locally: # RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --features=macro --no-deps --open @@ -31,6 +32,8 @@ features = ["macro"] rustdoc-args = ["--cfg", "doc_cfg"] [dependencies] +wasm-bindgen = { version = "0.2", optional = true } +getrandom = { version = "0.2", features = ["js"] } grass_compiler = { path = "../compiler", version = "=0.13.2", default-features = false } include_sass = { path = "../include_sass", version = "0.13.2", optional = true } clap = { version = "4.3.10", optional = true } @@ -41,7 +44,7 @@ default = ["commandline", "random"] # Option (enabled by default): build a binary using clap commandline = ["clap"] random = ["grass_compiler/random"] -wasm-exports = ["grass_compiler/wasm-exports"] +wasm-exports = ["grass_compiler/wasm-exports", "wasm-bindgen"] # Option: include the proc macro `include_sass!` macro = ["include_sass"] nightly = ["include_sass/nightly"]