This is a Cargo command for building Swift packages.
This crate uses xcframework to build the binary framework, and then takes care of including swift API wrappers (see UniFFI for generating them) and creating a resource extension for the resources that are included for convenient access.
Using the generated swift package:
import SwiftMath
// SwiftMath.resources is generated by this extension.
let helloFile = SwiftMath.resources.appendingPathComponent("hello.txt")
let hello = try! String(contentsOf: helloFile)
print("from resource file: \(hello)")
// SwiftMath.swift_add(_,_) is a pre-generated binding provided to
// swift-package.
print("SwiftMath.swift_add(4 + 2) = \(SwiftMath.swift_add(4, 2))")
It uses the xcframework configuration
from the Cargo.toml's [package.metadata.xcframework]
table and has the following
own configuration options:
# All the xcframework options are available here
[package.metadata.xcframework]
include-dir = "include"
macOS = true
[package.metadata.swift-package]
# The name of the generated package
package-name = "SwiftMath"
# Bindings that are included.
swift-source-dir = "swift"
# 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"]