From 6a344b2f36439c10ee23219de6fd24b68508668a Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 15 Aug 2023 14:05:24 +0100 Subject: [PATCH 1/3] chore: Fix typo (#2315) --- crates/wasm/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasm/README.md b/crates/wasm/README.md index e2b625c739b..c5e8d54a836 100644 --- a/crates/wasm/README.md +++ b/crates/wasm/README.md @@ -2,7 +2,7 @@ This JavaScript package enables users to compile a Noir program, i.e. generating its artifacts. -The package also handles dependency management like how Nargo (Noir's CLI tool) opreates, but the package is used just for compilation, not proving, verifying and simulating functions. +The package also handles dependency management like how Nargo (Noir's CLI tool) operates, but the package is used just for compilation, not proving, verifying and simulating functions. ## Building from source From 74ca305d2f128ad6efc7c38f2b1fab16d47eaf99 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 15 Aug 2023 14:06:29 +0100 Subject: [PATCH 2/3] chore: Make `wasm` tests pull from `result` directory (#2319) --- .github/workflows/wasm.yml | 2 +- crates/wasm/test/browser/index.test.ts | 2 +- crates/wasm/test/shared.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 66cb260aebf..7d429accdbf 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -130,7 +130,7 @@ jobs: uses: actions/download-artifact@v3 with: name: noir_wasm - path: ./crates/wasm/dist + path: ./crates/wasm/result - name: Download nargo binary uses: actions/download-artifact@v3 diff --git a/crates/wasm/test/browser/index.test.ts b/crates/wasm/test/browser/index.test.ts index 6c86f0d3f94..9cc49069bfd 100644 --- a/crates/wasm/test/browser/index.test.ts +++ b/crates/wasm/test/browser/index.test.ts @@ -1,5 +1,5 @@ import { expect } from "@esm-bundle/chai"; -import initNoirWasm from "../../dist"; +import initNoirWasm from "../../result"; import { compileNoirSource, nargoArtifactPath, noirSourcePath } from "../shared"; beforeEach(async () => { diff --git a/crates/wasm/test/shared.ts b/crates/wasm/test/shared.ts index c21ce2e0de4..ee9c57d24f6 100644 --- a/crates/wasm/test/shared.ts +++ b/crates/wasm/test/shared.ts @@ -1,5 +1,5 @@ import { initialiseResolver } from "@noir-lang/noir-source-resolver"; -import { compile } from "../dist/"; +import { compile } from "../result/"; export const noirSourcePath = "../../noir-script/src/main.nr"; export const nargoArtifactPath = "../../noir-script/target/noir_wasm_testing.json"; From 24ef2d29df95c437dcf7629fb800a49a155ba020 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 15 Aug 2023 14:09:14 +0100 Subject: [PATCH 3/3] chore: Parameterize the build mode for noir-wasm (#2317) --- crates/wasm/build.sh | 2 +- crates/wasm/buildPhaseCargoCommand.sh | 23 ++++++++++++++++++++--- flake.nix | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/wasm/build.sh b/crates/wasm/build.sh index 61b5b17d34d..54add2b8ed3 100755 --- a/crates/wasm/build.sh +++ b/crates/wasm/build.sh @@ -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 diff --git a/crates/wasm/buildPhaseCargoCommand.sh b/crates/wasm/buildPhaseCargoCommand.sh index 5ba924dbb7b..f7828d7cd35 100755 --- a/crates/wasm/buildPhaseCargoCommand.sh +++ b/crates/wasm/buildPhaseCargoCommand.sh @@ -23,9 +23,26 @@ 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/ @@ -33,7 +50,7 @@ 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 diff --git a/flake.nix b/flake.nix index 912b035d359..135f7d1742b 100644 --- a/flake.nix +++ b/flake.nix @@ -308,7 +308,7 @@ ]; buildPhaseCargoCommand = '' - bash crates/wasm/buildPhaseCargoCommand.sh + bash crates/wasm/buildPhaseCargoCommand.sh release ''; installPhase = ''