Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cargo-swift with equivalent script #15

Merged
merged 7 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/build+test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ jobs:
- name: Setup Rust
run: |
rustup default "${{env.rust_version}}"
rustup target install aarch64-apple-darwin x86_64-apple-darwin
cargo install cargo-swift
rustup target install aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-darwin x86_64-apple-ios
- name: Check out sources
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build rust bindings (macOS only)
run: cargo swift package --name=ConcordiumWalletCrypto --platforms=macos --release
- name: Build rust bindings
run: ./build.sh
working-directory: ./lib/crypto
- name: Check formatting
run: swift package plugin --allow-writing-to-package-directory swiftformat --lint
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ This SDK includes a thin wrapper for providing bindings to the Rust library
[`wallet_library`](https://github.com/Concordium/concordium-base/tree/main/rust-src/wallet_library)
which exposes functions specifically relevant for wallets.

These bindings are located in `./lib/crypto` and built using [`cargo-swift`](https://github.com/antoniusnaumann/cargo-swift/)
into a [XCFramework](https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages).
These bindings are located in `./lib/crypto` and compiled into an
[XCFramework](https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages).
The SDK pulls in this framework from a local path, so the bindings have to built manually before the SDK can be used.

Building is only a matter of installing `cargo-swift` and invoking a Make target:
Building is only a matter of invoking the Make target

```shell
cargo install cargo-swift
make build-crypto
```

This will place the target framework at `./lib/crypto/ConcordiumWalletCrypto`.
This will place the target framework in `./lib/crypto/ConcordiumWalletCrypto`.

### Build and test SDK

Expand Down
1 change: 0 additions & 1 deletion lib/crypto/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/target
/generated
/ConcordiumWalletCrypto
113 changes: 113 additions & 0 deletions lib/crypto/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions lib/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ crate-type = ["staticlib", "lib"]
name = "crypto"

[dependencies]
thiserror = "1.0.56"
uniffi = "0.25"
thiserror = "1"
uniffi = { version = "0.25", features = ["cli"] }
wallet_library = { path = "./concordium-base/rust-src/wallet_library" }

[build-dependencies]
uniffi = { version = "0.25", features = ["build"] }

[[bin]]
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"
3 changes: 3 additions & 0 deletions lib/crypto/ConcordiumWalletCrypto/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!*ignore
!/Package.swift
29 changes: 29 additions & 0 deletions lib/crypto/ConcordiumWalletCrypto/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version:5.6

import PackageDescription

let package = Package(
name: "ConcordiumWalletCrypto",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
],
products: [
.library(
name: "ConcordiumWalletCrypto",
targets: ["ConcordiumWalletCrypto"]
),
],
targets: [
.binaryTarget(
name: "RustFramework",
path: "./RustFramework.xcframework"
),
.target(
name: "ConcordiumWalletCrypto",
dependencies: [
.target(name: "RustFramework"),
]
),
]
)
36 changes: 34 additions & 2 deletions lib/crypto/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,37 @@

set -eux

rm -rf ./ConcordiumWalletCrypto/
cargo swift package --name=ConcordiumWalletCrypto --platforms=ios --platforms=macos --release
# Generate bindings/bridge code.
mkdir -p ./ConcordiumWalletCrypto/Sources/ConcordiumWalletCrypto
cargo run --bin uniffi-bindgen generate src/lib.udl --language=swift --out-dir=./generated
cp ./generated/crypto.swift ./ConcordiumWalletCrypto/Sources/ConcordiumWalletCrypto/crypto.swift
mv ./generated/cryptoFFI.modulemap ./generated/module.modulemap

# Compile for Darwin (macOS) as universal binary.
cargo build --target=x86_64-apple-darwin --release
cargo build --target=aarch64-apple-darwin --release
lipo \
./target/x86_64-apple-darwin/release/libcrypto.a \
./target/aarch64-apple-darwin/release/libcrypto.a \
-create -output=./target/universal-macos/release/libcrypto.a

# Compile for iOS.
cargo build --target=aarch64-apple-ios --release

# Compile for iOS Simulator as universal binary.
cargo build --target=x86_64-apple-ios --release
cargo build --target=aarch64-apple-ios-sim --release
lipo \
./target/x86_64-apple-ios/release/libcrypto.a \
./target/aarch64-apple-ios-sim/release/libcrypto.a \
-create -output=./target/universal-ios/release/libcrypto.a

# Build binary framework.
xcodebuild -create-xcframework \
-library=./target/aarch64-apple-ios/release/libcrypto.a -headers=./generated \
-library=./target/universal-ios/release/libcrypto.a -headers=./generated \
-library=./target/universal-macos/release/libcrypto.a -headers=./generated \
-output=./ConcordiumWalletCrypto/RustFramework.xcframework

# Clean up.
rm -rf ./generated
3 changes: 3 additions & 0 deletions lib/crypto/uniffi-bindgen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}
Loading