-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate_native_libs.sh
More file actions
executable file
·219 lines (187 loc) · 7.45 KB
/
update_native_libs.sh
File metadata and controls
executable file
·219 lines (187 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
#
# Clone F3D, build for Android using Docker, and copy native libraries.
#
# By default, clones f3d-app/f3d master from GitHub and builds for all four
# Android ABIs. Each architecture uses its own Docker image from
# ghcr.io/f3d-app/f3d-android-<abi>.
#
# Usage:
# ./update_native_libs.sh [options]
#
# Options:
# --repo <owner/repo> GitHub repository (default: f3d-app/f3d)
# --ref <name> Git ref (branch, tag, or commit SHA) to fetch. When
# specified, the resolved commit SHA is written to
# jniLibs-lock.json. When omitted, the script reads
# jniLibs-lock.json to fetch the pinned commit.
# --clone-dir <path> Directory to clone into (default: temporary, cleaned up on exit).
# If the directory already contains a git repo, no clone is
# performed and --repo/--ref are ignored.
# --arch <abi> Build only specific ABI (can be repeated; default: all four)
#
# Examples:
# ./update_native_libs.sh
# ./update_native_libs.sh --ref v3.4.1
# ./update_native_libs.sh --arch arm64-v8a --arch x86_64
# ./update_native_libs.sh --repo Meakk/f3d --ref my-feature
# ./update_native_libs.sh --clone-dir ~/dev/f3d-src
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ALL_ARCHS=(arm64-v8a armeabi-v7a x86_64 x86)
REPO="f3d-app/f3d"
REF=""
CLONE_DIR=""
ARCHS=()
REF_SPECIFIED=false
REPO_SPECIFIED=false
LOCK_FILE="$SCRIPT_DIR/jniLibs-lock.json"
usage() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --repo <owner/repo> GitHub repository (default: $REPO)"
echo " --ref <name> Git ref: branch, tag, or commit SHA (writes commit to jniLibs-lock.json)"
echo " --clone-dir <path> Clone directory (default: temporary)"
echo " --arch <abi> ABI to build (repeatable; default: all)"
echo ""
echo "Supported ABIs: ${ALL_ARCHS[*]}"
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--repo)
REPO="$2"
REPO_SPECIFIED=true
shift 2
;;
--ref)
REF="$2"
REF_SPECIFIED=true
shift 2
;;
--clone-dir)
CLONE_DIR="$2"
shift 2
;;
--arch)
ARCHS+=("$2")
shift 2
;;
-h|--help)
usage
;;
*)
echo "Error: unknown option '$1'"
usage
;;
esac
done
# Default to all architectures
if [[ ${#ARCHS[@]} -eq 0 ]]; then
ARCHS=("${ALL_ARCHS[@]}")
fi
# Validate requested ABIs
for arch in "${ARCHS[@]}"; do
case "$arch" in
arm64-v8a|armeabi-v7a|x86_64|x86) ;;
*)
echo "Error: unsupported ABI '$arch'."
echo "Supported: ${ALL_ARCHS[*]}"
exit 1
;;
esac
done
# ── Resolve commit / branch ───────────────────────────────────────────────────
if [[ "$REF_SPECIFIED" == false ]]; then
# Read pinned commit from lock file
if [[ ! -f "$LOCK_FILE" ]]; then
echo "Error: --ref not specified and $LOCK_FILE not found."
exit 1
fi
REF=$(jq -r '.commit' "$LOCK_FILE")
if [[ "$REPO_SPECIFIED" == false ]]; then
REPO=$(jq -r '.repo' "$LOCK_FILE")
fi
echo "Using pinned commit $REF (from $LOCK_FILE)"
fi
# ── Clone ────────────────────────────────────────────────────────────────────
if [[ -z "$CLONE_DIR" ]]; then
CLONE_DIR="$(mktemp -d)"
trap 'echo "Cleaning up $CLONE_DIR"; rm -rf "$CLONE_DIR"' EXIT
fi
if [[ -d "$CLONE_DIR/.git" ]]; then
echo "Source directory $CLONE_DIR already contains a git repo, skipping clone."
else
REPO_URL="https://github.com/${REPO}.git"
echo "Cloning $REPO_URL into $CLONE_DIR ..."
GIT_LFS_SKIP_SMUDGE=1 git clone "$REPO_URL" "$CLONE_DIR"
git -C "$CLONE_DIR" checkout "$REF"
fi
# ── Write lock file ──────────────────────────────────────────────────────────
if [[ "$REF_SPECIFIED" == true ]]; then
COMMIT=$(git -C "$CLONE_DIR" rev-parse HEAD)
VERSION=$(git -C "$CLONE_DIR" describe)
jq -n --arg repo "$REPO" --arg commit "$COMMIT" --arg version "$VERSION" \
'{repo: $repo, commit: $commit, version: $version}' > "$LOCK_FILE"
echo "Pinned commit $COMMIT (version $VERSION) to $LOCK_FILE"
fi
# ── Pull Docker images ───────────────────────────────────────────────────────
for arch in "${ARCHS[@]}"; do
echo "Pulling ghcr.io/f3d-app/f3d-android-${arch} ..."
docker pull "ghcr.io/f3d-app/f3d-android-${arch}"
done
# ── Build & copy for each architecture ───────────────────────────────────────
for arch in "${ARCHS[@]}"; do
echo ""
echo "========================================"
echo " Building for $arch"
echo "========================================"
CONFIG_CMD="cmake -S /src -B /src/build-${arch} \
-DCMAKE_BUILD_TYPE=Release \
-DF3D_MODULE_EXR=ON \
-DF3D_MODULE_UI=OFF \
-DF3D_MODULE_WEBP=ON \
-DF3D_PLUGINS_STATIC_BUILD=ON \
-DF3D_PLUGIN_BUILD_ALEMBIC=ON \
-DF3D_PLUGIN_BUILD_ASSIMP=ON \
-DF3D_PLUGIN_BUILD_DRACO=ON \
-DF3D_PLUGIN_BUILD_HDF=OFF \
-DF3D_PLUGIN_BUILD_OCCT=ON \
-DF3D_PLUGIN_BUILD_WEBIFC=ON \
-DF3D_STRICT_BUILD=ON \
-DF3D_BINDINGS_JAVA=ON"
BUILD_CMD="cmake --build /src/build-${arch}"
STRIP_CMD="/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --strip-all /src/build-${arch}/lib/libf3d-java.so"
docker run --rm \
-e CMAKE_BUILD_PARALLEL_LEVEL \
-u "$(id -u):$(id -g)" \
-v "$CLONE_DIR":/src \
"ghcr.io/f3d-app/f3d-android-${arch}" \
sh -c "$CONFIG_CMD && $BUILD_CMD && $STRIP_CMD"
# Copy .so into the Android project
SO_SRC="$CLONE_DIR/build-${arch}/lib/libf3d-java.so"
if [[ ! -f "$SO_SRC" ]]; then
echo "Error: expected $SO_SRC not found after build."
exit 1
fi
JNILIBS_DIR="$SCRIPT_DIR/f3d/src/main/jniLibs/$arch"
mkdir -p "$JNILIBS_DIR"
cp "$SO_SRC" "$JNILIBS_DIR/libf3d-java.so"
SO_SIZE=$(du -h "$JNILIBS_DIR/libf3d-java.so" | cut -f1)
echo "Copied libf3d-java.so ($SO_SIZE) -> jniLibs/$arch/"
done
# ── Copy .jar ────────────────────────────────────────────────────────────────
# The jar is architecture-independent, copy from the first built arch
JAR_SRC="$CLONE_DIR/build-${ARCHS[0]}/java/f3d.jar"
if [[ ! -f "$JAR_SRC" ]]; then
echo "Error: expected $JAR_SRC not found after build."
exit 1
fi
LIBS_DIR="$SCRIPT_DIR/f3d/libs"
mkdir -p "$LIBS_DIR"
cp "$JAR_SRC" "$LIBS_DIR/f3d.jar"
# ── Summary ──────────────────────────────────────────────────────────────────
echo ""
echo "Done. Updated architectures: ${ARCHS[*]}"