diff --git a/libs/wingc/package.json b/libs/wingc/package.json index c451384f799..0581867cea5 100644 --- a/libs/wingc/package.json +++ b/libs/wingc/package.json @@ -2,7 +2,7 @@ "name": "@winglang/wingc", "private": true, "scripts": { - "compile": "cargo build --target wasm32-wasi --release && ../../.cargo/binaryen-version_117/bin/wasm-opt --enable-bulk-memory --strip-debug --strip-producers -O3 -o wingc.wasm ../../target/wasm32-wasi/release/wingc.wasm", + "compile": "cargo build --target wasm32-wasi --release && ./scripts/postcompile.sh", "dev": "cargo run --example compile --release", "test": "cargo test", "lint": "cargo fmt && cargo clippy --fix --no-deps --allow-dirty --target wasm32-wasi --release" diff --git a/libs/wingc/scripts/postcompile.sh b/libs/wingc/scripts/postcompile.sh new file mode 100755 index 00000000000..5702df3f046 --- /dev/null +++ b/libs/wingc/scripts/postcompile.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +### +# This script should be run after release build of wingc to the wasm32-wasi target. +# The end result will be a final wasm file in the wingc directory. +# If running in CI (env "CI" is set), it will run wasm-opt on the generated wasm file. +# Otherwise, the wasm file will be copied to the wingc directory from its original output location. +### + +wingc=$(cd $(dirname $0)/.. && pwd) + +# Currently we only do release wasm builds +target="release" + +wasm_opt="$wingc/../../.cargo/binaryen-version_117/bin/wasm-opt" +input_wasm="$wingc/../../target/wasm32-wasi/$target/wingc.wasm" +output_wasm="$wingc/wingc.wasm" + +# If CI env is set, run wasm-opt with extra optimizations +echo "Optimising wasm..." +if [ -n "$CI" ]; then + $wasm_opt --enable-bulk-memory --strip-debug --strip-producers -O3 -o $output_wasm $input_wasm +else + $wasm_opt --enable-bulk-memory --strip-debug --strip-producers -o $output_wasm $input_wasm +fi +echo "Done!" diff --git a/libs/wingc/turbo.json b/libs/wingc/turbo.json index fad9c1cb977..4de29086657 100644 --- a/libs/wingc/turbo.json +++ b/libs/wingc/turbo.json @@ -4,6 +4,7 @@ "pipeline": { "compile": { "dependsOn": ["@winglang/wingii#compile", "@winglang/tree-sitter-wing#compile"], + "inputs": ["$TURBO_DEFAULT$", "scripts/postcompile.sh"], "outputs": [ "../../target/wasm32-wasi/release/wingc.wasm", "../../target/wasm32-wasi/release/libwingc.*",