From 3eff03eba32536dbc9dd2e85ae36826d8bada478 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Mon, 9 Oct 2023 16:49:59 +0100 Subject: [PATCH 1/4] feat: publish aztec build of noir_wasm --- .github/workflows/publish-noir-wasm-aztec.yml | 47 +++++++++++++++++++ compiler/wasm/buildPhaseCargoCommand.sh | 4 +- compiler/wasm/installPhase.sh | 14 +++++- flake.nix | 16 +++++-- 4 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish-noir-wasm-aztec.yml diff --git a/.github/workflows/publish-noir-wasm-aztec.yml b/.github/workflows/publish-noir-wasm-aztec.yml new file mode 100644 index 00000000000..cae345113d0 --- /dev/null +++ b/.github/workflows/publish-noir-wasm-aztec.yml @@ -0,0 +1,47 @@ +name: Publish Noir Wasm + +on: + workflow_dispatch: + +jobs: + publish-noir-wasm: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - uses: cachix/install-nix-action@v22 + with: + nix_path: nixpkgs=channel:nixos-23.05 + + - name: Build with Nix + run: nix build .#noir_wasm_aztec + + - name: Discover Build Output Path + run: echo "BUILD_OUTPUT_PATH=$(readlink -f ./result/noir_wasm)" >> $GITHUB_ENV + + - name: Copy Build Output to Temporary Directory + run: | + mkdir temp_publish_dir + cp -r ${{ env.BUILD_OUTPUT_PATH }}/* temp_publish_dir/ + touch temp_publish_dir/yarn.lock + + - name: Authenticate with npm + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + + - name: Publish to NPM + working-directory: ./temp_publish_dir + run: yarn npm publish --tag aztec + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/compiler/wasm/buildPhaseCargoCommand.sh b/compiler/wasm/buildPhaseCargoCommand.sh index 1188d00953e..c0942da972a 100755 --- a/compiler/wasm/buildPhaseCargoCommand.sh +++ b/compiler/wasm/buildPhaseCargoCommand.sh @@ -32,8 +32,8 @@ 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 --target $TARGET --package ${pname} +run_or_fail cargo build --lib --release --target $TARGET --package ${pname} --features ${features:-''} 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 -run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O \ No newline at end of file +run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O diff --git a/compiler/wasm/installPhase.sh b/compiler/wasm/installPhase.sh index e5be98a3339..b952d7d553e 100755 --- a/compiler/wasm/installPhase.sh +++ b/compiler/wasm/installPhase.sh @@ -3,8 +3,20 @@ export self_path=$(dirname "$(readlink -f "$0")") export out_path=$out/noir_wasm +SEMVER_SUFFIX="" + +# e.g. v1.0.0-alpha +if [[ -n "${SEMVER_PRE_RELEASE}" ]]; then + SEMVER_SUFFIX="$SEMVER_SUFFIX-$SEMVER_PRE_RELEASE" +fi + +# e.g. v1.0.0-alpha+sha.abcdef +if [[ -n "${SEMVER_BUILD_META}" ]]; then + SEMVER_SUFFIX="$SEMVER_SUFFIX+$SEMVER_BUILD_META" +fi + mkdir -p $out_path cp $self_path/README.md $out_path/ -cp $self_path/package.json $out_path/ +jq --arg semver_suffix "$SEMVER_SUFFIX" '.version = .version + $semver_suffix' $self_path/package.json > $out_path/package.json cp -r $self_path/nodejs $out_path/ cp -r $self_path/web $out_path/ diff --git a/flake.nix b/flake.nix index 0a9bf65322d..5818eacdab1 100644 --- a/flake.nix +++ b/flake.nix @@ -139,15 +139,14 @@ doCheck = false; }); - noir_wasm = craneLib.buildPackage (wasmConfig // rec { + noir_wasm = craneLib.buildPackage (wasmConfig // { pname = "noir_wasm"; + features = ""; inherit GIT_COMMIT GIT_DIRTY; cargoArtifacts = noir-wasm-cargo-artifacts; - cargoExtraArgs = "--package ${pname} --target wasm32-unknown-unknown"; - buildPhaseCargoCommand = '' bash compiler/wasm/buildPhaseCargoCommand.sh release ''; @@ -160,6 +159,16 @@ doCheck = false; }); + # this will be nicer once Configurable Derivations exist + # https://github.com/NixOS/nix/pull/6583 + noir_wasm_aztec = noir_wasm.overrideAttrs (finalAttrs: prevAttrs: { + name = "noir_wasm_aztec"; + features = "noirc_frontend/aztec"; + # build metadata is ignored by npm + # to ensure aztec and non-aztec builds don't get mixed up, use a pre-release tag + SEMVER_PRE_RELEASE = "aztec"; + }); + noirc_abi_wasm = craneLib.buildPackage (wasmConfig // rec { pname = "noirc_abi_wasm"; @@ -240,6 +249,7 @@ # We also export individual packages to enable `nix build .#nargo -L`, etc. inherit nargo; inherit noir_wasm; + inherit noir_wasm_aztec; inherit noirc_abi_wasm; inherit acvm_js; From 4dcde8fa6f63a5a3c997813d23f9c0e944fcbf2d Mon Sep 17 00:00:00 2001 From: Koby Date: Tue, 10 Oct 2023 10:11:27 +0200 Subject: [PATCH 2/4] chore: simpler aztec publishing --- .github/workflows/publish-es-packages.yml | 42 +++++++++++++++-- .github/workflows/publish-noir-wasm-aztec.yml | 47 ------------------- compiler/wasm/buildPhaseCargoCommand.sh | 4 +- compiler/wasm/installPhase.sh | 14 +----- flake.nix | 11 ----- 5 files changed, 42 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/publish-noir-wasm-aztec.yml diff --git a/.github/workflows/publish-es-packages.yml b/.github/workflows/publish-es-packages.yml index 7eec3939f8d..e0cd3643d2b 100644 --- a/.github/workflows/publish-es-packages.yml +++ b/.github/workflows/publish-es-packages.yml @@ -2,13 +2,23 @@ name: Publish Noir ES Packages on: workflow_dispatch: - + inputs: + noir-ref: + description: The noir reference to checkout + required: false + npm-tag: + description: Repository Tag to publish under + required: false + default: 'nightly' + jobs: build-noir_wasm: runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v4 + with: + ref: ${{ inputs.noir-ref || 'master' }} - name: Setup Nix uses: ./.github/actions/nix @@ -17,6 +27,11 @@ jobs: nix-cache-name: ${{ vars.NIX_CACHE_NAME }} cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }} + - name: Enable aztec features + if: ${{ inputs.npm-tag == 'aztec' }} + run: | + echo "\ndefault = [\"aztec\"]" >> compiler/noirc_frontend/Cargo.toml + - name: Build wasm package run: | nix build -L .#noir_wasm @@ -26,6 +41,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 + with: + ref: ${{ inputs.noir-ref || 'master' }} - name: Setup Nix uses: ./.github/actions/nix @@ -43,6 +60,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 + with: + ref: ${{ inputs.noir-ref || 'master' }} - name: Setup Nix uses: ./.github/actions/nix @@ -61,6 +80,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 + with: + ref: ${{ inputs.noir-ref || 'master' }} - name: Setup Nix uses: ./.github/actions/nix @@ -72,11 +93,26 @@ jobs: - name: Install Yarn dependencies run: yarn install + - name: Enable aztec features + if: ${{ inputs.npm-tag == 'aztec' }} + run: | + echo "\ndefault = [\"aztec\"]" >> compiler/noirc_frontend/Cargo.toml + - name: Build ES Packages run: yarn prepare:publish + - name: Prepare nightly version + if: ${{ inputs.npm-tag == 'nightly' }} + run: | + sudo apt-get install jq + yarn nightly:version + + - name: Update Version as specific + run: | + jq '.version = .version + "-${{ inputs.npm-tag }}"' package.json > package-tmp.json && mv package-tmp.json package.json + - name: Authenticate with npm run: "echo npmAuthToken: ${{ secrets.NPM_TOKEN }} > ~/.yarnrc.yml" - + - name: Publish ES Packages - run: yarn publish:all --access public \ No newline at end of file + run: yarn publish:all --access public --tag ${{ inputs.npm-tag }} \ No newline at end of file diff --git a/.github/workflows/publish-noir-wasm-aztec.yml b/.github/workflows/publish-noir-wasm-aztec.yml deleted file mode 100644 index cae345113d0..00000000000 --- a/.github/workflows/publish-noir-wasm-aztec.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Publish Noir Wasm - -on: - workflow_dispatch: - -jobs: - publish-noir-wasm: - runs-on: ubuntu-22.04 - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - uses: cachix/install-nix-action@v22 - with: - nix_path: nixpkgs=channel:nixos-23.05 - - - name: Build with Nix - run: nix build .#noir_wasm_aztec - - - name: Discover Build Output Path - run: echo "BUILD_OUTPUT_PATH=$(readlink -f ./result/noir_wasm)" >> $GITHUB_ENV - - - name: Copy Build Output to Temporary Directory - run: | - mkdir temp_publish_dir - cp -r ${{ env.BUILD_OUTPUT_PATH }}/* temp_publish_dir/ - touch temp_publish_dir/yarn.lock - - - name: Authenticate with npm - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - - - name: Publish to NPM - working-directory: ./temp_publish_dir - run: yarn npm publish --tag aztec - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/compiler/wasm/buildPhaseCargoCommand.sh b/compiler/wasm/buildPhaseCargoCommand.sh index c0942da972a..2ab0f1eb3cb 100755 --- a/compiler/wasm/buildPhaseCargoCommand.sh +++ b/compiler/wasm/buildPhaseCargoCommand.sh @@ -32,8 +32,8 @@ 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 --target $TARGET --package ${pname} --features ${features:-''} +run_or_fail cargo build --lib --release --target $TARGET --package ${pname} ${cargoExtraArgs} 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 -run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O +run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O \ No newline at end of file diff --git a/compiler/wasm/installPhase.sh b/compiler/wasm/installPhase.sh index b952d7d553e..e5be98a3339 100755 --- a/compiler/wasm/installPhase.sh +++ b/compiler/wasm/installPhase.sh @@ -3,20 +3,8 @@ export self_path=$(dirname "$(readlink -f "$0")") export out_path=$out/noir_wasm -SEMVER_SUFFIX="" - -# e.g. v1.0.0-alpha -if [[ -n "${SEMVER_PRE_RELEASE}" ]]; then - SEMVER_SUFFIX="$SEMVER_SUFFIX-$SEMVER_PRE_RELEASE" -fi - -# e.g. v1.0.0-alpha+sha.abcdef -if [[ -n "${SEMVER_BUILD_META}" ]]; then - SEMVER_SUFFIX="$SEMVER_SUFFIX+$SEMVER_BUILD_META" -fi - mkdir -p $out_path cp $self_path/README.md $out_path/ -jq --arg semver_suffix "$SEMVER_SUFFIX" '.version = .version + $semver_suffix' $self_path/package.json > $out_path/package.json +cp $self_path/package.json $out_path/ cp -r $self_path/nodejs $out_path/ cp -r $self_path/web $out_path/ diff --git a/flake.nix b/flake.nix index 5818eacdab1..c9225dedbde 100644 --- a/flake.nix +++ b/flake.nix @@ -159,16 +159,6 @@ doCheck = false; }); - # this will be nicer once Configurable Derivations exist - # https://github.com/NixOS/nix/pull/6583 - noir_wasm_aztec = noir_wasm.overrideAttrs (finalAttrs: prevAttrs: { - name = "noir_wasm_aztec"; - features = "noirc_frontend/aztec"; - # build metadata is ignored by npm - # to ensure aztec and non-aztec builds don't get mixed up, use a pre-release tag - SEMVER_PRE_RELEASE = "aztec"; - }); - noirc_abi_wasm = craneLib.buildPackage (wasmConfig // rec { pname = "noirc_abi_wasm"; @@ -249,7 +239,6 @@ # We also export individual packages to enable `nix build .#nargo -L`, etc. inherit nargo; inherit noir_wasm; - inherit noir_wasm_aztec; inherit noirc_abi_wasm; inherit acvm_js; From 823b2d7c167b779311ab229c3ff636b67d2cbb73 Mon Sep 17 00:00:00 2001 From: Koby Date: Tue, 10 Oct 2023 14:40:28 +0200 Subject: [PATCH 3/4] chore: remove unnecessary `features` --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index c9225dedbde..dc3b4881203 100644 --- a/flake.nix +++ b/flake.nix @@ -141,7 +141,6 @@ noir_wasm = craneLib.buildPackage (wasmConfig // { pname = "noir_wasm"; - features = ""; inherit GIT_COMMIT GIT_DIRTY; From 93de6ee886fb036387fd62b51755c9997af613f6 Mon Sep 17 00:00:00 2001 From: Koby Date: Tue, 10 Oct 2023 14:51:36 +0200 Subject: [PATCH 4/4] chore: align to `npm-tag` input --- .github/workflows/publish-es-packages.yml | 3 +-- .github/workflows/publish-nightly.yml | 2 +- .github/workflows/release.yml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-es-packages.yml b/.github/workflows/publish-es-packages.yml index 5de15faf074..c05e9fcacc9 100644 --- a/.github/workflows/publish-es-packages.yml +++ b/.github/workflows/publish-es-packages.yml @@ -106,10 +106,9 @@ jobs: - name: Prepare nightly version if: ${{ inputs.npm-tag != 'latest' }} run: | - sudo apt-get install jq yarn nightly:version - - name: Update Version as specific + - name: Update Version as specific tag run: | jq '.version = .version + "-${{ inputs.npm-tag }}"' package.json > package-tmp.json && mv package-tmp.json package.json diff --git a/.github/workflows/publish-nightly.yml b/.github/workflows/publish-nightly.yml index 9e8299bc597..f5c013883bb 100644 --- a/.github/workflows/publish-nightly.yml +++ b/.github/workflows/publish-nightly.yml @@ -23,4 +23,4 @@ jobs: with: workflow: publish-es-packages.yml token: ${{ secrets.NOIR_REPO_TOKEN }} - inputs: "{ \"noir-ref\": \"${{ env.GITHUB_REF }}\", \"nightly\": true }" + inputs: "{ \"noir-ref\": \"${{ env.GITHUB_REF }}\", \"npm-tag\": \"nightly\" }" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b1c61e2a5c4..2786bc32970 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,4 +77,4 @@ jobs: workflow: publish-es-packages.yml ref: master token: ${{ secrets.NOIR_REPO_TOKEN }} - inputs: '{ "noir-ref": "${{ needs.release-please.outputs.tag-name }}", "nightly": false }' \ No newline at end of file + inputs: '{ "noir-ref": "${{ needs.release-please.outputs.tag-name }}", "npm-tag": "latest" }' \ No newline at end of file