Crates.io | swift-package |
lib.rs | swift-package |
version | 0.1.0 |
source | src |
created_at | 2023-04-05 07:13:41.681789 |
updated_at | 2024-11-28 11:12:01.27128 |
description | Cargo plugin and library for building Apple Swift Packages |
homepage | |
repository | https://github.com/human-solutions/swift-package |
max_upload_size | |
id | 830810 |
size | 53,027 |
⚠️ WARNING
This has not yet been thoroughly tested. Use at your own risk.
This is a Cargo command for building Swift packages.
This crate uses uniffi to generate swift bindings and xcframework to build the binary framework, and then wraps it up in a Swift package together with any resources and a resource accessor.
See the end-to-end example for how to set it up.
Using the generated swift package:
import Foundation
import SwiftMath
@main
public struct swift_cmd {
public static func main() {
// the SwiftMath.resources(name:) func is generated by swift-package.
let helloFile = SwiftMath.resources(name: "hello.txt")
let hello = try! String(contentsOf: helloFile)
let sum = SwiftMath.rustAdd(a: 4, b: 2)
print(
"SwiftMath.swift_add(4 + 2) = \(sum); from resource file: \(hello)"
)
}
}
It uses the xcframework configuration
options except the include-dir
one plus it's own configuration options:
[package.metadata.swift-package]
# Any options that are valid for the xcframework command line utility
# can be set here. The options are passed to the xcframework command.
macOS = true
#### swift-package specific options ####
# The name of the generated package
package-name = "SwiftMath"
# Any resource directories. The files will be included
# in the swift package and a convenience accessor extesion
# of the same name as the dir is created
resource-dirs = ["resources"]
Another alternative is cargo-swift