#swift #packages #cargo #building #cargo-subcommand #framework #generated

bin+lib swift-package

Cargo plugin and library for building Apple Swift Packages

2 releases

0.1.0 Nov 28, 2024
0.1.0-alpha.0 Apr 5, 2023

#255 in Cargo plugins

MIT license

23KB
504 lines

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

Dependencies

~8–16MB
~208K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy