Skip to content

Commit 91ecb93

Browse files
committed
chore(ci): fix bullet3 builds for platforms
1 parent 1eb4a44 commit 91ecb93

3 files changed

Lines changed: 128 additions & 77 deletions

File tree

.github/workflows/build-android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
6868
- name: Build bullet3
6969
working-directory: package/
70-
run: bun build-bullet3
70+
run: bun build-bullet3 --platform android
7171

7272
- name: Build Android app (AppExampleFabric)
7373
if: matrix.app == 'AppExampleFabric'

.github/workflows/build-ios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
- name: Build bullet3
7373
working-directory: package/
74-
run: bun build-bullet3
74+
run: bun build-bullet3 --platform ios
7575

7676
- name: Build App
7777
working-directory: examples/AppExampleFabric/ios

package/scripts/build-bullet3.sh

Lines changed: 126 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,69 @@
22

33
set -e
44

5-
if [ -d "../package/android/libs/bullet3" ]; then
6-
echo "[bullet3] Android libraries already exist in react-native-filament package. Do you want to skip building them? (Y/N) (y)"
7-
read -r skip_android
8-
if [ "$skip_android" = "N" ] || [ "$skip_android" = "n" ]; then
9-
skip_android=false
10-
else
11-
echo "Skipping Android build..."
12-
skip_android=true
5+
# Parse command-line arguments
6+
BUILD_ANDROID=${BUILD_ANDROID:-true}
7+
BUILD_IOS=${BUILD_IOS:-true}
8+
9+
while [[ $# -gt 0 ]]; do
10+
case $1 in
11+
--platform)
12+
case $2 in
13+
android)
14+
BUILD_ANDROID=true
15+
BUILD_IOS=false
16+
;;
17+
ios)
18+
BUILD_ANDROID=false
19+
BUILD_IOS=true
20+
;;
21+
all)
22+
BUILD_ANDROID=true
23+
BUILD_IOS=true
24+
;;
25+
*)
26+
echo "Unknown platform: $2"
27+
echo "Usage: $0 [--platform android|ios|all]"
28+
exit 1
29+
;;
30+
esac
31+
shift 2
32+
;;
33+
*)
34+
echo "Unknown option: $1"
35+
echo "Usage: $0 [--platform android|ios|all]"
36+
exit 1
37+
;;
38+
esac
39+
done
40+
41+
# Interactive mode: ask to skip if libraries already exist (only if not in CI)
42+
if [ "$CI" != "true" ]; then
43+
if [ "$BUILD_ANDROID" = "true" ] && [ -d "../package/android/libs/bullet3" ]; then
44+
echo "[bullet3] Android libraries already exist in react-native-filament package. Do you want to skip building them? (Y/N) (y)"
45+
read -r skip_android
46+
if [ "$skip_android" = "N" ] || [ "$skip_android" = "n" ]; then
47+
BUILD_ANDROID=true
48+
else
49+
echo "Skipping Android build..."
50+
BUILD_ANDROID=false
51+
fi
1352
fi
14-
fi
1553

16-
if [ -d "../package/ios/libs/bullet3" ]; then
17-
echo "[bullet3] iOS libraries already exist in react-native-filament package. Do you want to skip building them? (Y/N) (y)"
18-
read -r skip_ios
19-
if [ "$skip_ios" = "N" ] || [ "$skip_ios" = "n" ]; then
20-
skip_ios=false
21-
else
22-
echo "Skipping iOS build..."
23-
skip_ios=true
54+
if [ "$BUILD_IOS" = "true" ] && [ -d "../package/ios/libs/bullet3" ]; then
55+
echo "[bullet3] iOS libraries already exist in react-native-filament package. Do you want to skip building them? (Y/N) (y)"
56+
read -r skip_ios
57+
if [ "$skip_ios" = "N" ] || [ "$skip_ios" = "n" ]; then
58+
BUILD_IOS=true
59+
else
60+
echo "Skipping iOS build..."
61+
BUILD_IOS=false
62+
fi
2463
fi
2564
fi
2665

27-
if [ "$skip_ios" = true ] && [ "$skip_android" = true ]; then
28-
echo "[bullet3] Both iOS and Android libraries already exist. Nothing to do."
66+
if [ "$BUILD_IOS" = "false" ] && [ "$BUILD_ANDROID" = "false" ]; then
67+
echo "[bullet3] Both iOS and Android builds are skipped. Nothing to do."
2968
exit 0
3069
fi
3170

@@ -36,71 +75,83 @@ PACKAGE_DIR=$(pwd)
3675
# Android #
3776
#############
3877

39-
rm -rf ../package/android/libs/bullet3
40-
mkdir -p ../package/android/libs/bullet3
41-
mkdir -p ../package/android/libs/bullet3/lib
42-
mkdir -p ../package/android/libs/bullet3/include
78+
if [ "$BUILD_ANDROID" = "true" ]; then
79+
echo "[bullet3] Building Android libraries..."
4380

44-
TARGET_SDK="$(grep '^Filament_targetSdkVersion' ./android/gradle.properties | cut -d'=' -f2)"
45-
ANDROID_NDK_VERSION="$(grep '^Filament_ndkversion' ./android/gradle.properties | cut -d'=' -f2)"
81+
rm -rf ../package/android/libs/bullet3
82+
mkdir -p ../package/android/libs/bullet3
83+
mkdir -p ../package/android/libs/bullet3/lib
84+
mkdir -p ../package/android/libs/bullet3/include
4685

47-
echo "Using target SDK: $TARGET_SDK"
48-
echo "Using NDK version: $ANDROID_NDK_VERSION"
86+
TARGET_SDK="$(grep '^Filament_targetSdkVersion' ./android/gradle.properties | cut -d'=' -f2)"
87+
ANDROID_NDK_VERSION="$(grep '^Filament_ndkversion' ./android/gradle.properties | cut -d'=' -f2)"
4988

50-
# We need to copy over the updated Bullet Android build files for NDK 27 compatibility
51-
cp -f scripts/BulletAndroidApplication.mk ../bullet3/build3/Android/jni/Application.mk
52-
cp -f scripts/BulletAndroid.mk ../bullet3/build3/Android/jni/Android.mk
53-
# Change the {PLATFORM_NAME} to the actual platform value from gradle.properties
54-
sed -i '' "s/{PLATFORM_NAME}/$TARGET_SDK/g" ../bullet3/build3/Android/jni/Application.mk
89+
echo "Using target SDK: $TARGET_SDK"
90+
echo "Using NDK version: $ANDROID_NDK_VERSION"
5591

56-
# Temporarily rename VERSION file to avoid conflicts with C++ standard library headers
57-
# (NDK 27+ includes <version> header which conflicts with bullet3's VERSION file)
58-
if [ -f ../bullet3/VERSION ]; then
59-
mv ../bullet3/VERSION ../bullet3/VERSION.tmp
60-
fi
92+
# We need to copy over the updated Bullet Android build files for NDK 27 compatibility
93+
cp -f scripts/BulletAndroidApplication.mk ../bullet3/build3/Android/jni/Application.mk
94+
cp -f scripts/BulletAndroid.mk ../bullet3/build3/Android/jni/Android.mk
95+
# Change the {PLATFORM_NAME} to the actual platform value from gradle.properties
96+
sed -i '' "s/{PLATFORM_NAME}/$TARGET_SDK/g" ../bullet3/build3/Android/jni/Application.mk
97+
98+
# Temporarily rename VERSION file to avoid conflicts with C++ standard library headers
99+
# (NDK 27+ includes <version> header which conflicts with bullet3's VERSION file)
100+
if [ -f ../bullet3/VERSION ]; then
101+
mv ../bullet3/VERSION ../bullet3/VERSION.tmp
102+
fi
103+
104+
cd ../bullet3/build3/Android/jni
105+
# Build the Bullet3 library
106+
$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION/ndk-build
107+
108+
# Copy the built library to the package
109+
cp -rf ../obj/local/* ../../../../package/android/libs/bullet3/lib
61110

62-
cd ../bullet3/build3/Android/jni
63-
# Build the Bullet3 library
64-
$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION/ndk-build
65-
66-
# Copy the built library to the package
67-
cp -rf ../obj/local/* ../../../../package/android/libs/bullet3/lib
68-
69-
# Clean all changes in bullet3 (the build files are not under gitignore)
70-
git checkout . # Discard all uncommitted changes
71-
rm -rf ../obj/ # Remove untracked files and directories
72-
73-
# Restore VERSION file if it was renamed
74-
if [ -f ../../../../bullet3/VERSION.tmp ]; then
75-
mv ../../../../bullet3/VERSION.tmp ../../../../bullet3/VERSION
76-
fi
77-
78-
# Remove the objs folder
79-
cd ../../../../package/android/libs/bullet3/lib
80-
rm -rf arm64-v8a/objs
81-
rm -rf armeabi-v7a/objs
82-
rm -rf x86/objs
83-
rm -rf x86_64/objs
84-
85-
# Copy over all headers
86-
cd $PACKAGE_DIR
87-
cp -rf ../bullet3/src/* android/libs/bullet3/include
88-
cd android/libs/bullet3/include
89-
# Remove all .cpp, .lua and .txt files
90-
find . -type f -name "*.cpp" -delete
91-
find . -type f -name "*.lua" -delete
92-
find . -type f -name "*.txt" -delete
111+
# Clean all changes in bullet3 (the build files are not under gitignore)
112+
git checkout . # Discard all uncommitted changes
113+
rm -rf ../obj/ # Remove untracked files and directories
114+
115+
# Restore VERSION file if it was renamed
116+
if [ -f ../../../../bullet3/VERSION.tmp ]; then
117+
mv ../../../../bullet3/VERSION.tmp ../../../../bullet3/VERSION
118+
fi
119+
120+
# Remove the objs folder
121+
cd ../../../../package/android/libs/bullet3/lib
122+
rm -rf arm64-v8a/objs
123+
rm -rf armeabi-v7a/objs
124+
rm -rf x86/objs
125+
rm -rf x86_64/objs
126+
127+
# Copy over all headers
128+
cd $PACKAGE_DIR
129+
cp -rf ../bullet3/src/* android/libs/bullet3/include
130+
cd android/libs/bullet3/include
131+
# Remove all .cpp, .lua and .txt files
132+
find . -type f -name "*.cpp" -delete
133+
find . -type f -name "*.lua" -delete
134+
find . -type f -name "*.txt" -delete
135+
136+
echo "[bullet3] Android libraries built successfully!"
137+
fi
93138

94139
#############
95140
# iOS #
96141
#############
97142

98-
cd $PACKAGE_DIR
143+
if [ "$BUILD_IOS" = "true" ]; then
144+
echo "[bullet3] Building iOS libraries..."
145+
146+
cd $PACKAGE_DIR
147+
148+
# For iOS we only need to copy the source files over (this is the recommended approach by bullet3):
149+
rm -rf ./ios/libs/bullet3
150+
mkdir -p ./ios/libs/bullet3
151+
cp -rf ../bullet3/src/* ./ios/libs/bullet3
99152

100-
# For iOS we only need to copy the source files over (this is the recommended approach by bullet3):
101-
rm -rf ./ios/libs/bullet3
102-
mkdir -p ./ios/libs/bullet3
103-
cp -rf ../bullet3/src/* ./ios/libs/bullet3
153+
# We need to remove the OpenCL folder as it is not supported on iOS
154+
rm -rf ./ios/libs/bullet3/Bullet3OpenCL
104155

105-
# We need to remove the OpenCL folder as it is not supported on iOS
106-
rm -rf ./ios/libs/bullet3/Bullet3OpenCL
156+
echo "[bullet3] iOS libraries built successfully!"
157+
fi

0 commit comments

Comments
 (0)