Swift Package Extension Workflow
Purpose
Own SwiftPM extension work that does not belong in ordinary package build/run or testing workflows. Keep package plugins, macros, traits, generated-source policy, permission review, and toolchain comparison in one package-first path, then hand off when Xcode-managed project context becomes authoritative.
When To Use
- Use this skill for build tool plugins, command plugins, plugin products, target plugin usage, and plugin commands.
- Use this skill for macro targets, macro declaration/implementation boundaries, expansion inspection, diagnostics, and macro tests.
- Use this skill for package traits, default traits, optional dependencies, conditional compilation, and trait-aware build/test matrices.
- Use this skill for generated sources, generated build products, plugin sandboxing, write access, or network permissions.
- Use this skill when the Swiftly-selected toolchain and Xcode-selected toolchain may differ.
- Recommend
swift-package-build-run-workflowfor ordinary manifests, dependencies, resources, builds, and executable runs. - Recommend
swift-package-testing-workflowwhen ordinary test organization or failure diagnosis is primary. - Recommend
format-swift-sourcesfor formatter-specific plugin operation after this skill establishes plugin permissions and ownership. - Recommend
xcode-build-run-workfloworxcode-testing-workflowwhen schemes, destinations, app hosts, Xcode project context, or Xcode-only evidence controls the result. - Recommend
explore-apple-swift-docswhen the task is documentation lookup rather than package mutation or execution.
Single-Path Workflow
- Inspect
Package.swift,Plugins/, macro targets, generated outputs, test targets, and any Xcode project or workspace markers. - Establish both toolchain identities before planning commands:
- Swiftly path:
swiftly use --print-location,swift --version, and relevantswift package,swift build, orswift testhelp. - Xcode path:
xcode-select -p,xcrun --find swift,xcrun swift --version, and matchingxcrun swift package, build, or test help. - If Swiftly is set to
xcode, record that bridge explicitly instead of presenting the two command paths as independent compiler distributions. - Do not assume the two toolchains expose identical SwiftPM commands, flags, manifest APIs, macro support, or plugin behavior.
- Swiftly path:
- Read the relevant official SwiftPM, Swift Evolution, or Apple/Xcode documentation and state the behavior relied on before editing.
- Classify the primary extension concern as
build-tool-plugin,command-plugin,macro,traits, orgenerated-source. - Run the managed FSX planner through the owning repository recipe for nearest-package resolution and a non-mutating command plan.
- Load only the reference needed for the selected concern:
- plugins:
references/package-plugins-build-command-and-xcode.md - permissions:
references/plugin-permissions-sandbox-and-outputs.md - macros:
references/swift-macros-package-shape.md - traits:
references/package-traits-feature-flags.md - generated files:
references/generated-source-and-build-products.md
- plugins:
- Use
references/cli-command-matrix.mdto keep Swiftly and Xcode commands distinct. - Use Xcode only when the requested operation changes an Xcode scheme, target, build phase, preview, or other Xcode-owned state; co-located Xcode files never change package routing.
- Validate the smallest relevant matrix first, then the supported Swift minor window and both host toolchains when the package claims both.
- Report the manifest/API floor, selected toolchain, commands run, generated or permission-sensitive outputs, and any handoff.
Inputs
extension_type:build-tool-plugin,command-plugin,macro,traits, orgenerated-source.request: optional natural-language request used to inferextension_type.repo_root: package path; defaults to the current directory.toolchain_scope:swiftly,xcode, orboth; defaults tobothfor Apple ecosystem compatibility work.
Outputs
status:success,handoff, orblocked.path_type:primaryorfallback.output: extension type, package context, toolchain scope, planned commands, evidence requirements, and one next step.
Guards and Stop Conditions
- Stop when the package root or
Package.swiftcannot be resolved. - Stop before raising the tools-version or manifest API floor without confirming the package support window.
- Keep beta or snapshot toolchain evidence separate from the latest-stable-plus-previous-stable support promise.
- Do not treat
swift --versionas evidence for the Xcode toolchain; inspectxcrun swift --versionseparately. - Do not disable the plugin sandbox as a routine workaround. Name the required capability and grant the narrowest permission.
- Do not let build tool plugins modify package sources; generate into plugin-controlled build output locations.
- Do not check in derived output merely to hide a nondeterministic generator.
- Do not use traits to remove API when enabled; design traits as additive feature choices.
- Stop with a handoff when Xcode project context, scheme/destination state, app-hosted execution, or project membership determines correctness.
Fallbacks and Handoffs
- Fall back to a command plan when execution would mutate the package or request permissions the user did not authorize.
- Hand ordinary package execution to
swift-package-build-run-workflowafter extension shape and flags are settled. - Hand ordinary test diagnosis to
swift-package-testing-workflow; retain ownership of macro/plugin test shape and trait matrices. - Hand Xcode-managed builds to
xcode-build-run-workflowand Xcode-native tests toxcode-testing-workflowwith the exact package, plugin, macro, trait, scheme, and destination context. - Use
format-swift-sourcesfor formatter-specific behavior without duplicating the general plugin permission model.
Fixed Policy
- The workflow currently keeps fixed package-first and least-permission defaults.
References
Workflow References
references/package-plugins-build-command-and-xcode.mdreferences/plugin-permissions-sandbox-and-outputs.mdreferences/swift-macros-package-shape.mdreferences/package-traits-feature-flags.mdreferences/generated-source-and-build-products.mdreferences/cli-command-matrix.md
Contract References
Support References
- Recommend
references/snippets/apple-swift-package-core.mdwhen reusable package policy is needed in an end-user repo. references/snippets/apple-swift-package-core.md
Script Inventory
scripts/run-workflow.fsx