Skip to content

Commit

Permalink
Make Sargon build, preparing for iOS example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Feb 14, 2024
1 parent 51db6a3 commit 0269a74
Show file tree
Hide file tree
Showing 12 changed files with 10,520 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
tarpaulin-report.html
.vscode
.idea
.build
build_rs_cov.profraw
cobertura.xml
jna-*.jar
23 changes: 23 additions & 0 deletions BuildProcess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swift

## Build script
Ah nevermind the build script in [uniffi-starter/../build-ios.sh](https://github.com/ianthetechie/uniffi-starter/blob/main/rust/build-ios.sh) already contained code to update checksum.

[Blog post about automating checksum update in Package.swift](https://blog.eidinger.info/distribute-binary-frameworks-in-swift-packages-and-how-to-automate-the-process) and here is a [Github Gist which looks nice](https://gist.github.com/litoarias/23bca22bb6161625484b4fb8cd245fe8)

This would allow for us to use a similar pattern like [`ferrostar`'s `Package.swift`](https://github.com/stadiamaps/ferrostar/blob/main/Package.swift) which has a nice `useLocalFramework` setup, and when NOT local uses SPM's setup:

```swift
let releaseTag = "0.1.0"
let releaseChecksum = "deadbeefdeadbeef..."
.binaryTarget(
name: "SargonCoreRS",
url: "https://github.com/radixdlt/sargon/releases/download/\(releaseTag)/libsargon-rs.xcframework.zip",
checksum: releaseChecksum
)
```

The advantage of this over what we are [doing today in Swift-Engine-Toolkit](https://github.com/radixdlt/swift-engine-toolkit/blob/main/Package.swift#L23C3-L23C78) is that the .xcframework files need not be part of Git! They can be put in Github! This will allow for much much faster git clone!

# Android
[See `uniffi-starter`](https://github.com/ianthetechie/uniffi-starter) (also contains Swift, but `@IanTheTech` has also created `ferrostar` which contains more advanced Swift setup).
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ name = "uniffi"
[lib]
crate-type = ["staticlib", "cdylib", "lib"]

[[bin]]
name = "uniffi-bindgen"
path = "src/bin.rs"

[dependencies]
log = "0.4.20"
pretty_env_logger = "0.5.0"
Expand Down
52 changes: 52 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let sargonBinaryTargetName = "SargonCoreRS"
let binaryTarget: Target
let useLocalFramework = true

if useLocalFramework {
binaryTarget = .binaryTarget(
name: sargonBinaryTargetName,
// IMPORTANT: Swift packages importing this locally will not be able to
// import SargonCore unless you specify this as a relative path!
path: "./target/ios/libsargon-rs.xcframework"
)
} else {
let releaseTag = "0.1.0"
let releaseChecksum = "4716b9370ed6cc848c2ae7435f7daeeb0528647b4e23ffd843e1ef6381c7b2c6"
binaryTarget = .binaryTarget(
name: sargonBinaryTargetName,
url:
"https://github.com/radixdlt/sargon/releases/download/\(releaseTag)/libsargon-rs.xcframework.zip",
checksum: releaseChecksum
)
}

let package = Package(
name: "Sargon",
platforms: [
.iOS(.v15)
],
products: [
.library(
name: "Sargon",
targets: ["Sargon"]
)
],
targets: [
binaryTarget,
.target(
name: "SargonUniFFI",
dependencies: [.target(name: sargonBinaryTargetName)],
path: "apple/Sources/UniFFI"
),
.target(
name: "Sargon",
dependencies: [.target(name: "SargonUniFFI")],
path: "apple/Sources/Sargon"
),
]
)
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,27 @@ cargo tarpaulin --out Html
```sh
cargo nextest run
```
```
# Build
## CD
See [`.github/workflows/release.yml`](.github/workflows/release.yml)
## Local
### iOS
#### Prerequisites
##### Rust targetse
```sh
rustup target add x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
```
##### `jq`
[_`jq` is a lightweight and flexible command-line JSON processor._](https://jqlang.github.io/jq/)
Used in build script
```sh
brew install jq
```
We build using [`scripts/build-ios.sh`](scripts/build-ios.sh)
6 changes: 5 additions & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[files]
extend-exclude = ["tarpaulin-report.html", "tests/vectors/fixtures/*.json"]
extend-exclude = [
"apple/Sources/UniFFI/Sargon.swift",
"tarpaulin-report.html",
"tests/vectors/fixtures/*.json",
]
1 change: 1 addition & 0 deletions apple/Sources/Sargon/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@_exported import SargonUniFFI
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension Decimal192: Comparable {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
extension Decimal192: Sendable {}
extension Decimal192: ExpressibleByStringLiteral,
ExpressibleByFloatLiteral
{}
extension Decimal192: SignedNumeric /* Numeric, ExpressibleByIntegerLiteral AdditiveArithmetic */
{}
*/
Loading

0 comments on commit 0269a74

Please sign in to comment.