Skip to content

ci: properly generate the swift bindnigs #14

ci: properly generate the swift bindnigs

ci: properly generate the swift bindnigs #14

name: ARK Drop Swift Bindings Release
on:
push:
paths:
- "drop-core/entities/**"
- "drop-core/exchanges/**"
- "drop-core/uniffi/**"
- ".github/workflows/arkdrop-swift-bindings-release.yml"
workflow_dispatch:
jobs:
build-and-publish:
runs-on: macos-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim,x86_64-apple-darwin,aarch64-apple-darwin
- name: Verify Rust targets
run: |
rustup target list --installed
echo "Verifying targets are installed..."
for target in aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim x86_64-apple-darwin aarch64-apple-darwin; do
if rustup target list --installed | grep -q "$target"; then
echo "✓ $target is installed"
else
echo "✗ $target is NOT installed"
rustup target add "$target"
fi
done
- uses: Swatinem/rust-cache@v2
with:
workspaces: drop-core/uniffi
- name: Install Xcode Command Line Tools
run: |
xcode-select --install 2>/dev/null || true
xcode-select -p
- name: Build Library (for binding generation)
working-directory: ./drop-core/uniffi
run: |
echo "Building debug library for Swift binding generation..."
cargo build --lib
echo "Verifying library was built..."
ls -lh target/debug/libarkdrop_uniffi.* || echo "Warning: Library not found"
- name: Generate Swift Bindings
working-directory: ./drop-core/uniffi/bindings/swift
run: |
chmod +x generate-bindings.sh
./generate-bindings.sh
env:
RUST_BACKTRACE: 1
- name: Verify Generated Bindings
working-directory: ./drop-core/uniffi/bindings/swift
run: |
echo "Checking generated files..."
ls -la
echo ""
echo "Required files check:"
for file in ArkDrop.swift arkdrop_uniffiFFI.h module.modulemap; do
if [ -f "$file" ]; then
echo "✓ $file exists"
echo " Size: $(wc -c < "$file") bytes"
else
echo "✗ $file missing!"
exit 1
fi
done
- name: Build XCFramework
working-directory: ./drop-core/uniffi/bindings/swift
run: |
chmod +x build-xcframework.sh
./build-xcframework.sh
env:
RUST_BACKTRACE: 1
- name: Create Swift Package Archive
working-directory: ./drop-core/uniffi/bindings/swift
run: |
echo "Creating distributable Swift package..."
# Create package directory structure
mkdir -p ArkDrop-Swift-Package
mkdir -p ArkDrop-Swift-Package/Sources/ArkDrop
# Verify all required files exist before copying
echo "Verifying files before packaging..."
for file in arkdrop_uniffiFFI.xcframework ArkDrop.swift Package.swift arkdrop_uniffiFFI.h module.modulemap; do
if [ ! -e "$file" ]; then
echo "ERROR: Required file missing: $file"
exit 1
fi
done
# Copy XCFramework
echo "Copying XCFramework..."
cp -r arkdrop_uniffiFFI.xcframework ArkDrop-Swift-Package/
# Copy Swift source to Sources directory
echo "Copying Swift bindings..."
cp ArkDrop.swift ArkDrop-Swift-Package/Sources/ArkDrop/
# Copy Package.swift
echo "Copying Package.swift..."
cp Package.swift ArkDrop-Swift-Package/
# Copy header and modulemap for reference
echo "Copying headers and modulemap..."
cp arkdrop_uniffiFFI.h ArkDrop-Swift-Package/
cp module.modulemap ArkDrop-Swift-Package/
# Create README with usage instructions
cat > ArkDrop-Swift-Package/README.md << 'EOF'
# ArkDrop Swift Bindings
This package contains Swift bindings for ARK Drop.
## Contents
- `arkdrop_uniffiFFI.xcframework` - Pre-built XCFramework for iOS and macOS
- `Sources/ArkDrop/ArkDrop.swift` - Swift bindings generated by UniFFI
- `Package.swift` - Swift Package Manager configuration
- `arkdrop_uniffiFFI.h` - C header file (reference)
- `module.modulemap` - Module map (reference)
## Installation
### Swift Package Manager
Add to your `Package.swift`:
```swift
dependencies: [
.package(path: "path/to/ArkDrop-Swift-Package")
]
```
Or add the extracted package directory to your Xcode project via:
File → Add Package Dependencies → Add Local...
## Usage
Import the module in your Swift code:
```swift
import ArkDrop
```
EOF
# List package contents
echo ""
echo "Package contents:"
find ArkDrop-Swift-Package -type f | sort
# Create a zip archive
echo ""
echo "Creating archive..."
zip -r ArkDrop-Swift-Package.zip ArkDrop-Swift-Package/
# Create checksum
echo "Creating checksum..."
shasum -a 256 ArkDrop-Swift-Package.zip > ArkDrop-Swift-Package.zip.sha256
echo ""
echo "Package created successfully!"
cat ArkDrop-Swift-Package.zip.sha256
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: swift-bindings
path: |
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip.sha256
retention-days: 30
- name: Create Release
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
uses: softprops/action-gh-release@v2
with:
tag_name: swift-bindings-${{ github.run_id }}
name: Swift Bindings Release ${{ github.run_id }}
draft: false
prerelease: false
files: |
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip
drop-core/uniffi/bindings/swift/ArkDrop-Swift-Package.zip.sha256
body: |
## Swift Bindings for ARK Drop
This release contains the Swift bindings for ARK Drop, including:
- XCFramework for iOS (device and simulator) and macOS
- Swift source files
- Swift Package Manager configuration
### Installation
#### Swift Package Manager
1. Download and extract `ArkDrop-Swift-Package.zip`
2. Add the package to your Xcode project or include it in your `Package.swift`:
```swift
dependencies: [
.package(path: "path/to/ArkDrop-Swift-Package")
]
```
#### Manual Installation
1. Download `ArkDrop-Swift-Package.zip`
2. Extract and add `arkdrop_uniffiFFI.xcframework` to your Xcode project
3. Add `drop.swift` to your project sources
### Verification
Verify the package integrity using the SHA256 checksum:
```bash
shasum -a 256 -c ArkDrop-Swift-Package.zip.sha256
```
Generated from commit: ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}