Skip to content

Commit fb1fd22

Browse files
committed
chore: readme
1 parent e7ccbbf commit fb1fd22

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ doc.checkoutToLatest()
9191

9292
## Develop
9393

94-
If you wanna build and develop this project, you need first run this script:
94+
If you wanna build and develop this project with MacOS, you need first run this script:
9595

9696
```bash
97-
sh ./scripts/build_swift_ffi.sh
97+
sh ./scripts/build_macos.sh
9898
```
9999

100100
The script will run `uniffi` and generate the `loroFFI.xcframework.zip`.

scripts/build_macos.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
# This script was cribbed from https://github.com/automerge/automerge-swift/blob/main/scripts/build-xcframework.sh
4+
# which was cribbed from https://github.com/y-crdt/y-uniffi/blob/7cd55266c11c424afa3ae5b3edae6e9f70d9a6bb/lib/build-xcframework.sh
5+
# which was written by Joseph Heck and Aidar Nugmanoff and licensed under the MIT license.
6+
7+
set -euxo pipefail
8+
THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
9+
LIB_NAME="libloro.a"
10+
RUST_FOLDER="$THIS_SCRIPT_DIR/../loro-rs"
11+
FRAMEWORK_NAME="loroFFI"
12+
13+
SWIFT_FOLDER="$THIS_SCRIPT_DIR/../gen-swift"
14+
BUILD_FOLDER="$RUST_FOLDER/target"
15+
16+
XCFRAMEWORK_FOLDER="$THIS_SCRIPT_DIR/../${FRAMEWORK_NAME}.xcframework"
17+
18+
19+
echo "▸ Install toolchains"
20+
rustup target add aarch64-apple-darwin # macOS ARM/M1
21+
rustup target add x86_64-apple-darwin # macOS Intel/x86
22+
cargo_build="cargo build --manifest-path $RUST_FOLDER/Cargo.toml"
23+
24+
echo "▸ Clean state"
25+
rm -rf "${XCFRAMEWORK_FOLDER}"
26+
rm -rf "${SWIFT_FOLDER}"
27+
mkdir -p "${SWIFT_FOLDER}"
28+
echo "▸ Generate Swift Scaffolding Code"
29+
cargo run --manifest-path "$RUST_FOLDER/Cargo.toml" \
30+
--features=cli \
31+
--bin uniffi-bindgen generate \
32+
"$RUST_FOLDER/src/loro.udl" \
33+
--language swift \
34+
--out-dir "${SWIFT_FOLDER}"
35+
36+
bash "${THIS_SCRIPT_DIR}/refine_trait.sh"
37+
38+
echo "▸ Building for aarch64-apple-darwin"
39+
CFLAGS_aarch64_apple_darwin="-target aarch64-apple-darwin" \
40+
$cargo_build --target aarch64-apple-darwin --locked --release
41+
42+
echo "▸ Building for x86_64-apple-darwin"
43+
CFLAGS_x86_64_apple_darwin="-target x86_64-apple-darwin" \
44+
$cargo_build --target x86_64-apple-darwin --locked --release
45+
46+
# copies the generated header into the build folder structure for local XCFramework usage
47+
mkdir -p "${BUILD_FOLDER}/includes"
48+
cp "${SWIFT_FOLDER}/loroFFI.h" "${BUILD_FOLDER}/includes"
49+
cp "${SWIFT_FOLDER}/loroFFI.modulemap" "${BUILD_FOLDER}/includes/module.modulemap"
50+
cp -f "${SWIFT_FOLDER}/loro.swift" "${THIS_SCRIPT_DIR}/../Sources/Loro/LoroFFI.swift"
51+
52+
echo "▸ Lipo (merge) x86 and arm macOS static libraries into a fat static binary"
53+
mkdir -p "${BUILD_FOLDER}/apple-darwin/release"
54+
lipo -create \
55+
"${BUILD_FOLDER}/x86_64-apple-darwin/release/${LIB_NAME}" \
56+
"${BUILD_FOLDER}/aarch64-apple-darwin/release/${LIB_NAME}" \
57+
-output "${BUILD_FOLDER}/apple-darwin/release/${LIB_NAME}"
58+
59+
xcodebuild -create-xcframework \
60+
-library "$BUILD_FOLDER/apple-darwin/release/$LIB_NAME" \
61+
-headers "${BUILD_FOLDER}/includes" \
62+
-output "${XCFRAMEWORK_FOLDER}"
63+
64+
echo "▸ Compress xcframework"
65+
ditto -c -k --sequesterRsrc --keepParent "$XCFRAMEWORK_FOLDER" "$XCFRAMEWORK_FOLDER.zip"

0 commit comments

Comments
 (0)