16.8 · Conditional settings, platform minimums, language modes, traits and plugins

The manifest is Swift code that builds a Package value, and most day-to-day trouble comes from what you can put in it: which settings reach which target, which platform floor a dependency forces, and how optional features and code generation are declared.

Mental model. Settings are per target, conditions pick the configuration, platform or trait they apply to, and anything that runs code at build time is a plugin with an explicit sandbox.

Settings that reach the compiler

Defines, platform floors and language modes.

  1. How do swiftSettings and their .when conditions work in a package, and which targets do they reach? 16.8.1 · L3
    Each target has its own swiftSettings (and cSettings, linkerSettings), and a setting can carry a condition: .when(configuration: .debug) or .release…
  2. What does the platforms: array in Package.swift mean, and why can a dependency stop your build? 16.8.2 · L3
    platforms: [.macOS(.v13), .iOS(.v16)] declares the minimum deployment version this package supports on each platform. A platform you do not list gets a default…
  3. How do per-target Swift language modes let a package migrate to Swift 6 one module at a time? 16.8.3 · L5
    The tools version fixes the default language mode for the package (tools 6.0 means Swift 6 mode, which turns data-race safety into errors), but each target can…

Optional features and build-time code

Traits and the two plugin kinds.

  1. What are package traits, and how do they differ from build configurations or separate packages for optional features? 16.8.4 · L5
    Traits (SE-0450, tools 6.1) let a package declare optional features that a consumer turns on: traits: [.trait(name: "Logging"), .default(enabledTraits: [])]…
  2. What is a build tool plugin, how does it generate code, and what does it replace? 16.8.5 · L5
    A build tool plugin runs as part of the build and produces files for a target: the target lists it in plugins: ["GenPlugin"], the plugin (a Swift file in…
  3. What is a command plugin, what can it touch, and what does the permission model look like? 16.8.6 · L5
    A command plugin is a package-provided command you run on demand: swift package <verb> (or Xcode’s context menu on a package). It conforms to CommandPlugin…

More in Modularization & SPM