Skip to content

Commit 65a2b50

Browse files
committed
rollup integration test working
1 parent 6ec863d commit 65a2b50

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
lines changed

box2d-wasm/build_all.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,26 @@ set -x
3030

3131
popd
3232

33-
FLAVOUR_NAMES=(vanilla SIMD)
34-
FLAVOUR_DIRNAMES=(standard simd)
35-
SIMD_ENABLED=('' 1)
33+
FLAVOURS=(standard simd)
3634

3735
for i in {0..1}
3836
do
39-
FLAVOUR_NAME="${FLAVOUR_NAMES["$i"]}"
40-
FLAVOUR_DIRNAME="${FLAVOUR_DIRNAMES["$i"]}"
37+
FLAVOUR="${FLAVOURS["$i"]}"
4138

4239
# use JUST_SIMD=1 to save time when prototyping
43-
if [[ "$JUST_SIMD" = "1" && "$FLAVOUR_NAME" != "simd" ]]; then
44-
>&2 echo -e "\nSkipping '$FLAVOUR_NAME' flavour build because JUST_SIMD is set."
40+
if [[ "$JUST_SIMD" = "1" && "$FLAVOUR" != "simd" ]]; then
41+
>&2 echo -e "\nSkipping '$FLAVOUR' flavour build because JUST_SIMD is set."
4542
continue
4643
fi
4744

4845

49-
FLAVOUR_DIR="build/flavour/$FLAVOUR_DIRNAME"
50-
>&2 echo -e "\nMaking '$FLAVOUR_NAME' flavour in ./$FLAVOUR_DIR directory"
46+
FLAVOUR_DIR="build/flavour/$FLAVOUR"
47+
>&2 echo -e "\nMaking '$FLAVOUR' flavour in ./$FLAVOUR_DIR directory"
5148
mkdir -p "$FLAVOUR_DIR"
5249
pushd "$FLAVOUR_DIR"
5350

5451
set -x
55-
SIMD_ENABLED="$SIMD_ENABLED" "$DIR/build_makefile.sh"
52+
FLAVOUR="$FLAVOUR" "$DIR/build_makefile.sh"
5653
{ set +x; } 2>&-
5754

5855
>&2 echo -e '\nCompiling C++ to LLVM IR (creates ./build/bin/libbox2d.a archive)'
@@ -63,10 +60,10 @@ do
6360

6461
# generate Box2D_*.{wasm,js} from glue code + libbox2d.a
6562
set -x
66-
SIMD_ENABLED="$SIMD_ENABLED" "$DIR/build_wasm.sh"
63+
FLAVOUR="$FLAVOUR" "$DIR/build_wasm.sh"
6764
{ set +x; } 2>&-
6865

69-
>&2 echo -e "Completed '$FLAVOUR_NAME' flavour"
66+
>&2 echo -e "Completed '$FLAVOUR' flavour"
7067

7168
popd
7269
done

box2d-wasm/build_makefile.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ Red='\033[0;31m'
66
Purple='\033[0;35m'
77
NC='\033[0m' # No Color
88

9-
if ! [[ "$(dirname "$PWD")" -ef "$DIR/build/flavour" ]]; then
10-
>&2 echo -e "${Red}This script is meant to be run from <repository_root>/box2d-wasm/build/flavour/\$FLAVOUR_DIRNAME${NC}"
9+
CMAKE_CXX_FLAGS=()
10+
case "$FLAVOUR" in
11+
standard)
12+
;;
13+
simd)
14+
CMAKE_CXX_FLAGS=(${CMAKE_CXX_FLAGS[@]} -msimd128)
15+
;;
16+
*)
17+
>&2 echo -e "${Red}FLAVOUR not set.${NC}"
18+
>&2 echo -e "Please set FLAVOUR to 'standard' or 'simd'. For example, with:"
19+
>&2 echo -e "${Purple}export FLAVOUR='simd'${NC}"
20+
exit 1
21+
;;
22+
esac
23+
24+
if ! [[ "$PWD" -ef "$DIR/build/flavour/$FLAVOUR" ]]; then
25+
>&2 echo -e "${Red}This script is meant to be run from <repository_root>/box2d-wasm/build/flavour/$FLAVOUR${NC}"
1126
exit 1
1227
fi
1328

@@ -25,10 +40,5 @@ case "$TARGET_TYPE" in
2540
esac
2641
>&2 echo -e "TARGET_TYPE is $TARGET_TYPE"
2742

28-
CMAKE_CXX_FLAGS=()
29-
if [[ "$SIMD_ENABLED" = "1" ]]; then
30-
CMAKE_CXX_FLAGS=(${CMAKE_CXX_FLAGS[@]} -msimd128)
31-
fi
32-
3343
set -x
3444
emcmake cmake -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS[@]}" "$DIR/../box2d" -DBOX2D_BUILD_UNIT_TESTS=OFF -DBOX2D_BUILD_DOCS=OFF -DBOX2D_BUILD_TESTBED=OFF

box2d-wasm/build_wasm.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,25 @@ Blue='\033[0;34m'
88
Purple='\033[0;35m'
99
NC='\033[0m' # No Color
1010

11-
if ! [[ "$(dirname "$PWD")" -ef "$DIR/build/flavour" ]]; then
12-
>&2 echo -e "${Red}This script is meant to be run from <repository_root>/box2d-wasm/build/flavour/\$FLAVOUR_DIRNAME${NC}"
11+
BASENAME=Box2D
12+
FLAVOUR_EMCC_OPTS=()
13+
case "$FLAVOUR" in
14+
standard)
15+
;;
16+
simd)
17+
BASENAME="$BASENAME.simd"
18+
FLAVOUR_EMCC_OPTS=(${FLAVOUR_EMCC_OPTS[@]} -msimd128)
19+
;;
20+
*)
21+
>&2 echo -e "${Red}FLAVOUR not set.${NC}"
22+
>&2 echo -e "Please set FLAVOUR to 'standard' or 'simd'. For example, with:"
23+
>&2 echo -e "${Purple}export FLAVOUR='simd'${NC}"
24+
exit 1
25+
;;
26+
esac
27+
28+
if ! [[ "$PWD" -ef "$DIR/build/flavour/$FLAVOUR" ]]; then
29+
>&2 echo -e "${Red}This script is meant to be run from <repository_root>/box2d-wasm/build/flavour/$FLAVOUR${NC}"
1330
exit 1
1431
fi
1532

@@ -24,10 +41,8 @@ EMCC_OPTS=(
2441
-s SUPPORT_LONGJMP=0
2542
-s EXPORTED_FUNCTIONS=_malloc,_free
2643
-s ALLOW_MEMORY_GROWTH=1
44+
${FLAVOUR_EMCC_OPTS[@]}
2745
)
28-
if [[ "$SIMD_ENABLED" = "1" ]]; then
29-
EMCC_OPTS=(${EMCC_OPTS[@]} -msimd128)
30-
fi
3146
DEBUG_OPTS=(
3247
-g3
3348
-gsource-map
@@ -73,7 +88,6 @@ case "$TARGET_TYPE" in
7388
esac
7489
>&2 echo -e "TARGET_TYPE is $TARGET_TYPE"
7590

76-
BASENAME='Box2D'
7791
BARE_WASM="$BASENAME.bare.wasm"
7892

7993
>&2 echo -e "${Blue}Building bare WASM${NC}"

box2d-wasm/entry/es/entry.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { simd } from 'wasm-feature-detect'
22

3-
export default (async () => {
3+
export default async (...args) => {
44
const hasSIMD = await simd();
5-
const module = await (
5+
const Box2DModule = await (
66
hasSIMD
77
? import('../../build/flavour/simd/es/Box2D.simd.js')
88
: import('../../build/flavour/standard/es/Box2D.js')
99
);
10-
return module;
11-
})();
10+
const { 'default': Box2DFactory } = Box2DModule;
11+
return await Box2DFactory(...args);
12+
};

integration-test/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel='stylesheet' href='global.css'>
1111
<link rel='stylesheet' href='build/bundle.css'>
1212

13-
<script defer src='build/bundle.js'></script>
13+
<script defer src='build/main.js' type='module'></script>
1414
</head>
1515

1616
<body>

integration-test/rollup.config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export default {
1414
input: 'src/main.ts',
1515
output: {
1616
sourcemap: true,
17-
format: 'iife',
17+
format: 'esm',
1818
name: 'app',
19-
file: 'public/build/bundle.js'
19+
dir: 'public/build'
2020
},
21+
// inlineDynamicImports: true,
2122
plugins: [
2223
svelte({
2324
// enable run-time checks when not in production
@@ -48,7 +49,11 @@ export default {
4849
// In dev mode, call `npm run start` once
4950
// the bundle has been generated
5051
!production && serve({
51-
contentBase: ['public', 'node_modules/box2d-wasm/build/es'],
52+
contentBase: [
53+
'public',
54+
'node_modules/box2d-wasm/build/flavour/standard/es',
55+
'node_modules/box2d-wasm/build/flavour/simd/es'
56+
],
5257
port: 4000
5358
}),
5459

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)