Skip to content

Commit 083a866

Browse files
Fix rapier(x)d-simd-compat to use simd instructions (#315)
* attempt to fix #314 * pass rustflags when building from rapier compat too. * add ci to check simd is indeed in use. * run different install for ubuntu or mac
1 parent 4ec6b18 commit 083a866

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.github/workflows/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ jobs:
4848
- name: Build all no-compat projects
4949
run: |
5050
./builds/prepare_builds/build_all_projects.sh
51+
# Install dependencies to check simd for builds
52+
- name: Install wabt
53+
run: |
54+
sudo apt install wabt;
55+
if: matrix.os == 'ubuntu-latest'
56+
- name: Install wabt
57+
run: |
58+
brew install wabt;
59+
if: matrix.os == 'macos-latest'
60+
# Check simd for rust builds
61+
- name: Check 2d simd rust build
62+
run: |
63+
if ! wasm-objdump -d builds/rapier2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then
64+
>&2 echo "ERROR: 2d simd compat build does not include simd opcode prefix." && exit 1
65+
fi
66+
- name: Check 3d simd compat build
67+
run: |
68+
if ! wasm-objdump -d builds/rapier3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then
69+
>&2 echo "ERROR: 3d simd compat build does not include simd opcode prefix." && exit 1
70+
fi
5171
- uses: actions/upload-artifact@v4
5272
with:
5373
name: pkg no-compat ${{ matrix.os }}
@@ -82,6 +102,27 @@ jobs:
82102
npm ci;
83103
npm run build;
84104
npm run test;
105+
# Install dependencies to check simd for builds
106+
- name: Install wabt
107+
run: |
108+
sudo apt install wabt;
109+
if: matrix.os == 'ubuntu-latest'
110+
- name: Install wabt
111+
run: |
112+
brew install wabt;
113+
if: matrix.os == 'macos-latest'
114+
# Check simd for compat builds
115+
- name: Check 2d simd compat build
116+
run: |
117+
if ! wasm-objdump -d rapier-compat/builds/2d-simd/pkg/rapier_wasm2d_bg.wasm | grep :\\sfd ; then
118+
>&2 echo "ERROR: 2d simd compat build does not include simd opcode prefix." && exit 1;
119+
fi
120+
- name: Check 3d simd compat build
121+
run: |
122+
if ! wasm-objdump -d rapier-compat/builds/3d-simd/pkg/rapier_wasm3d_bg.wasm | grep :\\sfd ; then
123+
>&2 echo "ERROR: 3d simd compat build does not include simd opcode prefix." && exit 1;
124+
fi
125+
# Upload
85126
- uses: actions/upload-artifact@v4
86127
with:
87128
name: pkg compat ${{ matrix.os }}

builds/prepare_builds/templates/build_rust.sh.tera

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh
22

3+
# Cleaning rust because changing rust flags may lead to different build results.
4+
cargo clean
5+
36
{{ additional_rust_flags }} npx wasm-pack build
47
sed -i.bak 's#dimforge_rapier#@dimforge/rapier#g' pkg/package.json
58
sed -i.bak 's/"rapier_wasm{{ dimension }}d_bg.wasm"/"*"/g' pkg/package.json

rapier-compat/build-rust.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ fi
4141

4242
# Working dir in wasm-pack is the project root so we need that "../../"
4343

44-
wasm-pack build --target web --out-dir "../../rapier-compat/builds/${dimension}d${feature_postfix}/wasm-build" "$rust_source_directory"
44+
if [[ $feature == "simd" ]]; then
45+
export additional_rustflags='-C target-feature=+simd128'
46+
else
47+
export additional_rustflags=''
48+
fi
49+
50+
RUSTFLAGS="${additional_rustflags}" wasm-pack --verbose build --target web --out-dir "../../rapier-compat/builds/${dimension}d${feature_postfix}/wasm-build" "$rust_source_directory"

0 commit comments

Comments
 (0)