diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7977f5..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: @@ -57,17 +59,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 +86,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 +107,9 @@ jobs: brew install wabt; if: matrix.os == 'macos-latest' # Check simd for compat builds - - name: Check 2d simd compat build + - name: Check 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 - 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: @@ -129,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' @@ -152,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/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