Skip to content

Commit c44cf4b

Browse files
committed
chore: add ci
1 parent 7cbe419 commit c44cf4b

File tree

6 files changed

+245
-15
lines changed

6 files changed

+245
-15
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: build-test
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
build-test:
10+
runs-on: macos-14
11+
env:
12+
LOCAL_BUILD: true
13+
DEVELOPER_DIR: /Applications/Xcode_15.4.app
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions-rs/toolchain@v1
17+
with:
18+
profile: minimal
19+
toolchain: 1.78.0
20+
default: true
21+
- name: get xcode information
22+
run: |
23+
xcodebuild -version
24+
swift --version
25+
- name: build xcframework
26+
run: ./scripts/build-swift-ffi.sh
27+
- name: Swift tests
28+
run: swift test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
99
/gen-swift
10+
loroFFI.xcframework
1011
loroFFI.xcframework.zip

loro-rs/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ path = "src/uniffi-bindgen.rs"
1616
[dependencies]
1717
# loro-ffi = { path = "../../loro/crates/loro-ffi" }
1818
loro-ffi = { git = "https://github.com/loro-dev/loro.git", branch = "feat-ffi-loro-788" }
19-
uniffi = { version = "0.28", features = ["cli"] }
19+
uniffi = { version = "0.28" }
2020

2121
[build-dependencies]
2222
uniffi = { version = "0.28", features = ["build"] }
23+
24+
[features]
25+
cli = ["uniffi/cli"]

loro-rs/src/uniffi-bindgen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fn main() {
2+
#[cfg(feature = "cli")]
23
uniffi::uniffi_bindgen_main()
34
}

scripts/build_swift_ffi.sh

Lines changed: 207 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,207 @@
1-
rm -rf gen-swift
2-
mkdir -p gen-swift/includes
3-
cd loro-rs
4-
cargo build -r
5-
cargo run -r --bin uniffi-bindgen generate src/loro.udl --language swift --out-dir ../gen-swift
6-
cd ..
7-
mv gen-swift/loroFFI.h gen-swift/includes/loroFFI.h
8-
mv gen-swift/loroFFI.modulemap gen-swift/includes/module.modulemap
9-
xcodebuild -create-xcframework -library loro-rs/target/release/libloro.a -headers gen-swift/includes -output loroFFI.xcframework
10-
zip -r loroFFI.xcframework.zip loroFFI.xcframework
11-
mv gen-swift/loro.swift Sources/Loro/LoroFFI.swift
12-
sh scripts/refine_trait.sh
13-
rm -rf gen-swift loroFFI.xcframework
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+
# The specific issue with an earlier nightly version and linking into an
19+
# XCFramework appears to be resolved with latest versions of +nightly toolchain
20+
# (as of 10/10/23), but leaving it open to float seems less useful than
21+
# moving the pinning forward, since Catalyst support (target macabi) still
22+
# requires an active, nightly toolchain.
23+
RUST_NIGHTLY="nightly-2024-05-23"
24+
25+
echo "Install nightly and rust-src for Catalyst"
26+
rustup toolchain install ${RUST_NIGHTLY}
27+
rustup component add rust-src --toolchain ${RUST_NIGHTLY}
28+
rustup update
29+
rustup default ${RUST_NIGHTLY}
30+
31+
32+
echo "▸ Install toolchains"
33+
rustup target add x86_64-apple-ios # iOS Simulator (Intel)
34+
rustup target add aarch64-apple-ios-sim # iOS Simulator (M1)
35+
rustup target add aarch64-apple-ios # iOS Device
36+
rustup target add aarch64-apple-darwin # macOS ARM/M1
37+
rustup target add x86_64-apple-darwin # macOS Intel/x86
38+
rustup target add wasm32-wasi # WebAssembly
39+
cargo_build="cargo build --manifest-path $RUST_FOLDER/Cargo.toml"
40+
cargo_build_nightly="cargo +${RUST_NIGHTLY} build --manifest-path $RUST_FOLDER/Cargo.toml"
41+
cargo_build_nightly_with_std="cargo -Zbuild-std build --manifest-path $RUST_FOLDER/Cargo.toml"
42+
43+
echo "▸ Clean state"
44+
rm -rf "${XCFRAMEWORK_FOLDER}"
45+
rm -rf "${SWIFT_FOLDER}"
46+
mkdir -p "${SWIFT_FOLDER}"
47+
echo "▸ Generate Swift Scaffolding Code"
48+
cargo run --manifest-path "$RUST_FOLDER/Cargo.toml" \
49+
--features=cli \
50+
--bin uniffi-bindgen generate \
51+
"$RUST_FOLDER/src/loro.udl" \
52+
--language swift \
53+
--out-dir "${SWIFT_FOLDER}"
54+
55+
bash "${THIS_SCRIPT_DIR}/refine_trait.sh"
56+
57+
echo "▸ Building for x86_64-apple-ios"
58+
CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" \
59+
$cargo_build --target x86_64-apple-ios --locked --release
60+
61+
echo "▸ Building for aarch64-apple-ios-sim"
62+
CFLAGS_aarch64_apple_ios="-target aarch64-apple-ios-sim" \
63+
$cargo_build --target aarch64-apple-ios-sim --locked --release
64+
65+
echo "▸ Building for aarch64-apple-ios"
66+
CFLAGS_aarch64_apple_ios="-target aarch64-apple-ios" \
67+
$cargo_build --target aarch64-apple-ios --locked --release
68+
69+
# echo "▸ Building for aarch64-apple-visionos-sim"
70+
# CFLAGS_aarch64_apple_visionos="-target aarch64-apple-visionos-sim" \
71+
# $cargo_build_nightly_with_std --target aarch64-apple-visionos-sim --locked --release
72+
73+
# echo "▸ Building for aarch64-apple-visionos"
74+
# CFLAGS_aarch64_apple_visionos="-target aarch64-apple-visionos" \
75+
# $cargo_build_nightly_with_std --target aarch64-apple-visionos --locked --release
76+
77+
echo "▸ Building for aarch64-apple-darwin"
78+
CFLAGS_aarch64_apple_darwin="-target aarch64-apple-darwin" \
79+
$cargo_build --target aarch64-apple-darwin --locked --release
80+
81+
echo "▸ Building for x86_64-apple-darwin"
82+
CFLAGS_x86_64_apple_darwin="-target x86_64-apple-darwin" \
83+
$cargo_build --target x86_64-apple-darwin --locked --release
84+
85+
echo "▸ Building for aarch64-apple-ios-macabi"
86+
$cargo_build_nightly -Z build-std --target aarch64-apple-ios-macabi --locked --release
87+
88+
echo "▸ Building for x86_64-apple-ios-macabi"
89+
$cargo_build_nightly -Z build-std --target x86_64-apple-ios-macabi --locked --release
90+
91+
echo "▸ Building for wasm32-wasi"
92+
$cargo_build --target wasm32-wasi --locked --release
93+
94+
# echo "▸ Consolidating the headers and modulemaps for XCFramework generation"
95+
# copies the generated header from AutomergeUniffi/automergeFFI.h to
96+
# Sources/_CAutomergeUniffi/include/automergeFFI.h within the project
97+
# cp "${SWIFT_FOLDER}/automergeFFI.h" "${SWIFT_FOLDER}/../Sources/_CAutomergeUniffi/include"
98+
# cp "${SWIFT_FOLDER}/automergeFFI.modulemap" "${SWIFT_FOLDER}/../Sources/_CAutomergeUniffi/include/module.modulemap"
99+
100+
# copies the generated header into the build folder structure for local XCFramework usage
101+
mkdir -p "${BUILD_FOLDER}/includes"
102+
cp "${SWIFT_FOLDER}/loroFFI.h" "${BUILD_FOLDER}/includes"
103+
cp "${SWIFT_FOLDER}/loroFFI.modulemap" "${BUILD_FOLDER}/includes/module.modulemap"
104+
cp "${SWIFT_FOLDER}/loro.swift" "${THIS_SCRIPT_DIR}/../Sources/Loro/LoroFFI.swift"
105+
106+
echo "▸ Lipo (merge) x86 and arm simulator static libraries into a fat static binary"
107+
mkdir -p "${BUILD_FOLDER}/ios-simulator/release"
108+
lipo -create \
109+
"${BUILD_FOLDER}/x86_64-apple-ios/release/${LIB_NAME}" \
110+
"${BUILD_FOLDER}/aarch64-apple-ios-sim/release/${LIB_NAME}" \
111+
-output "${BUILD_FOLDER}/ios-simulator/release/${LIB_NAME}"
112+
113+
# echo "▸ arm simulator static libraries into a static binary"
114+
# mkdir -p "${BUILD_FOLDER}/visionos-simulator/release"
115+
# lipo -create \
116+
# "${BUILD_FOLDER}/aarch64-apple-visionos-sim/release/${LIB_NAME}" \
117+
# -output "${BUILD_FOLDER}/visionos-simulator/release/${LIB_NAME}"
118+
119+
echo "▸ Lipo (merge) x86 and arm macOS static libraries into a fat static binary"
120+
mkdir -p "${BUILD_FOLDER}/apple-darwin/release"
121+
lipo -create \
122+
"${BUILD_FOLDER}/x86_64-apple-darwin/release/${LIB_NAME}" \
123+
"${BUILD_FOLDER}/aarch64-apple-darwin/release/${LIB_NAME}" \
124+
-output "${BUILD_FOLDER}/apple-darwin/release/${LIB_NAME}"
125+
126+
echo "▸ Lipo (merge) x86 and arm macOS Catalyst static libraries into a fat static binary"
127+
mkdir -p "${BUILD_FOLDER}/apple-macabi/release"
128+
lipo -create \
129+
"${BUILD_FOLDER}/x86_64-apple-ios-macabi/release/${LIB_NAME}" \
130+
"${BUILD_FOLDER}/aarch64-apple-ios-macabi/release/${LIB_NAME}" \
131+
-output "${BUILD_FOLDER}/apple-macabi/release/${LIB_NAME}"
132+
133+
134+
# -library "$BUILD_FOLDER/aarch64-apple-visionos/release/$LIB_NAME" \
135+
# -headers "${BUILD_FOLDER}/includes" \
136+
# -library "${BUILD_FOLDER}/visionos-simulator/release/${LIB_NAME}" \
137+
# -headers "${BUILD_FOLDER}/includes" \
138+
xcodebuild -create-xcframework \
139+
-library "$BUILD_FOLDER/aarch64-apple-ios/release/$LIB_NAME" \
140+
-headers "${BUILD_FOLDER}/includes" \
141+
-library "${BUILD_FOLDER}/ios-simulator/release/${LIB_NAME}" \
142+
-headers "${BUILD_FOLDER}/includes" \
143+
-library "$BUILD_FOLDER/apple-darwin/release/$LIB_NAME" \
144+
-headers "${BUILD_FOLDER}/includes" \
145+
-library "$BUILD_FOLDER/apple-macabi/release/$LIB_NAME" \
146+
-headers "${BUILD_FOLDER}/includes" \
147+
-output "${XCFRAMEWORK_FOLDER}"
148+
149+
echo "▸ Compress xcframework"
150+
ditto -c -k --sequesterRsrc --keepParent "$XCFRAMEWORK_FOLDER" "$XCFRAMEWORK_FOLDER.zip"
151+
152+
echo "▸ Compute checksum"
153+
openssl dgst -sha256 "$XCFRAMEWORK_FOLDER.zip"
154+
155+
156+
#############
157+
# rm -rf gen-swift
158+
# mkdir -p gen-swift/includes
159+
# cd loro-rs
160+
# cargo run --features=cli --bin uniffi-bindgen generate src/loro.udl --language swift --out-dir ../gen-swift
161+
162+
# echo "Building x86_64-apple-ios"
163+
# CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" \
164+
# cargo build --target x86_64-apple-ios --locked --release
165+
166+
# echo "Building aarch64-apple-ios-sim"
167+
# CFLAGS_x86_64_apple_ios="-aarch64-apple-ios-sim" \
168+
# cargo build --target aarch64-apple-ios-sim --locked --release
169+
170+
# echo "Building aarch64-apple-ios"
171+
# CFLAGS_x86_64_apple_ios="-target aarch64-apple-ios" \
172+
# cargo build --target aarch64-apple-ios --locked --release
173+
174+
# echo "Building aarch64-apple-visionos-sim"
175+
# CFLAGS_x86_64_apple_ios="-target aarch64-apple-visionos-sim" \
176+
# cargo build --target aarch64-apple-visionos-sim --locked --release
177+
178+
# echo "Building aarch64-apple-visionos"
179+
# CFLAGS_x86_64_apple_ios="-target aarch64-apple-visionos" \
180+
# cargo build --target aarch64-apple-visionos --locked --release
181+
182+
# echo "Building aarch64-apple-darwin"
183+
# CFLAGS_x86_64_apple_ios="-target aarch64-apple-darwin" \
184+
# cargo build --target aarch64-apple-darwin --locked --release
185+
186+
# echo "Building x86_64-apple-darwin"
187+
# CFLAGS_x86_64_apple_ios="-target x86_64-apple-darwin" \
188+
# cargo build --target x86_64-apple-darwin --locked --release
189+
190+
# echo "Building aarch64-apple-ios-macabi"
191+
# CFLAGS_x86_64_apple_ios="-target aarch64-apple-ios-macabi" \
192+
# cargo build --target aarch64-apple-ios-macabi --locked --release
193+
194+
# echo "Building x86_64-apple-ios-macabi"
195+
# CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios-macabi" \
196+
# cargo build --target x86_64-apple-ios-macabi --locked --release
197+
198+
199+
200+
# cd ..
201+
# mv gen-swift/loroFFI.h gen-swift/includes/loroFFI.h
202+
# mv gen-swift/loroFFI.modulemap gen-swift/includes/module.modulemap
203+
# xcodebuild -create-xcframework -library loro-rs/target/release/libloro.a -headers gen-swift/includes -output loroFFI.xcframework
204+
# zip -r loroFFI.xcframework.zip loroFFI.xcframework
205+
# mv gen-swift/loro.swift Sources/Loro/LoroFFI.swift
206+
# sh scripts/refine_trait.sh
207+
# rm -rf gen-swift loroFFI.xcframework

scripts/refine_trait.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22

3-
file_path="Sources/Loro/loroFFI.swift"
3+
set -euxo pipefail
4+
THIS_SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
5+
SWIFT_FOLDER="$THIS_SCRIPT_DIR/../gen-swift"
6+
file_path="$SWIFT_FOLDER/loro.swift"
47

58
search_string="public protocol LoroValueLike : AnyObject {"
69
replace_string="public protocol LoroValueLike : Any {"

0 commit comments

Comments
 (0)