Define and manage your Xcode Build Phases from inside Package.swift


A Swift Package that allows you to define your Xcode Build Phases from the Package.swift manifest.


Define your build phases at the very bottom of your Package.swift like this.

#if canImport(PhaseConfig)
import PhaseConfig

PhaseConfig(phases: [
        name: "Swift Lint", 
        script: "swiftlint", // actual bash script that will be added to xcodeproj build phase
        targets: ["SomeTarget", "AnotherTarget"] // targets on which to apply
        name: "Generate code",
        script: "sourcery",
        targets: ["OneMoreTarget"]
        name: "xcode", // a phase to easily generate and inject phases in freshly made xcode project
        script: "swift run package-config;swift package generate-xcodeproj;swift run phase install --verbose",
        targets: [] // wont be installed on any targets, can be triggered via bash as "swift run phase run xcode"

Whenever you need your Build Phases injected into xcodeproj run this from directory with your Package.swift.

swift run phase install

Whenever you wish to execute your phase from command line within the project directory with Package.swift.

swift run phase run yourPhaseName

Also consider that you probably don't need to have Xcode to be in your repository so you can add this line /*.xcodeproj to your .gitignore, and whenever you need your Xcode project just run swift package generate-xcodeproj and then you can inject Build Phases into your Xcode project using phase.


Add dependency to dependencies in your project Package.swift

dependencies: [
    .package(url: "", from: "0.0.5"),  

Add target PackageConfigs to your targets and list the PhaseConfig there:

.target(name: "PackageConfigs", dependencies: [

To make sure you can run phase run this in your project directory with Package.swift.

swift run package-config # builds PackageConfigs dependencies


  • Swift Tools
View More Packages from this Author


  • None
Last updated: Tue Mar 14 2023 11:00:39 GMT-0500 (GMT-05:00)