【问题标题】:Configution "copts" based on compiler (gcc vs clang) in Bazel基于 Bazel 中的编译器(gcc vs clang)的配置“copts”
【发布时间】:2019-11-03 18:03:42
【问题描述】:

我有一个基于 Bazel 的 C 项目,我想在 Linux 上同时使用 gccclang 编译它。为了在编译器之间切换,我在调用前加上 CC=<compiler,如下所示:

CC=clang bazel build //my-package:my-target

这按预期工作,除了我还使用 copts 参数调用 Bazel 规则:

cc_binary(
    name = "my-target",
    srcs = [
        "my-src.c",
    ],
    copts = [
        "-std=c89",
        "-Wno-unused-label",
        "-Wno-unused-variable",
        "-Wno-unused-but-set-variable",
        "-Wno-misleading-indentation",
    ],
)

这可行,但我从clang 收到“未知警告选项”消息:

warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]

warning: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-binding-in-condition'? [-Wunknown-warning-option]

是否可以在用于特定 Bazel 调用的 C 编译器上指定 copts 参数条件

【问题讨论】:

    标签: c gcc clang bazel


    【解决方案1】:

    创建一个.bazelrc 文件并使用--config 选项。

    我使用 Visual Studio 2019 和 GCC 来构建我的代码。

    我的.bazelrc

    build:vs2019 --cxxopt=/std:c++17
    
    build:gcc --cxxopt=-std=c++17
    

    Visual Studio 2019

    构建

    bazel build --config=vs2019 //...
    

    测试

    bazel test --config vs2019 //...
    

    gcc

    构建

    bazel build --config gcc //...
    

    测试

    bazel test --config gcc //...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 2014-11-02
      • 1970-01-01
      • 2022-01-08
      • 2011-07-16
      相关资源
      最近更新 更多