CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Swift CLI

$ swift 官方出品 低风险
Swift.org · 代码托管与研发协同 · Apache-2.0 · macos / linux / windows

驱动 Swift 编译器与 SwiftPM 包管理器的官方 CLI(swift build、swift test、swift package)。提供 swift package dump-package 与 swift package show-dependencies --format json,无需触发完整编译即可获取结构化工程与依赖信息。

FCRS-1.0 综合评分
80 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
brew install swift
CLI vs MCP 选型建议 仅 CLI 可用

本地 Swift 工具链与 SwiftPM 调度器,直接在 Package.swift 工作区运行。

Agent 友好度体检单

本地探针实测证据
✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
实测版本
Apple Swift version 6.4.2 (swiftlang-6.4.2.1.9 clang-2100.4.1.1)
冷启动耗时
545 ms
退出码 (help / 非法参数)
0 / 1
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --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 六维评分拆解

Agent 友好度 18 / 25

swift package dump-package 与 show-dependencies --format json 输出干净 JSON,但 swift build 与 swift test 仍为文本诊断。

  • dump-package and show-dependencies --format json support
  • Non-interactive swift build and swift test
安全与权限边界 20 / 25

纯本地编译且无远程写入命令,但求值 Package.swift 会运行其中的 Swift 清单代码。

  • Local-only writes to .build/ and Package.resolved
安装与运行摩擦 11 / 15

macOS 通过 Xcode CLT 自带且官方支持 Linux,但 Windows 及 iOS 生态支持相对受限。

  • First-class on macOS/Linux; partial ecosystem parity on Windows
能力覆盖与边际价值 13 / 15

将编译器、测试与 SwiftPM 依赖解析统一在同一命令下。

  • Covers builds, testing, and package management in one binary
维护与来源背书 10 / 10

由 Apple 与 Swift 社区在 Swift.org 组织下以 Apache-2.0 维护。

  • Official swiftlang/swift repository
文档与可验证性 8 / 10

swift.org 官方文档与各级 --help 结构清晰。

  • Official docs at swift.org/documentation

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 本地配置文件
凭证存储位置

公开包无需认证;私有 Swift Registry 读取 ~/.swiftpm/configuration/registries.json 或系统 Git 凭证。

潜在副作用
只读查询 本地写入
费用与配额提示

Apache-2.0 开源工具链,完全免费。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# 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 高频安全命令配方

只读查询(安全推荐)

以 JSON 导出解析后的 Package.swift 清单
swift package dump-package

求值 Package.swift 并以 JSON 打印所有 target、product 与依赖声明。

以 JSON 查看依赖树
swift package show-dependencies --format json

以 JSON 格式输出已解析的 SwiftPM 依赖图。

受控写入与预演

并行构建并运行 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 完成。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI