Skip to content

Commit

Permalink
chore: Parameterize the build mode for noir-wasm (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored Aug 15, 2023
1 parent 74ca305 commit 24ef2d2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
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

0 comments on commit 24ef2d2

Please sign in to comment.