Skip to content

Commit 5ffe9cb

Browse files
committed
feat: swift bindings
1 parent cd3d1cd commit 5ffe9cb

File tree

7 files changed

+271
-0
lines changed

7 files changed

+271
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: ARK Drop Swift Bindings Release
2+
3+
on:
4+
push:
5+
paths:
6+
- "drop-core/entities/**"
7+
- "drop-core/exchanges/**"
8+
- "drop-core/uniffi/**"
9+
- ".github/workflows/arkdrop-swift-bindings-release.yml"
10+
workflow_dispatch:
11+
12+
jobs:
13+
build-and-publish:
14+
runs-on: macos-latest
15+
permissions:
16+
contents: write
17+
packages: write
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install Rust
23+
uses: dtolnay/rust-toolchain@stable
24+
with:
25+
targets: aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim,x86_64-apple-darwin,aarch64-apple-darwin
26+
27+
- uses: Swatinem/rust-cache@v2
28+
with:
29+
workspaces: drop-core/uniffi
30+
31+
- name: Install Xcode Command Line Tools
32+
run: |
33+
xcode-select --install 2>/dev/null || true
34+
xcode-select -p
35+
36+
- name: Generate Swift Bindings
37+
working-directory: ./drop-core/uniffi/bindings/swift
38+
run: |
39+
chmod +x generate-bindings.sh
40+
./generate-bindings.sh
41+
42+
- name: Build XCFramework
43+
working-directory: ./drop-core/uniffi/bindings/swift
44+
run: |
45+
chmod +x build-xcframework.sh
46+
./build-xcframework.sh
47+
48+
- name: Create Swift Package Archive
49+
working-directory: ./drop-core/uniffi/bindings/swift
50+
run: |
51+
# Create a distributable package
52+
mkdir -p ArkDrop-Swift-Package
53+
cp -r arkdrop_uniffiFFI.xcframework ArkDrop-Swift-Package/
54+
cp drop.swift ArkDrop-Swift-Package/
55+
cp Package.swift ArkDrop-Swift-Package/
56+
cp arkdrop_uniffiFFI.h ArkDrop-Swift-Package/
57+
58+
# Create a zip archive
59+
zip -r ArkDrop-Swift-Package.zip ArkDrop-Swift-Package/
60+
61+
# Also create a checksum
62+
shasum -a 256 ArkDrop-Swift-Package.zip > ArkDrop-Swift-Package.zip.sha256
63+
64+
- name: Upload Build Artifacts
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: swift-bindings
68+
path: |
69+
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip
70+
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip.sha256
71+
retention-days: 30
72+
73+
- name: Create Release
74+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
75+
uses: softprops/action-gh-release@v2
76+
with:
77+
tag_name: swift-bindings-${{ github.run_id }}
78+
name: Swift Bindings Release ${{ github.run_id }}
79+
draft: false
80+
prerelease: false
81+
files: |
82+
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip
83+
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip.sha256
84+
body: |
85+
## Swift Bindings for ARK Drop
86+
87+
This release contains the Swift bindings for ARK Drop, including:
88+
- XCFramework for iOS (device and simulator) and macOS
89+
- Swift source files
90+
- Swift Package Manager configuration
91+
92+
### Installation
93+
94+
#### Swift Package Manager
95+
96+
1. Download and extract `ArkDrop-Swift-Package.zip`
97+
2. Add the package to your Xcode project or include it in your `Package.swift`:
98+
99+
```swift
100+
dependencies: [
101+
.package(path: "path/to/ArkDrop-Swift-Package")
102+
]
103+
```
104+
105+
#### Manual Installation
106+
107+
1. Download `ArkDrop-Swift-Package.zip`
108+
2. Extract and add `arkdrop_uniffiFFI.xcframework` to your Xcode project
109+
3. Add `drop.swift` to your project sources
110+
111+
### Verification
112+
113+
Verify the package integrity using the SHA256 checksum:
114+
```bash
115+
shasum -a 256 -c ArkDrop-Swift-Package.zip.sha256
116+
```
117+
118+
Generated from commit: ${{ github.sha }}
119+
env:
120+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

drop-core/uniffi/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ name = "uniffi-bindgen"
1313
path = "uniffi-bindgen.rs"
1414
bench = false
1515

16+
[[bin]]
17+
name = "uniffi-bindgen-swift"
18+
path = "uniffi-bindgen-swift.rs"
19+
bench = false
20+
1621
[dependencies]
1722
arkdropx-sender = { path = "../exchanges/sender" }
1823
arkdropx-receiver = { path = "../exchanges/receiver" }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Build artifacts
2+
build/
3+
*.xcframework
4+
5+
# Generated files from uniffi-bindgen
6+
*.swift
7+
*.h
8+
*.modulemap
9+
10+
# Swift Package Manager
11+
.build/
12+
.swiftpm/
13+
14+
# Xcode
15+
xcuserdata/
16+
*.xcworkspace
17+
DerivedData/
18+
19+
# macOS
20+
.DS_Store
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Build the Rust library for iOS and macOS and create an XCFramework
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
UNIFFI_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
8+
BUILD_DIR="$SCRIPT_DIR/build"
9+
XCFRAMEWORK_NAME="arkdrop_uniffiFFI.xcframework"
10+
11+
echo "Building Rust library for iOS and macOS..."
12+
13+
# Clean previous builds
14+
rm -rf "$BUILD_DIR"
15+
rm -rf "$SCRIPT_DIR/$XCFRAMEWORK_NAME"
16+
mkdir -p "$BUILD_DIR"
17+
18+
cd "$UNIFFI_DIR"
19+
20+
# Build for iOS device (arm64)
21+
echo "Building for iOS (aarch64-apple-ios)..."
22+
cargo build --release --target aarch64-apple-ios
23+
24+
# Build for iOS Simulator (x86_64 and arm64)
25+
echo "Building for iOS Simulator..."
26+
cargo build --release --target x86_64-apple-ios
27+
cargo build --release --target aarch64-apple-ios-sim
28+
29+
# Build for macOS (x86_64 and arm64)
30+
echo "Building for macOS..."
31+
cargo build --release --target x86_64-apple-darwin
32+
cargo build --release --target aarch64-apple-darwin
33+
34+
# Create fat libraries
35+
echo "Creating universal libraries..."
36+
mkdir -p "$BUILD_DIR/ios-simulator"
37+
mkdir -p "$BUILD_DIR/macos"
38+
39+
lipo -create \
40+
"$UNIFFI_DIR/target/x86_64-apple-ios/release/libarkdrop_uniffi.a" \
41+
"$UNIFFI_DIR/target/aarch64-apple-ios-sim/release/libarkdrop_uniffi.a" \
42+
-output "$BUILD_DIR/ios-simulator/libarkdrop_uniffi.a"
43+
44+
lipo -create \
45+
"$UNIFFI_DIR/target/x86_64-apple-darwin/release/libarkdrop_uniffi.a" \
46+
"$UNIFFI_DIR/target/aarch64-apple-darwin/release/libarkdrop_uniffi.a" \
47+
-output "$BUILD_DIR/macos/libarkdrop_uniffi.a"
48+
49+
# Copy iOS device library
50+
mkdir -p "$BUILD_DIR/ios"
51+
cp "$UNIFFI_DIR/target/aarch64-apple-ios/release/libarkdrop_uniffi.a" "$BUILD_DIR/ios/"
52+
53+
# Copy headers and modulemap to each platform directory
54+
for platform_dir in "$BUILD_DIR/ios" "$BUILD_DIR/ios-simulator" "$BUILD_DIR/macos"; do
55+
mkdir -p "$platform_dir/Headers"
56+
57+
# Copy the C header
58+
if [ -f "$SCRIPT_DIR/arkdrop_uniffiFFI.h" ]; then
59+
cp "$SCRIPT_DIR/arkdrop_uniffiFFI.h" "$platform_dir/Headers/"
60+
else
61+
echo "Error: arkdrop_uniffiFFI.h not found. Run generate-bindings.sh first."
62+
exit 1
63+
fi
64+
65+
# Copy the modulemap
66+
if [ -f "$SCRIPT_DIR/module.modulemap" ]; then
67+
cp "$SCRIPT_DIR/module.modulemap" "$platform_dir/Headers/"
68+
else
69+
echo "Error: module.modulemap not found. Run generate-bindings.sh first."
70+
exit 1
71+
fi
72+
done
73+
74+
# Create XCFramework
75+
echo "Creating XCFramework..."
76+
xcodebuild -create-xcframework \
77+
-library "$BUILD_DIR/ios/libarkdrop_uniffi.a" \
78+
-headers "$BUILD_DIR/ios/Headers" \
79+
-library "$BUILD_DIR/ios-simulator/libarkdrop_uniffi.a" \
80+
-headers "$BUILD_DIR/ios-simulator/Headers" \
81+
-library "$BUILD_DIR/macos/libarkdrop_uniffi.a" \
82+
-headers "$BUILD_DIR/macos/Headers" \
83+
-output "$SCRIPT_DIR/$XCFRAMEWORK_NAME"
84+
85+
echo "XCFramework created successfully: $SCRIPT_DIR/$XCFRAMEWORK_NAME"
86+
echo ""
87+
echo "You can now use the Swift package with Xcode or Swift Package Manager"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Generate Swift bindings using uniffi-bindgen
5+
# This creates the .swift file and .modulemap for the Swift module
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
UNIFFI_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
9+
OUTPUT_DIR="$SCRIPT_DIR"
10+
11+
echo "Generating Swift bindings..."
12+
echo "UniFFI directory: $UNIFFI_DIR"
13+
echo "Output directory: $OUTPUT_DIR"
14+
15+
cd "$UNIFFI_DIR"
16+
17+
# Generate Swift bindings
18+
cargo run --bin uniffi-bindgen generate \
19+
./src/drop.udl \
20+
--language swift \
21+
--out-dir "$OUTPUT_DIR"
22+
23+
# Rename modulemap to module.modulemap (required for XCFramework)
24+
if [ -f "$OUTPUT_DIR/arkdrop_uniffiFFI.modulemap" ]; then
25+
mv "$OUTPUT_DIR/arkdrop_uniffiFFI.modulemap" "$OUTPUT_DIR/module.modulemap"
26+
echo "Renamed modulemap to module.modulemap"
27+
fi
28+
29+
echo "Swift bindings generated successfully!"
30+
echo "Generated files:"
31+
ls -la "$OUTPUT_DIR"/*.swift "$OUTPUT_DIR"/*.modulemap 2>/dev/null || true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
uniffi::uniffi_bindgen_swift()
3+
}

drop-core/uniffi/uniffi.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
[bindings.kotlin]
22
package_name = "dev.arkbuilders.drop"
33
cdylib_name = "arkdrop_uniffi"
4+
5+
[bindings.swift]
6+
module_name = "ArkDrop"
7+
cdylib_name = "arkdrop_uniffi"
8+
ffi_module_name = "arkdrop_uniffiFFI"

0 commit comments

Comments
 (0)