【问题标题】:How to build optimized version of Swift Package using the Swift Package Manager `swift build` command如何使用 Swift Package Manager `swift build` 命令构建 Swift Package 的优化版本
【发布时间】:2017-02-08 02:41:27
【问题描述】:

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

【问题讨论】:

    标签: swift optimization swift-package-manager


    【解决方案1】:

    您可以使用以下代码构建发布配置: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
    

    其中列出了此选项。

    请参阅包管理器reference 了解更多信息。

    【讨论】:

    • 感谢您的信息。能够通过运行以下命令swift build -Xswiftc -O 来传递优化选项
    • 您是否知道如何获取加载到 XCODE 中的包以使用此 -O 标志?每当我使用软件包时,它们总是构建未优化的。即使母项目设置为优化
    • 找到了解决方案。无论如何谢谢✌️
    • “参考”链接已失效
    猜你喜欢
    • 2023-02-10
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多