How to build optimized version of Swift Package using the Swift Package Manager `swift build` command

风格不统一 提交于 2019-12-11 07:08:19

问题


I want to compile my swift code written in the new Swift Package Manager format into highly optimized binary code. This is possible currently using swiftc -O somefile.swift But since the swift packages are built using swift build command, I cannot pass -O option as it does not accept it. So is there a way to specify to optimize the code during the compile process?


回答1:


You can build in a release configuration with: swift build --configuration release.

You can also see the tool usage via:

$ 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

which lists this option.

See the package manager reference for more information.



来源:https://stackoverflow.com/questions/39775937/how-to-build-optimized-version-of-swift-package-using-the-swift-package-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!