Adding support for generating library product schemes #2768
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Generating Library Product Schemes
This pull request adds a
swift package generate-xcodeproj
option--enable-library-schemes
that will allow creation of schemes for library products during the scheme generation step of generating an Xcode project.Motivation
I'm very excited to see binary dependency support was added to swift package manager! Once that is released, certain swift packages maintainers may want to start providing xcframework assets when they release their swift packages so that consumers can integrate with swift package manager's brand new feature.
This pull request aims to add more options to scheme generation while generating an Xcode project, so that it is easier to use
xcodebuild
to create xcframeworks from swift packages.Use Case
The following is a common CI workflow that I can see some package maintainers desiring for their package repos:
Build Trigger: Push a new release or beta Tag to a git repo
Build Steps:
swift package generate-xcodeproj
xcodebuild
to Archive your project using several destinations to get an archived framework for each apple SDK your Package supports.Example using iOS and watchOS + Simulators:
xcodebuild
to Combine the Frameworks from the previous step into an xcframeworkWhat's the Problem?
During scheme generation (in step 2 above), the current expected schemes generated are:
-Package
)Notice that there will be no schemes generated for library product targets.
This sounds reasonable at first glance, but it's a very common practice within the swift command line tooling community to split the source for your tool into multiples modules — pushing the majority of your code into one or several frameworks and then having a thin executable client that wraps your frameworks.
A few examples of tools that I believe do this are SwiftLint, Carthage, SwiftFormat, swift-format, and Publish.
Quoting John Sundell in his article about creating command line tools, there are good reasons for doing this:
The problem I'm hoping to fix arises during archiving (step 3 above). If you:
Expected Result: There should be a scheme that was created during Xcode project generation that will allow me to build the library products in preparation for creating an xcframework.
Actual Result: There will be no generated scheme that will build the library products in preparation for creating an xcframework. You have to manually create a scheme to use.
What Other Changeless Options Are There?
If a user tries to archive their executable or master scheme against iOS, watchOS, or tvOS, they receive the following expected errors:
-target
instead of-scheme
).I don't think this will work either. The man page for xcodebuild states that a scheme is requirement of archiving.
archive Archive a scheme from the build root (SYMROOT). This requires specifying a scheme.
Proposed Solution
I kept backwards compatibility in mind for this change, to ensure that we don't affect the way that scheme generator is currently handled.
Acceptance Criteria:
swift package generate-xcodeproj
produces the same exact schemes as it did before this change.swift package generate-xcodeproj --enable-library-schemes
will add additional schemes for any library products.--enable-library-schemes
option will also contain test targets.Alternative Solutions Considered
Enable Library Product scheme generation by default