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 [
switch self {
case .myLib:
return [
.target(
name: "MyLib",
url: "https://github.com/example/mylib/releases/download/\(BuildShared.options!.releaseVersion)/myLib.xcframework.zip",
checksum: "https://github.com/example/mylib/releases/download/\(BuildShared.options!.releaseVersion)/myLib.xcframework.checksum.txt"
),
]
}
]
}
}
// 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 BuildRunner.performCommand()
let build = MyBuild(library: MyLibrary.myLib, options: options)
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 (e.g.,1.2.3).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 enable-debug