Skip to content

Commit

Permalink
Merge pull request #9 from Concordium/dev
Browse files Browse the repository at this point in the history
SwiftPM: Add ability to use local framework
  • Loading branch information
bisgardo authored Mar 13, 2024
2 parents 4728950 + 8e33f7c commit f239f5e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Build-time environment variable `CONCORDIUM_WALLET_CRYPTO_FRAMEWORK_PATH`
for resolving the framework to a path instead of using the released one.

### Changed

- Rename crate from "crypto" to "concordium-wallet-crypto-uniffi"
Expand Down
27 changes: 24 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,37 @@ let package = Package(
),
],
targets: [
.binaryTarget(
name: "RustFramework",
overridableFrameworkTarget(
name: "ConcordiumWalletCryptoFramework",
url: "https://github.com/Concordium/concordium-wallet-crypto-swift/releases/download/build%2F1.0.0-1/RustFramework.xcframework.zip",
checksum: "edc2628d1721697b555891316dac3be1490072c1649d040fff8f3c160b2d0e09"
),
.target(
name: "ConcordiumWalletCrypto",
dependencies: [
.target(name: "RustFramework"),
.target(name: "ConcordiumWalletCryptoFramework"),
]
),
]
)

func overridableFrameworkTarget(name: String, url: String, checksum: String) -> Target {
if let p = providedFrameworkPath(), !p.isEmpty {
return .binaryTarget(name: name, path: p)
}
return .binaryTarget(name: name, url: url, checksum: checksum)
}

func providedFrameworkPath() -> String? {
if let p = getEnv("CONCORDIUM_WALLET_CRYPTO_FRAMEWORK_PATH") {
return p
}
if let _ = getEnv("CONCORDIUM_WALLET_CRYPTO_PATH") {
return "./generated/ConcordiumWalletCrypto.xcframework"
}
return nil
}

func getEnv(_ key: String) -> String? {
ProcessInfo.processInfo.environment[key]
}
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ In our [`Package.swift`](./Package.swift), the framework is referring to a GitHu

## Development

This repository is a Rust project with a SwiftPM package embedded into it.
### Swift package

This repository is a Rust project with an embedded SwiftPM package for using it from Swift.
The Swift bridge in `./Sources` is generated by UniFFI and must not be edited manually.

The package spec file `Package.swift` is only edited as part of publishing a release.
This is also the only time that the generated changes in `./Sources` are committed.

The environment variable `CONCORDIUM_WALLET_CRYPTO_FRAMEWORK_PATH`
may be used to select a locally compiled framework instead of the released one.
This allows one to use an unreleased version during development of the SDK.
Note that even when this is used from downstream projects,
the provided path is evaluated relative to the root of this project.

For convenience, if `CONCORDIUM_WALLET_CRYPTO_PATH` is set
(indicating that we're using a development version of this library)
then `CONCORDIUM_WALLET_CRYPTO_FRAMEWORK_PATH` will default to `./generated/ConcordiumWalletCrypto.xcframework`.
Provide the empty string to that variable to disable this behavior.

### Rust

The Rust source files are expected to be formatted according to `cargo fmt`.

The version in `Cargo.toml` is not updated during regular development.
Expand Down

0 comments on commit f239f5e

Please sign in to comment.