Skip to content

Commit

Permalink
Chore/swift uniffi (#74)
Browse files Browse the repository at this point in the history
* sacepoint

* savepoint

* savepoint

* savepoint

* savepoint

* savepoint

* savepoint

* savepoint

* savepoint

* update swift package generation

* update release workflow

* update script

* update

* update release workflow

* update comment

* update pods

* chore: update Package.swift and podspec for version 0.2.16

* chore: update Package.swift and podspec for version 0.2.17

* savepoint

* fix debug and release

* add cocoapods release

* chore: update Package.swift and podspec for version 0.2.18

* chore: update Package.swift and podspec for version 0.2.19

* fix podspec

* chore: update Package.swift and podspec for version 0.2.20

* update build script for ios 13

* update podspec

* chore: update Package.swift and podspec for version 02.21

* update workflow

* chore: update Package.swift and podspec for version 0.2.22

* lint

* add comment

* update ci

* comment out swift ci

* update

* add back swift tests to ci workflow

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
llbartekll and github-actions[bot] authored Dec 3, 2024
1 parent a6cc40b commit 6622a3e
Show file tree
Hide file tree
Showing 22 changed files with 5,170 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- run: rustup update stable && rustup default stable
- run: make build-ios-bindings
- run: make build-xcframework
- name: Select Xcode 15.4
run: sudo xcode-select -s /Applications/Xcode_15.4.app
- name: Build ${{ matrix.config }}
Expand Down
24 changes: 11 additions & 13 deletions .github/workflows/release-swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ jobs:
run: |
sudo xcode-select -s /Applications/Xcode_15.4.app
# 6. Build and Package Rust XCFramework
- name: Build and Package Rust XCFramework
# 6. Build and Package XCFramework
- name: Build and Package XCFramework
run: |
make build-ios-bindings-release
make zip-rust-xcframework
make compute-rust-checksum
make build-xcframework
make generate-package-swift
# 7. Update Podspec with Version and Download URL
Expand All @@ -68,10 +66,10 @@ jobs:
sed -i '' "s/^ s\.version *= *.*/ s.version = '${VERSION}'/g" YttriumWrapper.podspec
# Construct the download URL
DOWNLOAD_URL="https://github.com/reown-com/yttrium/releases/download/${VERSION}/RustXcframework.xcframework.zip"
DOWNLOAD_URL="https://github.com/reown-com/yttrium/releases/download/${VERSION}/libuniffi_yttrium.xcframework.zip"
# Replace the download URL in prepare_command
sed -i '' "s|curl -L -o RustXcframework.xcframework.zip '.*'|curl -L -o RustXcframework.xcframework.zip '${DOWNLOAD_URL}'|g" YttriumWrapper.podspec
sed -i '' "s|curl -L -o libuniffi_yttrium.xcframework.zip '.*'|curl -L -o libuniffi_yttrium.xcframework.zip '${DOWNLOAD_URL}'|g" YttriumWrapper.podspec
# 8. Commit and Push Package.swift and Podspec
- name: Commit and Push Package.swift and Podspec
Expand All @@ -80,7 +78,7 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Package.swift crates/ffi/YttriumCore/Sources/YttriumCore/* YttriumWrapper.podspec
git add Package.swift platforms/swift/Sources/Yttrium/* YttriumWrapper.podspec
if git diff --cached --quiet; then
echo "No changes to commit."
else
Expand Down Expand Up @@ -119,20 +117,20 @@ jobs:
draft: false
prerelease: true

# 11. Upload Rust XCFramework to the Release
- name: Upload Rust XCFramework to Release
# 11. Upload XCFramework to the Release
- name: Upload XCFramework to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./Output/RustXcframework.xcframework.zip
asset_name: RustXcframework.xcframework.zip
asset_path: ./Output/libuniffi_yttrium.xcframework.zip
asset_name: libuniffi_yttrium.xcframework.zip
asset_content_type: application/zip

# 12. Publish to CocoaPods Trunk
- name: Publish to CocoaPods Trunk
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
run: |
pod trunk push YttriumWrapper.podspec --allow-warnings
pod trunk push YttriumWrapper.podspec --allow-warnings
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ alloy = "0.6.1"
alloy-provider = "0.6.1"
erc6492 = { git = "https://github.com/reown-com/erc6492.git", branch = "main" }

# The values have been configured this way to prevent crashes in Swift debug builds with the default settings.
[profile.release]
opt-level = 'z'
debug = true
lto = true
opt-level = 0


codegen-units = 1
# panic = "abort"
# strip = true - it removes kotlin-bindings
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ build-ios-bindings:
build-ios-bindings-release:
sh crates/ffi/build-rust-ios-release.sh

build-xcframework:
sh scripts/build-xcframework.sh

set-up-local-swift-package:
sh scripts/set-up-local-package.sh

test:
cargo test --workspace

Expand All @@ -62,12 +68,6 @@ local-infra-forked:
local-infra-7702:
cd test/scripts/7702 && sh local-infra.sh

.PHONY: zip-rust-xcframework
zip-rust-xcframework:
mkdir -p Output
cd crates/ffi/YttriumCore/ && \
zip -r ../../../Output/RustXcframework.xcframework.zip \
RustXcframework.xcframework \

.PHONY: compute-rust-checksum
compute-rust-checksum:
Expand All @@ -76,8 +76,8 @@ compute-rust-checksum:

.PHONY: generate-package-swift
generate-package-swift:
chmod +x scripts/generate_package_swift.sh
./scripts/generate_package_swift.sh
chmod +x scripts/generate-package-swift.sh
./scripts/generate-package-swift.sh

.PHONY: build setup build-ios-bindings build-swift-apple-platforms test-swift-apple-platforms fetch-thirdparty setup-thirdparty test format clean local-infra local-infra-forked local-infra-7702

Expand Down
57 changes: 14 additions & 43 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,32 @@
import PackageDescription
import Foundation

let useLocalRustXcframework = ProcessInfo.processInfo.environment["USE_LOCAL_RUST_XCFRAMEWORK"] == "1"

let rustXcframeworkTarget: Target = useLocalRustXcframework ?
.binaryTarget(
name: "RustXcframework",
path: "crates/ffi/YttriumCore/RustXcframework.xcframework"
) :
.binaryTarget(
name: "RustXcframework",
url: "https://github.com/reown-com/yttrium/releases/download/0.2.13/RustXcframework.xcframework.zip",
checksum: "5abd6f384957e2016493d929cdef9b2a1e9aab6d2a9201e74e5477847b804313"
)

let package = Package(
name: "yttrium",
name: "Yttrium",
platforms: [
.macOS(.v14),
.iOS(.v13),
.watchOS(.v10),
.tvOS(.v17)
.iOS(.v13), .macOS(.v12)
],
products: [
.library(
name: "Yttrium",
targets: ["Yttrium"]
),
],
dependencies: [
.package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0")
],
targets: [
rustXcframeworkTarget,
.target(
name: "YttriumCore",
dependencies: [
"RustXcframework",
.product(name: "SwiftDotenv", package: "swift-dotenv")
],
path: "crates/ffi/YttriumCore/Sources/YttriumCore"
),
.target(
name: "Yttrium",
dependencies: [
"YttriumCore",
.product(name: "SwiftDotenv", package: "swift-dotenv")
],
path: "platforms/swift/Sources/Yttrium"
),
.testTarget(
name: "YttriumTests",
dependencies: [
"Yttrium",
.product(name: "SwiftDotenv", package: "swift-dotenv")
],
path: "platforms/swift/Tests/YttriumTests"
dependencies: ["YttriumXCFramework"],
path: "platforms/swift/Sources/Yttrium",
publicHeadersPath: ".",
cSettings: [
.headerSearchPath(".")
]
),
.binaryTarget(
name: "YttriumXCFramework",
url: "https://github.com/reown-com/yttrium/releases/download/0.2.22/libuniffi_yttrium.xcframework.zip",
checksum: "582c820d78325294160af8a359b106ef998a19c50ca400ae7ee181b28bede5bb"
)
]
)

14 changes: 7 additions & 7 deletions YttriumWrapper.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Pod::Spec.new do |s|
s.name = 'YttriumWrapper'
s.version = '0.2.13'
s.version = '0.2.22'
s.summary = '4337 implementation'
s.description = '4337 implementation '
s.description = '4337 implementation and Chain Abstraction'
s.homepage = 'https://reown.com'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.authors = 'reown inc.'
Expand All @@ -14,14 +14,14 @@ Pod::Spec.new do |s|
s.swift_version = '5.9'

# Include the Swift source files
s.source_files = 'crates/ffi/YttriumCore/Sources/YttriumCore/**/*.{swift,h}'
s.source_files = 'platforms/swift/Sources/Yttrium/**/*.{swift,h}'

# Include the vendored framework
s.prepare_command = <<-SCRIPT
curl -L -o RustXcframework.xcframework.zip 'https://github.com/reown-com/yttrium/releases/download/0.2.13/RustXcframework.xcframework.zip'
unzip -o RustXcframework.xcframework.zip -d crates/ffi/YttriumCore/
rm RustXcframework.xcframework.zip
curl -L -o libuniffi_yttrium.xcframework.zip 'https://github.com/reown-com/yttrium/releases/download/0.2.22/libuniffi_yttrium.xcframework.zip'
unzip -o libuniffi_yttrium.xcframework.zip -d platforms/swift/
rm libuniffi_yttrium.xcframework.zip
SCRIPT

s.vendored_frameworks = 'crates/ffi/YttriumCore/RustXcframework.xcframework'
s.vendored_frameworks = 'platforms/swift/target/ios/libuniffi_yttrium.xcframework'
end
3 changes: 0 additions & 3 deletions crates/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ license.workspace = true
[lib]
crate-type = ["staticlib"]

[build-dependencies]
swift-bridge-build = { git = "https://github.com/wooden-worm/swift-bridge.git", branch = "derive_debug_serde" }

[dependencies]
# See: https://github.com/kornelski/rust-security-framework/pull/204
# security-framework = "2.10.0"
Expand Down
22 changes: 11 additions & 11 deletions crates/ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::PathBuf;
//use std::path::PathBuf;

fn main() {
let out_dir = PathBuf::from("./generated");
println!("cargo:rerun-if-changed={}", out_dir.display());

let bridges = vec!["src/lib.rs"];
for path in &bridges {
println!("cargo:rerun-if-changed={}", path);
}

swift_bridge_build::parse_bridges(bridges)
.write_all_concatenated(out_dir, env!("CARGO_PKG_NAME"));
// let out_dir = PathBuf::from("./generated");
// println!("cargo:rerun-if-changed={}", out_dir.display());
//
// let bridges = vec!["src/lib.rs"];
// for path in &bridges {
// println!("cargo:rerun-if-changed={}", path);
// }
//
// swift_bridge_build::parse_bridges(bridges)
// .write_all_concatenated(out_dir, env!("CARGO_PKG_NAME"));
}
2 changes: 1 addition & 1 deletion crates/kotlin-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[lib]
name = "uniffi_yttrium"
crate-type = ["cdylib"]
crate-type = ["staticlib", "cdylib"]

[build-dependencies]
uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "e796e00ad150f8b14b61a859a2e8c6497b35074e" }
Expand Down
Loading

0 comments on commit 6622a3e

Please sign in to comment.