Bazel用ccache构建C ++示例失败 [英] Bazel building C++ sample with ccache fails

查看:530
本文介绍了Bazel用ccache构建C ++示例失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在此处进行操作.我已经安装了bazel,克隆了示例并尝试使用bazel build //main:hello-world进行构建.但是这里出了问题.

I've been following the instructions for OSX here. I've installed bazel, cloned the sample and tried to build it with bazel build //main:hello-world. But here where it got wrong.

INFO: Analysed target //main:hello-world (0 packages loaded). INFO:
Found 1 target... ERROR:
/Users/myuser/work/temp/bazel-sample/examples/cpp-tutorial/stage1/main/BUILD:1:1:
Linking of rule '//main:hello-world' failed (Exit 1) ccache: error:
Failed to create temporary file for
/Users/myuser/.ccache/6/stats.tmp: Operation not
permitted Target //main:hello-world failed to build Use
--verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 0.295s, Critical Path: 0.07s INFO: 0 processes.
FAILED: Build did NOT complete successfully

好像我安装的ccache有问题.用--verbose_failures

Seems like there's an issue with ccache which I have installed. After running same command with --verbose_failures

INFO: Analysed target //main:hello-world (0 packages loaded). INFO:
Found 1 target... ERROR:
/Users/myuser/work/temp/bazel-sample/examples/cpp-tutorial/stage1/main/BUILD:1:1:
Linking of rule '//main:hello-world' failed (Exit 1): cc_wrapper.sh
failed: error executing command    (cd
/private/var/tmp/_bazel_myuser/550c05da61518b4bbbb0ffdfd033154f/execroot/__main__
&& \   exec env - \
    APPLE_SDK_PLATFORM='' \
    APPLE_SDK_VERSION_OVERRIDE='' \
    PATH=/Users/myuser/Library/Android/sdk/platform-tools:/Users/myuser/Library/Android/sdk/tools:/Users/myuser/Library/Android/sdk/build-tools/25.0.0:/Users/myuser/Library/Android/ndk/android-ndk-r10c:/Applications/CMake.app/Contents/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/myuser/bin
\
    XCODE_VERSION_OVERRIDE=9.3.0 \   external/local_config_cc/cc_wrapper.sh -fobjc-link-runtime -Wl,-S -o
bazel-out/darwin-fastbuild/bin/main/hello-world
bazel-out/darwin-fastbuild/bin/main/_objs/hello-world/main/hello-world.o
-headerpad_max_install_names -lc++ -no-canonical-prefixes)

Use --sandbox_debug to see verbose messages from the sandbox ccache:
error: Failed to create temporary file for
/Users/myuser/.ccache/0/stats.tmp: Operation not permitted Target
//main:hello-world failed to build INFO: Elapsed time: 0.294s,
Critical Path: 0.07s INFO: 0 processes. FAILED: Build did NOT complete
successfully

我发现沙箱存在问题.添加--sandbox_debug打印:

I figured out that there's an issue with sandbox. Adding --sandbox_debug prints:

INFO: Analysed target //main:hello-world (0 packages loaded).
INFO: Found 1 target...
ERROR: /Users/myuser/work/temp/bazel-sample/examples/cpp-tutorial/stage1/main/BUILD:1:1: Linking of rule '//main:hello-world' failed (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_myuser/550c05da61518b4bbbb0ffdfd033154f/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM='' \
    APPLE_SDK_VERSION_OVERRIDE='' \
    DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/myuser/bin \
    SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk \
    TMPDIR=/var/folders/x3/r5tf7wfx3_q0xnyx95s3r5400000gq/T/ \
    XCODE_VERSION_OVERRIDE=9.3.0 \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_myuser/550c05da61518b4bbbb0ffdfd033154f/sandbox/darwin-sandbox/1/sandbox.sb /private/var/tmp/_bazel_myuser/550c05da61518b4bbbb0ffdfd033154f/execroot/__main__/_bin/process-wrapper '--timeout=0' '--kill_delay=15' external/local_config_cc/cc_wrapper.sh -fobjc-link-runtime -Wl,-S -o bazel-out/darwin-fastbuild/bin/main/hello-world bazel-out/darwin-fastbuild/bin/main/_objs/hello-world/main/hello-world.o -headerpad_max_install_names -lc++ -no-canonical-prefixes)
ccache: error: Failed to create temporary file for /Users/myuser/.ccache/b/stats.tmp: Operation not permitted
Target //main:hello-world failed to build
INFO: Elapsed time: 0.268s, Critical Path: 0.06s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

沙箱文件sandbox.sb的内容为:

(version 1)
(debug deny)
(allow default)
(deny file-write*)
(allow file-write*
    (subpath "/dev")
    (subpath "/Users/myuser/Library/Logs")
    (subpath "/Users/myuser/Library/Developer")
    (subpath "/private/var/folders/x3/r5tf7wfx3_q0xnyx95s3r5400000gq/T")
    (subpath "/private/var/tmp/_bazel_myuser/550c05da61518b4bbbb0ffdfd033154f/sandbox/darwin-sandbox/1/execroot/__main__")
    (subpath "/private/var/tmp")
    (subpath "/private/var/folders/x3/r5tf7wfx3_q0xnyx95s3r5400000gq/C")
    (subpath "/private/tmp")
)

它显然缺少写入/Users/myuser/.ccache目录的权限.我尝试用export CCACHE_DISABLE=1禁用ccache,但是没有任何变化.如何在不删除ccache的情况下进行修复?

It is apparently missing the permissions to write to the /Users/myuser/.ccache directory. I have tried disabling ccache with export CCACHE_DISABLE=1 but nothing changes. How can I fix it without removing ccache?

推荐答案

是否设置了编译器的绝对路径并将其传递给CC环境变量?如果您已安装Xcode,则可能需要使用BAZEL_USE_CPP_ONLY_TOOLCHAIN=1.

Is setting an absolute path to the compiler and passing it to CC environment variable an option? You might need to use BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 if you have Xcode installed.

这篇关于Bazel用ccache构建C ++示例失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆