swift-package

Crates.ioswift-package
lib.rsswift-package
version0.1.0
sourcesrc
created_at2023-04-05 07:13:41.681789
updated_at2024-11-28 11:12:01.27128
descriptionCargo plugin and library for building Apple Swift Packages
homepage
repositoryhttps://github.com/human-solutions/swift-package
max_upload_size
id830810
size53,027
henrik (akesson)

documentation

README

⚠️ WARNING

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 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

Commit count: 19

cargo fmt