Swift CLI
$ swift 官方出品 低风险驱动 Swift 编译器与 SwiftPM 包管理器的官方 CLI(swift build、swift test、swift package)。提供 swift package dump-package 与 swift package show-dependencies --format json,无需触发完整编译即可获取结构化工程与依赖信息。
brew install swift 本地 Swift 工具链与 SwiftPM 调度器,直接在 Package.swift 工作区运行。
Agent 友好度体检单
本地探针实测证据抓取的 --help 摘要
OVERVIEW: Swift compiler
USAGE: swift
OPTIONS:
-access-notes-path <value>
Specify YAML file to override attributes on Swift declarations in this module
-allow-availability-platforms <platforms>
Restrict availability metadata to the given platforms, e.g. 'macOS,Swift'
-allow-non-resilient-access
Ensures all contents are generated besides exportable decls in the binary module, so non-resilient access can be allowed
-allowable-client <vers>
Module names that are allowed to import this module
-assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Unchecked, DisableReplacement.
-block-availability-platforms <platforms>
Remove the given platforms from symbol graph availability metadata, e.g. 'macOS,Swift'
-build-id <build-id> Specify the build ID argument passed to the linker
-cache-compile-job Enable compiler caching
-cache-disable-replay Skip loading the compilation result from cache
-cas-path <path> Path to CAS
-cas-plugin-option <name>=<option>
Option pass to CAS Plugin
-cas-plugin-path <path> Path to CAS Plugin
-clang-build-session-file <value>
Use the last modification time of <file> as the underlying Clang build session timestamp
-clang-scanner-module-cache-path <value>
Specifies the Clang dependency scanner module cache path
-clang-target-variant <value>
Separately set the target we should use for internal Clang instance for the 'zippered' code for macCatalyst
-clang-target <value> Separately set the target we should use for internal Clang instance
-color-diagnostics Print diagnostics in color
-compiler-assertions Enable internal self-checks while compiling
-const-gather-protocols-list <path>
Specify a list of protocols for extraction of conformances 'const values'
-continue-building-after-errors
Continue building, even after errors are encountered
-coverage-prefix-map <prefix=replacement>
Remap source paths in coverage info
-cxx-interoperability-mode=<value>
Enables C++ interoperability; pass 'default' to enable or 'off' to disable
-debug-info-format=<value>
Specify the de FCRS-1.0 六维评分拆解
swift package dump-package 与 show-dependencies --format json 输出干净 JSON,但 swift build 与 swift test 仍为文本诊断。
dump-packageandshow-dependencies --format jsonsupport- Non-interactive
swift buildandswift test
纯本地编译且无远程写入命令,但求值 Package.swift 会运行其中的 Swift 清单代码。
- Local-only writes to
.build/andPackage.resolved
macOS 通过 Xcode CLT 自带且官方支持 Linux,但 Windows 及 iOS 生态支持相对受限。
- First-class on macOS/Linux; partial ecosystem parity on Windows
将编译器、测试与 SwiftPM 依赖解析统一在同一命令下。
- Covers builds, testing, and package management in one binary
由 Apple 与 Swift 社区在 Swift.org 组织下以 Apache-2.0 维护。
- Official
swiftlang/swiftrepository
swift.org 官方文档与各级 --help 结构清晰。
- Official docs at swift.org/documentation
安全边界、鉴权与放权指南
公开包无需认证;私有 Swift Registry 读取 ~/.swiftpm/configuration/registries.json 或系统 Git 凭证。
Apache-2.0 开源工具链,完全免费。
# Swift CLI (swift) Agent Rules - Use `swift package dump-package` and `show-dependencies --format json` to inspect `Package.swift` cleanly. - Note that `Package.swift` executes arbitrary Swift code during evaluation; inspect untrusted manifests before running.
Agent 高频安全命令配方
只读查询(安全推荐)
swift package dump-package
求值 Package.swift 并以 JSON 打印所有 target、product 与依赖声明。
swift package show-dependencies --format json
以 JSON 格式输出已解析的 SwiftPM 依赖图。
受控写入与预演
swift test --parallel
编译目标并并发执行 XCTest / Swift Testing 测试套件。
核心优势
- +
swift package dump-package与show-dependencies --format json可可靠解析Package.swift。 - + 编译器、SwiftPM 与
swift test无缝集成。
注意事项与踩坑点
- !
swift build与swift test的报错为纯文本而非 JSON。 - ! 涉及 iOS/UIKit 的工程仍需在 macOS 上调用
xcodebuild,无法仅靠swift build完成。