This new swift package
sub-command adds a way to programmatically insert new settings into a package manifest per target similarly to existing add-target
and add-{target}-dependency
commands.
Currently only a limited number of Swift settings is supported, namely: enable{Upcoming, Experimental}Feature
, languageMode
and strictMemorySafety
by passing --swift
option to the command; but the command could be expanded to support more Swift (C, C++, linker) settings in the future.
Interface
OVERVIEW: Add a new setting to the manifest
USAGE: swift package add-setting --target <target> --swift <swift> ...
OPTIONS:
--target <target> The target to add the setting to
--swift <swift> The Swift language setting(s) to add. Supported settings: experimentalFeature, upcomingFeature, languageMode, strictMemorySafety
--version Show the version.
-h, -help, --help Show help information.
Use case
swift package add-setting --target MyTarget --swift upcomingFeature=InferSendableFromCaptures --swift strictMemorySafety
which would add following swiftSettings
to MyTarget
:
.target(
name: "MyTarget",
...
swiftSettings: [
// ... existing settings,
.enableUpcomingFeature("InferSendableFromCaptures"),
.strictMemorySafety
]
)
Note that the command checks the tools-version of the manifest to avoid adding settings that won't be supported. For example, attempting to add strictMemorySafety
setting to 6.0.0
manifest would result in the following error:
error: package manifest version 6.0.0 is too old: please update to manifest version 6.2.0 or newer
Attempting to add a setting to a .plugin
target is going to result in an error as well since plugins don't support settings.
Impact on Interface
This introduces a new Package manifest editing command but does not interfere with existing commands. It follows the same pattern as add-target-dependency
, allowing users to add settings to .target(...)
, .macro(...)
and .testTarget(...)
in a consistent manner.
See SwiftPM PR for more details.