A shared Swift Package for building libraries across multiple Apple platforms (iOS, macOS, tvOS, visionOS).
- Add
BuildSharedas a dependency in yourPackage.swift.
dependencies: [
.package(url: "https://github.com/mpvkit/BuildShared.git", from: "1.0.0")
],
targets: [
.target(
name: "MyLibraryBuild",
dependencies: ["BuildShared"]),
]- Create a
main.swift(or your build script entry point) and define your library by conforming toBuildLibrary.
import BuildShared
// 1. Define your library
enum MyLibrary: String, BuildLibrary {
case myLib
var version: String {
switch self {
case .myLib:
return "v1.2.3"
}
}
var url: String {
switch self {
case .myLib:
return "https://github.com/example/mylib.git"
}
}
var targets: [PackageTarget] {
return []
}
}
// 2. Define your build class inheriting from BaseBuild (Non-generic)
class MyBuild: BaseBuild {
override func flagsDependencelibrarys() -> [any BuildLibrary] {
// Return dependencies if any
return []
}
// Override other methods to customize build process (configure, arguments, etc.)
}
// 3. Execute the build
do {
let options = try ArgumentOptions.parse(Array(CommandLine.arguments))
try BuildRunner.performCommand(options)
let build = MyBuild(library: MyLibrary.myLib)
try build.buildALL()
} catch {
print("Build failed: \(error)")
exit(1)
}enable-debug: Enable debug mode.enable-gpl: Enable GPL features.enable-split-platform: Generate split platform xcframeworks.version=<version>: Set release version.platform=<platform>: Specify target platforms (comma separated).- Values:
ios,macos,tvos,xros(visionOS).
- Values:
Example:
swift run MyLibraryBuild platform=ios,macos version=1.2.3