From 820c1666da5ebc2caa7f51ba3a1c493c3f5dad03 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Fri, 11 Apr 2025 09:06:28 +0200 Subject: [PATCH 1/2] add CI job to release on tag pushed --- .github/workflows/main.yml | 26 +++++------------- .github/workflows/publish_prod.yml | 36 +++++++++++++++++++++++++ README.md | 22 +++++++++++++++- scripts/verify_simd_compat.sh | 42 ++++++++++++++++++++++++++++++ scripts/verify_simd_rust.sh | 42 ++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/publish_prod.yml create mode 100755 scripts/verify_simd_compat.sh create mode 100755 scripts/verify_simd_rust.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7977f5..002657f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,17 +57,9 @@ jobs: run: | brew install wabt; if: matrix.os == 'macos-latest' - # Check simd for rust builds - - name: Check 2d simd rust build + - name: Check simd rust build run: | - if ! wasm-objdump -d builds/rapier2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then - >&2 echo "ERROR: 2d simd compat build does not include simd opcode prefix." && exit 1 - fi - - name: Check 3d simd compat build - run: | - if ! wasm-objdump -d builds/rapier3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then - >&2 echo "ERROR: 3d simd compat build does not include simd opcode prefix." && exit 1 - fi + ./scripts/verify_simd_rust.sh - uses: actions/upload-artifact@v4 with: name: pkg no-compat ${{ matrix.os }} @@ -92,16 +84,17 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - run: npm ci; - name: Prepare compat builds run: | ./builds/prepare_builds/prepare_all_projects.sh + - run: npm ci; - name: Build rapier-compat run: | cd rapier-compat; npm ci; npm run build; npm run test; + cd -; # Install dependencies to check simd for builds - name: Install wabt run: | @@ -112,16 +105,9 @@ jobs: brew install wabt; if: matrix.os == 'macos-latest' # Check simd for compat builds - - name: Check 2d simd compat build - run: | - if ! wasm-objdump -d rapier-compat/builds/2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then - >&2 echo "ERROR: 2d simd compat build does not include simd opcode prefix." && exit 1; - fi - - name: Check 3d simd compat build + - name: Check simd compat build run: | - if ! wasm-objdump -d rapier-compat/builds/3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then - >&2 echo "ERROR: 3d simd compat build does not include simd opcode prefix." && exit 1; - fi + ./scripts/verify_simd_compat.sh # Upload - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/publish_prod.yml b/.github/workflows/publish_prod.yml new file mode 100644 index 0000000..dd9bddb --- /dev/null +++ b/.github/workflows/publish_prod.yml @@ -0,0 +1,36 @@ +name: publish_prod + +on: + push: + tags: + - "v*.*.*" + # In case an automated release failed, we can retrigger them manually. + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + publish: + # To avoid releasing a wrong version: check this commit is tagged + if: startsWith(github.event.workflow_run.head_branch, 'refs/tags/v') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: pkg no-compat ubuntu-latest + path: builds + - uses: actions/download-artifact@v4 + with: + name: pkg compat ubuntu-latest + path: rapier-compat/builds + - uses: actions/setup-node@v4 + with: + node-version: "22.x" + registry-url: "https://registry.npmjs.org" + - name: Publish projects + run: | + ./publish_all_prod.sh + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index d04cc4b..536e247 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ ## Building packages manually +### Rust + From the root of the repository, run: ```shell @@ -41,10 +43,28 @@ From the root of the repository, run: Note that `prepare_all_projects.sh` only needs to be run once. It needs to be re-run if any file from the `builds/prepare_builds` directory (and subdirectories) are modified. -The built packages will be in `builds/rapier2d/pkg`, `builds/rapier3d/pkg`, etc. To build the `-compat` variant of the +The built packages will be in `builds/rapier2d/pkg`, `builds/rapier3d/pkg`, etc. + +### Compat version + +To build the `-compat` variant of the packages, run `npm run build` in the `rapier-compat` directory. Note that this will only work if you already ran `prepare_all_projects.sh`. The compat packages are then generated in, e.g., `rapier-compat/builds/3d/pkg`. +```shell +git clean -fxd # Delete all untracked files. +./builds/prepare_builds/prepare_all_projects.sh +cd rapier-compat; +npm ci; +npm run build; +``` + +### Building packages in CI + +Pushing a tag `v*.*.*` will trigger a CI for production release. + +This can fail due to artifacts not available, restart the job manually if needed. + ## Feature selection Multiple NPM packages exist for Rapier, depending on your needs: diff --git a/scripts/verify_simd_compat.sh b/scripts/verify_simd_compat.sh new file mode 100755 index 0000000..9c5f681 --- /dev/null +++ b/scripts/verify_simd_compat.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +is_error=0 + +check_simd_opcode_compat() { + local dimension=$1 + local features_flag=$2 + + local file_path="rapier-compat/builds/${dimension}${features_flag}/pkg/rapier_wasm${dimension}_bg.wasm" + + echo "wasm-objdump -d $file_path" >&2 + if [ "$features_flag" = "-simd" ]; then + if ! wasm-objdump -d $file_path | grep :\\sfd > /dev/null ; then + >&2 echo "ERROR: ${dimension}${features_flag} compat build should include simd opcode prefix." && exit 1 + fi + else + if wasm-objdump -d $file_path | grep :\\sfd > /dev/null ; then + >&2 echo "ERROR: ${dimension} ${features_flag} compat build should not include simd opcode prefix." && exit 1 + fi + fi +} + +## simd + +check_simd_opcode_compat "2d" "-simd" || is_error=1 +check_simd_opcode_compat "3d" "-simd" || is_error=1 + + +## not simd + +check_simd_opcode_compat "2d" "-deterministic" || is_error=1 +check_simd_opcode_compat "3d" "-deterministic" || is_error=1 + +check_simd_opcode_compat "2d" "" || is_error=1 +check_simd_opcode_compat "3d" "" || is_error=1 + +if [ $is_error = 1 ]; then + echo "ERROR: SIMD check in rust builds failed." + exit 1 +else + echo "SIMD check in rust builds: All checks passed." +fi \ No newline at end of file diff --git a/scripts/verify_simd_rust.sh b/scripts/verify_simd_rust.sh new file mode 100755 index 0000000..a4518e8 --- /dev/null +++ b/scripts/verify_simd_rust.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +is_error=0 + +check_simd_opcode_rust() { + local dimension=$1 + local features_flag=$2 + + local file_path="builds/rapier${dimension}${features_flag}/pkg/rapier_wasm${dimension}_bg.wasm" + + if [ "$features_flag" = "-simd" ]; then + if ! wasm-objdump -d $file_path | grep :\\sfd > /dev/null ; then + >&2 echo "ERROR: ${dimension}${features_flag} build should include simd opcode prefix." && exit 1 + fi + else + if wasm-objdump -d $file_path | grep :\\sfd > /dev/null ; then + >&2 echo "ERROR: ${dimension} ${features_flag} build should not include simd opcode prefix." && exit 1 + fi + fi +} + +## simd + +check_simd_opcode_rust "2d" "-simd" || is_error=1 +check_simd_opcode_rust "3d" "-simd" || is_error=1 + + +## not simd + +check_simd_opcode_rust "2d" "-deterministic" || is_error=1 +check_simd_opcode_rust "3d" "-deterministic" || is_error=1 + +check_simd_opcode_rust "2d" "" || is_error=1 +check_simd_opcode_rust "3d" "" || is_error=1 + + +if [ $is_error = 1 ]; then + echo "ERROR: SIMD check in rust builds failed." + exit 1 +else + echo "SIMD check in rust builds: All checks passed." +fi \ No newline at end of file From b369c07e26d22e1e6cbc8167a6c375ef5e5f5dc7 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Tue, 6 May 2025 14:31:19 +0200 Subject: [PATCH 2/2] use same workflow for prod release simplicity --- .github/workflows/main.yml | 28 ++++++++++++++++++++++- .github/workflows/publish_prod.yml | 36 ------------------------------ 2 files changed, 27 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/publish_prod.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 002657f..c70fa96 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,8 @@ name: main on: push: branches: [master] + tags: + - "v*.*.*" pull_request: branches: [master] workflow_dispatch: @@ -115,7 +117,7 @@ jobs: path: | rapier-compat/builds/*/pkg overwrite: true - publish: + publish-canary: runs-on: ubuntu-latest needs: [build, build-compat] if: github.ref == 'refs/heads/master' @@ -138,3 +140,27 @@ jobs: ./publish_all_canary.sh env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + publish-prod: + runs-on: ubuntu-latest + needs: [build, build-compat] + # To avoid releasing a wrong version: check this commit is tagged + if: startsWith(github.event.workflow_run.head_branch, 'refs/tags/v') }} + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: pkg no-compat ubuntu-latest + path: builds + - uses: actions/download-artifact@v4 + with: + name: pkg compat ubuntu-latest + path: rapier-compat/builds + - uses: actions/setup-node@v4 + with: + node-version: "22.x" + registry-url: "https://registry.npmjs.org" + - name: Publish projects + run: | + ./publish_all_prod.sh + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish_prod.yml b/.github/workflows/publish_prod.yml deleted file mode 100644 index dd9bddb..0000000 --- a/.github/workflows/publish_prod.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: publish_prod - -on: - push: - tags: - - "v*.*.*" - # In case an automated release failed, we can retrigger them manually. - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - publish: - # To avoid releasing a wrong version: check this commit is tagged - if: startsWith(github.event.workflow_run.head_branch, 'refs/tags/v') }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 - with: - name: pkg no-compat ubuntu-latest - path: builds - - uses: actions/download-artifact@v4 - with: - name: pkg compat ubuntu-latest - path: rapier-compat/builds - - uses: actions/setup-node@v4 - with: - node-version: "22.x" - registry-url: "https://registry.npmjs.org" - - name: Publish projects - run: | - ./publish_all_prod.sh - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}