本文介绍了如何使用Swift Package Manager`swift build`命令构建Swift Package的优化版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将以新的Swift Package Manager格式编写的Swift代码编译为高度优化的二进制代码.当前可以使用swiftc -O somefile.swift来实现,但是由于swift软件包是使用swift build命令构建的,因此我无法通过-O选项,因为它不接受.那么有没有一种方法可以指定在编译过程中优化代码?

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?

推荐答案

您可以使用以下版本构建发布配置:swift build --configuration release.

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

列出了此选项.

请参阅程序包管理器参考了解更多信息.

See the package manager reference for more information.

这篇关于如何使用Swift Package Manager`swift build`命令构建Swift Package的优化版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:47