mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
31 lines
1.3 KiB
Bash
Executable file
31 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
shopt -s inherit_errexit
|
|
|
|
rm -rf out/ || true
|
|
mkdir out/
|
|
|
|
cargo build --target wasm32-unknown-unknown --release
|
|
echo "[ws] built rust"
|
|
wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
|
|
echo "[ws] bindgen finished"
|
|
|
|
mv out/epoxy_client_bg.wasm out/epoxy_client_unoptimized.wasm
|
|
time wasm-opt -O4 out/epoxy_client_unoptimized.wasm -o out/epoxy_client_bg.wasm
|
|
echo "[ws] optimized"
|
|
|
|
AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js")
|
|
WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm)
|
|
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//__wbg_init(input) \{/__wbg_init() \{let input=\'data:application/wasm;base64,$WASM_BASE64\'}
|
|
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init\(instance\, module\);/__wbg_finalize_init\(instance\, module\); return epoxy}
|
|
echo "$AUTOGENERATED_SOURCE" > index.js
|
|
cp index.js module.js
|
|
echo "module.exports = epoxy" >> module.js
|
|
|
|
AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts")
|
|
AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*}
|
|
echo "$AUTOGENERATED_TYPEDEFS" >"module.d.ts"
|
|
echo "} export default function epoxy(): Promise<typeof wasm_bindgen>;" >> "module.d.ts"
|
|
|
|
rm -rf out/
|
|
echo "[ws] done!"
|