> <span style="color:darkorange">**⚠️ WARNING**</span>
>
> This has not yet been thoroughly tested. Use at your own risk.
# swift-package
This is a Cargo command for building Swift packages.
This crate uses [uniffi](https://mozilla.github.io/uniffi-rs/latest/) to generate swift bindings
and [xcframework](https://crates.io/crates/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:
```swift
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](https://crates.io/crates/xcframework#configuration)
options except the `include-dir` one plus it's own configuration options:
```toml
[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](https://crates.io/crates/cargo-swift)