Skip to content

A cargo subcommand for creating Swift packages from a Rust library

License

Notifications You must be signed in to change notification settings

human-solutions/swift-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swift-package

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

About

A cargo subcommand for creating Swift packages from a Rust library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages