-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(xcframework): generate xcframework
- Loading branch information
1 parent
dfe0f88
commit 545959e
Showing
5 changed files
with
259 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Build and Release Yttrium | ||
|
||
on: | ||
# workflow_dispatch: | ||
# inputs: | ||
# version: | ||
# description: 'Version number for the release (e.g., 0.1.0)' | ||
# required: true | ||
push: | ||
branches: | ||
- 'jack/xcframework' | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
SKIP_RELEASE: true | ||
TARGET_BRANCH: ${{ github.head_ref }} # ${{ github.head_ref || 'main' }} | ||
|
||
jobs: | ||
release-swift-package: | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
config: | ||
- debug | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run sccache-cache | ||
uses: mozilla-actions/[email protected] | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
- name: Build and Package Rust XCFramework | ||
env: | ||
GITHUB_VERSION: ${{ github.event.inputs.version }} | ||
run: | | ||
rustup update stable && rustup default stable | ||
git submodule update --init --recursive | ||
make setup-thirdparty | ||
make build-ios-bindings-release | ||
make zip-rust-xcframework | ||
make compute-rust-checksum | ||
make generate-package-swift | ||
- name: Commit and Push Package.swift | ||
if: ${{ env.SKIP_RELEASE != 'true' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
git checkout ${{ env.TARGET_BRANCH }} | ||
git add Package.swift | ||
git commit -m "chore: update package.swift for version ${{ github.event.inputs.version }}" | ||
git push origin HEAD:${{ env.TARGET_BRANCH }} | ||
- name: Create Release | ||
if: ${{ env.SKIP_RELEASE != 'true' }} | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} | ||
with: | ||
tag_name: ${{ github.event.inputs.version }}-test | ||
release_name: Yttrium ${{ github.event.inputs.version }}-test | ||
draft: false | ||
prerelease: true | ||
|
||
- name: Upload Rust XCFramework to Release | ||
if: ${{ env.SKIP_RELEASE != 'true' }} | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./Output/RustXcframework.xcframework.zip | ||
asset_name: RustXcframework.xcframework.zip | ||
asset_content_type: application/zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# build-rust-ios.sh | ||
|
||
#!/bin/bash | ||
|
||
PACKAGE_NAME=ffi | ||
SWIFT_PACKAGE_NAME=YttriumCore | ||
|
||
set -e | ||
|
||
THISDIR=$(dirname $0) | ||
cd $THISDIR | ||
|
||
echo "Building for iOS..." | ||
|
||
rustup target add aarch64-apple-ios | ||
rustup target add x86_64-apple-ios | ||
rustup target add aarch64-apple-ios-sim | ||
|
||
cargo build --release --target aarch64-apple-ios | ||
cargo build --release --target x86_64-apple-ios | ||
cargo build --release --target aarch64-apple-ios-sim | ||
|
||
mkdir -p ./../../target/universal-ios/release | ||
|
||
echo "Lipoing for iOS..." | ||
|
||
lipo \ | ||
./../../target/aarch64-apple-ios-sim/release/lib$PACKAGE_NAME.a \ | ||
./../../target/x86_64-apple-ios/release/lib$PACKAGE_NAME.a -create -output \ | ||
./../../target/universal-ios/release/lib$PACKAGE_NAME.a | ||
|
||
function create_package { | ||
cargo install -f swift-bridge-cli | ||
swift-bridge-cli create-package \ | ||
--bridges-dir ./generated \ | ||
--out-dir $SWIFT_PACKAGE_NAME \ | ||
--ios ./../../target/aarch64-apple-ios/release/lib$PACKAGE_NAME.a \ | ||
--simulator ./../../target/universal-ios/release/lib$PACKAGE_NAME.a \ | ||
--name $SWIFT_PACKAGE_NAME | ||
} | ||
|
||
# Check if Package.swift file exists | ||
if [ -f $SWIFT_PACKAGE_NAME/Package.swift ]; then | ||
echo "Package.swift already exists. Copying existing file to backup..." | ||
rm -f $SWIFT_PACKAGE_NAME/Package.swift.bak | ||
cp $SWIFT_PACKAGE_NAME/Package.swift $SWIFT_PACKAGE_NAME/Package.swift.bak | ||
echo "Creating Swift package..." | ||
create_package | ||
cp $SWIFT_PACKAGE_NAME/Package.swift.bak $SWIFT_PACKAGE_NAME/Package.swift | ||
rm -f $SWIFT_PACKAGE_NAME/Package.swift.bak | ||
else | ||
echo "Creating Swift package..." | ||
create_package | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Variables | ||
# PACKAGE_VERSION="${GITHUB_VERSION:-0.0.1-alpha}" | ||
PACKAGE_VERSION="${GITHUB_VERSION:-0.0.1-alpha}-test" | ||
RUST_CHECKSUM=$(cat rust_checksum.txt) | ||
RUST_XCFRAMEWORK_ZIP="RustXcframework.xcframework.zip" | ||
REPO_URL="https://github.com/WalletConnect/yttrium" | ||
|
||
# Generate Package.swift | ||
cat > Package.swift <<EOF | ||
// swift-tools-version: 5.10 | ||
import PackageDescription | ||
import Foundation | ||
let isDevelopment = ProcessInfo.processInfo.environment["YTTRIUM_DEVELOPMENT"] == "false" | ||
let rustBinaryTarget: Target = { | ||
guard isDevelopment else { | ||
return .binaryTarget( | ||
name: "RustXcframework", | ||
url: "$REPO_URL/releases/download/$PACKAGE_VERSION/$RUST_XCFRAMEWORK_ZIP", | ||
checksum: "$RUST_CHECKSUM" | ||
), | ||
} | ||
return .binaryTarget( | ||
name: "RustXcframework", | ||
path: "crates/ffi/YttriumCore/RustXcframework.xcframework" | ||
) | ||
}() | ||
let package = Package( | ||
name: "yttrium", | ||
platforms: [ | ||
.macOS(.v14), | ||
.iOS(.v13), | ||
.watchOS(.v10), | ||
.tvOS(.v17) | ||
], | ||
products: [ | ||
.library( | ||
name: "Yttrium", | ||
targets: ["Yttrium"] | ||
), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0") | ||
], | ||
targets: [ | ||
.target( | ||
name: "Yttrium", | ||
dependencies: [ | ||
"YttriumCore", | ||
.product(name: "SwiftDotenv", package: "swift-dotenv") | ||
], | ||
path: "platforms/swift/Sources/Yttrium" | ||
), | ||
.target( | ||
name: "YttriumCore", | ||
dependencies: [ | ||
"RustXcframework" | ||
], | ||
path: "crates/ffi/YttriumCore/Sources/YttriumCore" | ||
), | ||
rustBinaryTarget, | ||
.testTarget( | ||
name: "YttriumTests", | ||
dependencies: [ | ||
"Yttrium" , | ||
.product(name: "SwiftDotenv", package: "swift-dotenv") | ||
], | ||
path: "platforms/swift/Tests/YttriumTests" | ||
), | ||
] | ||
) | ||
EOF | ||
|
||
echo "Package.swift generated with Rust XCFramework checksum: $RUST_CHECKSUM" |