如何在不配置新工具链的情况下告诉Bazel使用哪个编译器

结婚戒指

我想强迫Bazel使用新的编译器来构建我的项目。据我了解,我可以配置一个新的工具链或使用一些命令行选项。我尝试了以下选项:

-CC=clang bazel build //main:hello-world
-export CC=C:\cygwin64\bin\clang++
- bazel build //main:hello-world  --client_env=CC=clang

我认为这些方法不起作用,因为如果我使用以下命令编译相同的hello-world.cc文件,

clang hello-world.cc 

我得到错误:

clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

但随着

CC=clang bazel build //main:hello-world 
or
bazel build //main:hello-world  --client_env=CC=clang

构建成功。

知道结果为何不同以及如何解决这个问题吗?在哪里可以检查Bazel使用的是哪个编译器?

编辑:

这里的输出:

CC = C:\ cygwin64 \ bin \ clang bazel build -s // main:hello-world

Starting local Bazel server and connecting to it...
Loading: 
Loading: 0 packages loaded
Analyzing: target //main:hello-world (1 packages loaded, 0 targets configured)
Analyzing: target //main:hello-world (11 packages loaded, 18 targets configured)
INFO: Analyzed target //main:hello-world (14 packages loaded, 59 targets configured).
INFO: Found 1 target...
[0 / 6] [Prepa] BazelWorkspaceStatusAction stable-status.txt ... (4 actions, 0 running)
SUBCOMMAND: # //main:hello-world [action 'Compiling main/hello-world.cc', configuration: 1f7c3bee164375155568e7845819f422152903a0240344d14b0c6474746ef185, execution platform: @local_config_platform//:host]
cd C:/cygwin64/home/user/_bazel_user/5r4lncy4/execroot/__main__
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\;C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe
    SET PWD=/proc/self/cwd
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=C:\cygwin64\tmp
    SET TMP=C:\cygwin64\tmp
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-fastbuild/bin/main/_objs/hello-world/hello-world.obj /c main/hello-world.cc
SUBCOMMAND: # //main:hello-world [action 'Linking main/hello-world.exe', configuration: 1f7c3bee164375155568e7845819f422152903a0240344d14b0c6474746ef185, execution platform: @local_config_platform//:host]
cd C:/cygwin64/home/user/_bazel_user/5r4lncy4/execroot/__main__
  SET LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\ATLMFC\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\;C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe
    SET PWD=/proc/self/cwd
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=C:\cygwin64\tmp
    SET TMP=C:\cygwin64\tmp
  C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/HostX64/x64/link.exe @bazel-out/x64_windows-fastbuild/bin/main/hello-world.exe-2.params
Target //main:hello-world up-to-date:
  bazel-bin/main/hello-world.exe
INFO: Elapsed time: 4.561s, Critical Path: 0.67s
INFO: 2 processes: 2 local.
INFO: Build completed successfully, 6 total actions
INFO: Build completed successfully, 6 total actions

知道为什么会这样吗?我正在使用Windows 10。

安德烈·K。

当不定义自己的工具链时,bazel会尝试为您执行自动配置,这实际上会CC在定义时考虑变量的为什么裸露的编译尝试失败的原因尚不完全清楚,但有疑问时,您可以将其添加-s到bazel命令行中以查看所调用的命令,并查看被调用了哪个编译器:

$ CC=/usr/bin/clang bazel build -s //:hello
INFO: Analyzed target //:hello (1 packages loaded, 15 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //:greet [action 'Compiling greet.cpp', configuration: dd44f3279b21e91676f65783c46b7b7816026ef7e696e80c251418ec64ffdf5e]
(cd /tmp/_bzl/execroot/__main__ && \
  exec env - \
    PATH=/bin:/usr/bin:/usr/local/bin \
    PWD=/proc/self/cwd \
  /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -I/usr/lib64/qt/include -MD -MF bazel-out/k8-fastbuild/bin/_objs/greet/greet.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/greet/greet.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -Ibazel-out/k8-fastbuild/bin/_virtual_includes/greet -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c greet.cpp -o bazel-out/k8-fastbuild/bin/_objs/greet/greet.pic.o)
SUBCOMMAND: # //:hello [action 'Compiling hello.cpp', configuration: dd44f3279b21e91676f65783c46b7b7816026ef7e696e80c251418ec64ffdf5e]
(cd /tmp/_bzl/execroot/__main__ && \
  exec env - \
    PATH=/bin:/usr/bin:/usr/local/bin \
    PWD=/proc/self/cwd \
  /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -I/usr/lib64/qt/include -MD -MF bazel-out/k8-fastbuild/bin/_objs/hello/hello.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/hello/hello.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -Ibazel-out/k8-fastbuild/bin/_virtual_includes/greet -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c hello.cpp -o bazel-out/k8-fastbuild/bin/_objs/hello/hello.pic.o)
SUBCOMMAND: # //:hello [action 'Linking hello', configuration: dd44f3279b21e91676f65783c46b7b7816026ef7e696e80c251418ec64ffdf5e]
(cd /tmp/_bzl/execroot/__main__ && \
  exec env - \
    PATH=/bin:/usr/bin:/usr/local/bin \
    PWD=/proc/self/cwd \
  /usr/bin/clang @bazel-out/k8-fastbuild/bin/hello-2.params)
Target //:hello up-to-date:
  bazel-bin/hello
INFO: Elapsed time: 1.606s, Critical Path: 0.44s
INFO: 3 processes: 3 linux-sandbox.
INFO: Build completed successfully, 5 total actions

Windows有点特殊/不同的情况:我已经开始查看相应的rules_cc,但是实际上从那里开始回到docs,目前推荐的方法是添加一个平台定义(例如,在您的工作区root中BUILD):

  platform(
      name = "x64_windows-clang-cl",
      constraint_values = [
          "@platforms//cpu:x86_64",
          "@platforms//os:windows",
          "@bazel_tools//tools/cpp:clang-cl",
      ],
  )

并在WORKSPACE文件中注册其他工具链

  register_execution_platforms(
      ":x64_windows-clang-cl"
  )

  register_toolchains(
      "@local_config_cc//:cc-toolchain-x64_windows-clang-cl",
  )

然后(现在)使用--incompatible_enable_cc_toolchain_resolution带有bazel的标志。

至少目前,或者,您应该能够通过运行bazel来告诉bazel在Windows上使用LLVM --compiler=clang-cl

您可能需要BAZEL_LLVM(这次)设置为安装LLVM的目录(或尝试依靠自动解析)。

就是说,您似乎无法在Windows上使用cygwin LLVM编译器,同时仍然依赖于自动工具链配置。我怀疑您确实需要为此定义自己的工具链(不确定跨越Windows bazel与基于cygwin的编译器之间的界限会遇到多少实质性问题,而每种编译器对使用哪种路径名都有不同的想法)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在没有 webpack fable-loader 的情况下使用 Fable 编译器?

如何指定Yocto使用哪个编译器工具链来构建映像?

如何确定我的Rust编译器正在使用哪个Windows工具链?

如何在不配置邮件服务器的情况下将邮件发送到所有域

Bazel,带有mingw64编译器的Windows 10工具链配置

编译器如何在不知道编译时大小的情况下分配内存?

如何在不配置Bash脚本的情况下运行aws命令?

如何使用Rustup删除Rust编译器工具链?

编译器如何在不更改参数列表的情况下重载模板函数?

如何在不得到编译器警告的情况下初始化char * args []

如何在不参考doc的情况下获得g ++编译器的c ++的默认模式?

如何在没有主机编译器的情况下创建Cuda模块

如何在不以“监视”模式运行TypeScript编译器的情况下快速启动Deno?

如何在编译器选项设置为strict的情况下读取元素?

如何在不使编译器崩溃的情况下实现MutableCollectionType?

如何在没有编译器的情况下获得简单的Makefile教程

如何在编译器不知道的情况下更改变量的值?

C ++编译器在没有告诉我的情况下通过引用传递?

如何覆盖默认情况下setup.py使用的编译器(gcc)标志?

如何覆盖默认情况下setup.py使用的编译器(gcc)标志?

如何避免“需要非空的情况下使用空参数”编译器警告

如何在不引起重新编译的情况下更改sbt项目的编译器标志?

如何在不创建新工具栏布局的情况下使用XML更改Android工具栏背景颜色

如何在不运行静态代码分析的情况下使用 Visual C++ 在我自己的代码中引起 SAL 编译器警告

F#TaskBuilder:如何在不返回伪值以符合编译器约束的情况下引发异常?

像Babel这样的编译器如何在固有地不受支持的情况下实现尾部调用优化?

TypeScript:如何在编译器不了解可达性的情况下抛出错误?

如何在没有编译器警告的情况下返回对空字符串的const引用?

如何在没有C ++编译器聪明的情况下实现GLSL vec *构造语法?