mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
35 lines
1.5 KiB
Bash
Executable file
35 lines
1.5 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 -Oz --vacuum --dce 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" > epoxy-bundled.js
|
|
cp epoxy-bundled.js epoxy-module-bundled.js
|
|
echo "module.exports = epoxy" >> epoxy-module-bundled.js
|
|
|
|
AUTOGENERATED_TYPEDEFS=$(<"out/epoxy_client.d.ts")
|
|
AUTOGENERATED_TYPEDEFS=${AUTOGENERATED_TYPEDEFS%%export class IntoUnderlyingByteSource*}
|
|
echo "$AUTOGENERATED_TYPEDEFS" >"epoxy-module-bundled.d.ts"
|
|
echo "} export default function epoxy(): Promise<typeof wasm_bindgen>;" >> "epoxy-module-bundled.d.ts"
|
|
|
|
cp out/epoxy_client.js epoxy.js
|
|
cp out/epoxy_client.d.ts epoxy.d.ts
|
|
cp out/epoxy_client_bg.wasm epoxy.wasm
|
|
|
|
rm -rf out/
|
|
echo "[ws] done!"
|