Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Parameterize the build mode for noir-wasm #2317

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ else
echo "Will install package to $out"
fi

run_or_fail ${self_path}/buildPhaseCargoCommand.sh
run_or_fail ${self_path}/buildPhaseCargoCommand.sh release
run_or_fail ${self_path}/installPhase.sh

ln -s $out $self_path/result
23 changes: 20 additions & 3 deletions crates/wasm/buildPhaseCargoCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,34 @@ if [ -d ${self_path}/pkg/ ]; then
rm -rf ${self_path}/pkg/
fi

# TODO: Handle the wasm target being built in release mode
# Check that the user passed in debug or release mode
# and set the BUILD_FLAG and BUILD_MODE appropriately.
if [[ -z "$1" ]]; then
echo "Build script requires either "debug" or "release" as an argument."
exit 1
fi

BUILD_MODE=$1
BUILD_FLAG="" # Defaults to debug mode which is an empty string

if [[ "$1" == "release" ]]; then
BUILD_MODE=release
BUILD_FLAG="--release"
elif [[ "$1" != "debug" ]]; then
echo "Invalid BUILD_MODE. Accepted values are 'debug' or 'release'."
exit 1
fi

TARGET=wasm32-unknown-unknown
WASM_BINARY=${CARGO_TARGET_DIR}/${TARGET}/release/${pname}.wasm
WASM_BINARY=${CARGO_TARGET_DIR}/${TARGET}/${BUILD_MODE}/${pname}.wasm

NODE_DIR=${self_path}/pkg/nodejs/
BROWSER_DIR=${self_path}/pkg/web/
NODE_WASM=${NODE_DIR}/${pname}_bg.wasm
BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm

# Build the new wasm package
run_or_fail cargo build --lib --release --package noir_wasm --target wasm32-unknown-unknown
run_or_fail cargo build --lib $BUILD_FLAG --package noir_wasm --target wasm32-unknown-unknown
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
];

buildPhaseCargoCommand = ''
bash crates/wasm/buildPhaseCargoCommand.sh
bash crates/wasm/buildPhaseCargoCommand.sh release
'';

installPhase = ''
Expand Down