如何使用 Swift Package Manager `swift build` 命令构建 Swift Package 的优化版本

Enc*_*PTL 2 optimization swift swift-package-manager

我想将以新的 Swift Package Manager 格式编写的 swift 代码编译为高度优化的二进制代码。这在当前使用中是可能的swiftc -O somefile.swift但是由于 swift 包是使用swift build命令构建的,我无法传递-O选项,因为它不接受它。那么有没有办法指定在编译过程中优化代码呢?

Dan*_*bar 5

你可以建立与释放配置:swift build --configuration release

您还可以通过以下方式查看工具使用情况:

$ swift build --help
OVERVIEW: Build sources into binary products

USAGE: swift build [mode] [options]

MODES:
  -c, --configuration <value>   Build with configuration (debug|release) [default: debug]
  --clean [<mode>]              Delete artifacts (build|dist) [default: build]

OPTIONS:
      -C, --chdir <path>       Change working directory before any other operation
  --build-path <path>      Specify build/cache directory [default: ./.build]
  --color <mode>           Specify color mode (auto|always|never) [default: auto]
  -v, --verbose            Increase verbosity of informational output
  -Xcc <flag>              Pass flag through to all C compiler invocations
  -Xlinker <flag>          Pass flag through to all linker invocations
  -Xswiftc <flag>          Pass flag through to all Swift compiler invocations

NOTE: Use `swift package` to perform other functions on packages
Run Code Online (Sandbox Code Playgroud)

其中列出了此选项。

有关更多信息,请参阅包管理器参考

  • 谢谢(你的)信息。能够通过运行以下命令`swift build -Xswiftc -O`来传递优化选项 (3认同)