Skip to content

Commit bfc4946

Browse files
authored
Adds helper build script to build ffi libs locally and copy to plugins folder (#197)
* My new build script to build macos and android locally and copy ffi lib artifacts into plugins * Added section in README for the new build helper script
1 parent 0183a3a commit bfc4946

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

BuildScripts~/build_ffi_locally.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
4+
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
5+
MANIFEST="$ROOT/client-sdk-rust~/Cargo.toml"
6+
BASE_DST="$ROOT/Runtime/Plugins"
7+
BASE_TARGET="$ROOT/client-sdk-rust~/target"
8+
9+
RED='\033[0;31m'
10+
YELLOW='\033[0;33m'
11+
GREEN='\033[0;32m'
12+
RESET='\033[0m'
13+
14+
usage() {
15+
echo "Usage: $0 <platform>"
16+
echo ""
17+
echo "Platforms:"
18+
echo " macos Build for aarch64-apple-darwin"
19+
echo " android Build for aarch64-linux-android"
20+
exit 1
21+
}
22+
23+
if [ $# -ne 1 ]; then
24+
echo -e "${RED}Error: Expected exactly one argument.${RESET}"
25+
usage
26+
fi
27+
28+
PLATFORM="$1"
29+
30+
case "$PLATFORM" in
31+
macos)
32+
echo "Building for macOS (aarch64-apple-darwin)..."
33+
cargo build \
34+
--manifest-path "$MANIFEST" \
35+
--release \
36+
--workspace \
37+
-p livekit \
38+
--target aarch64-apple-darwin
39+
BUILD_STATUS=$?
40+
41+
SRC="$BASE_TARGET/aarch64-apple-darwin/release/liblivekit_ffi.dylib"
42+
DST="$BASE_DST/ffi-macos-arm64/liblivekit_ffi.dylib"
43+
;;
44+
android)
45+
echo "Building for Android (aarch64-linux-android)..."
46+
pushd "$ROOT/client-sdk-rust~" > /dev/null
47+
cargo ndk \
48+
--target aarch64-linux-android \
49+
build \
50+
--release \
51+
-p livekit \
52+
--workspace \
53+
-v \
54+
--no-default-features \
55+
--features "rustls-tls-webpki-roots"
56+
BUILD_STATUS=$?
57+
popd > /dev/null
58+
59+
SRC="$BASE_TARGET/aarch64-linux-android/release/liblivekit_ffi.so"
60+
DST="$BASE_DST/ffi-android-arm64/liblivekit_ffi.so"
61+
;;
62+
*)
63+
echo -e "${RED}Error: Unknown platform '$PLATFORM'.${RESET}"
64+
usage
65+
;;
66+
esac
67+
68+
if [ $BUILD_STATUS -ne 0 ]; then
69+
echo -e "${RED}Build failed. Aborting copy.${RESET}"
70+
exit 1
71+
fi
72+
73+
echo ""
74+
echo "Copying to $DST..."
75+
cp -f "$SRC" "$DST"
76+
77+
if [ $? -eq 0 ]; then
78+
echo -e "${GREEN}Copied $(basename "$DST") successfully.${RESET}"
79+
if [ "$PLATFORM" = "macos" ]; then
80+
echo ""
81+
echo -e "${YELLOW}WARNING: QUIT UNITY TO LOAD NEW LIB${RESET}"
82+
fi
83+
else
84+
echo -e "${RED}Failed to copy $(basename "$DST"). Check that the source file exists and the destination directory is writable.${RESET}"
85+
exit 1
86+
fi

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ You can use the package manager to import local `client-sdk-unity` into your Uni
4848

4949
Or you can import the git url `https://github.com/livekit/client-sdk-unity.git` from the package manager.
5050

51+
### Building Livekit plugins locally
5152

53+
For local development, initialize the git submodule containing the Rust code for the LiveKit plugin libraries.
54+
55+
There is a [helper script](https://github.com/livekit/client-sdk-unity/blob/main/BuildScripts~/build_ffi_locally.sh) to build the libraries locally and exchange the downloaded libraries with the build artifacts.
56+
57+
Currently, the build script supports the following arguments:
58+
- macos
59+
- android
5260

5361
### iOS
5462

0 commit comments

Comments
 (0)