Move build:wasm commands to dedicated scripts (#5813)

* add script to build on mac mini

* Remove wasm-prep, rust flag only on wasm-pack build, add ps1 script

* Make it exectuable, tested on macOS

* Add set -e

* Stop scripts on error

---------

Co-authored-by: lf94 <ircsurfer33@gmail.com>
This commit is contained in:
Pierre Jacquier
2025-03-17 12:24:40 -04:00
committed by GitHub
parent e50e9a00d4
commit e78788482e
4 changed files with 36 additions and 5 deletions

18
scripts/build-wasm.ps1 Normal file
View File

@ -0,0 +1,18 @@
# Stop the script when a cmdlet or a native command fails
# from https://www.meziantou.net/stop-the-script-when-an-error-occurs-in-powershell.htm
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
rm -Recurse -Force rust/kcl-wasm-lib/pkg
mkdir -p rust/kcl-wasm-lib/pkg
rm -Recurse -Force rust/kcl-lib/bindings
cd rust
$env:RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
wasm-pack build kcl-wasm-lib --release --target web --out-dir pkg
$env:RUSTFLAGS=''
cargo test -p kcl-lib export_bindings
cd ..
copy rust\kcl-wasm-lib\pkg\kcl_wasm_lib_bg.wasm public
yarn fmt

16
scripts/build-wasm.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
rm -rf rust/kcl-wasm-lib/pkg
mkdir -p rust/kcl-wasm-lib/pkg
rm -rf rust/kcl-lib/bindings
cd rust
export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
wasm-pack build kcl-wasm-lib --release --target web --out-dir pkg
export RUSTFLAGS=''
cargo test -p kcl-lib export_bindings
cd ..
cp rust/kcl-wasm-lib/pkg/kcl_wasm_lib_bg.wasm public
yarn fmt

View File

@ -1 +0,0 @@
copy rust\kcl-wasm-lib\pkg\kcl_wasm_lib_bg.wasm public