|
1
|
#!/usr/bin/env bash |
|
2
|
# generate-bindings.sh |
|
3
|
# |
|
4
|
# Generates Kotlin UniFFI bindings from the compiled Android arm64 library. |
|
5
|
# Output goes to lib/src/generated/kotlin/ and is gitignored. |
|
6
|
# |
|
7
|
# Run this after build-android.sh whenever the Rust API changes. |
|
8
|
# |
|
9
|
# Prerequisites |
|
10
|
# ------------- |
|
11
|
# cargo-ndk and Android targets installed (see build-android.sh) |
|
12
|
# uniffi-bindgen binary built (pinned to =0.31.0): |
|
13
|
# cargo build --manifest-path ../../uniffi-bindgen/Cargo.toml --release |
|
14
|
# |
|
15
|
# Usage |
|
16
|
# ./scripts/generate-bindings.sh |
|
17
|
|
|
18
|
set -euo pipefail |
|
19
|
|
|
20
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
|
21
|
SDK_DIR="$SCRIPT_DIR/.." |
|
22
|
REPO_ROOT="$(cd "$SDK_DIR/../.." && pwd)" |
|
23
|
OUT_DIR="$SDK_DIR/lib/src/generated/kotlin" |
|
24
|
BINDGEN="$REPO_ROOT/uniffi-bindgen/target/release/uniffi-bindgen" |
|
25
|
LIBRARY="$REPO_ROOT/target/aarch64-linux-android/release/libonde.so" |
|
26
|
|
|
27
|
echo "=== Generating Kotlin UniFFI bindings ===" |
|
28
|
|
|
29
|
# Build the bindgen binary if it doesn't exist or is stale |
|
30
|
if [[ ! -f "$BINDGEN" ]]; then |
|
31
|
echo " → Building uniffi-bindgen…" |
|
32
|
cargo build --manifest-path "$REPO_ROOT/uniffi-bindgen/Cargo.toml" --release |
|
33
|
fi |
|
34
|
|
|
35
|
# The library must exist — run build-android.sh first |
|
36
|
if [[ ! -f "$LIBRARY" ]]; then |
|
37
|
echo "Error: $LIBRARY not found." |
|
38
|
echo "Run ./scripts/build-android.sh first to compile the Rust library." |
|
39
|
exit 1 |
|
40
|
fi |
|
41
|
|
|
42
|
mkdir -p "$OUT_DIR" |
|
43
|
|
|
44
|
echo " → Generating from: $LIBRARY" |
|
45
|
"$BINDGEN" generate "$LIBRARY" \ |
|
46
|
--language kotlin \ |
|
47
|
--out-dir "$OUT_DIR" |
|
48
|
|
|
49
|
echo "" |
|
50
|
echo "Generated bindings: $OUT_DIR" |
|
51
|
echo "Generated files:" |
|
52
|
ls -lh "$OUT_DIR" |