我一直在尝试通过遵循doc from bazel来使用Bazel在webassembly中构建一个简单的c ++,但是我无法使其正常工作。
一切正常,bazel设法下载emscripten软件包,开始构建,突然说他找不到源...
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
Loading:
Loading: 0 packages loaded
Analyzing: target //main:helloworld (1 packages loaded, 0 targets configured)
Analyzing: target //main:helloworld (5 packages loaded, 16 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
INFO: SHA256 (https://github.com/kripken/emscripten/archive/1.37.22.tar.gz) = 433dedb63ba423cf04bbc9802b49fa842bd479bad31a339db9506614e92334c7
Analyzing: target //main:helloworld (11 packages loaded, 59 targets configured)
DEBUG: Rule 'emscripten_toolchain' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "433dedb63ba423cf04bbc9802b49fa842bd479bad31a339db9506614e92334c7"
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
INFO: SHA256 (https://s3.amazonaws.com/mozilla-games/emscripten/packages/llvm/tag/linux_64bit/emscripten-llvm-e1.37.22.tar.gz) = fd457ebfbe5a727058880ff55cdabf7f1b7809aea07957d2cc854e7de3001ef3
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
Analyzing: target //main:helloworld (12 packages loaded, 59 targets configured)
DEBUG: Rule 'emscripten_clang' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "fd457ebfbe5a727058880ff55cdabf7f1b7809aea07957d2cc854e7de3001ef3"
INFO: Analyzed target //main:helloworld (13 packages loaded, 7624 targets configured).
INFO: Found 1 target...
[0 / 3] [Prepa] Creating source manifest for //main:helloworld ... (2 actions, 0 running)
[0 / 3] [Prepa] Creating source manifest for //main:helloworld ... (2 actions, 0 running)
[3 / 5] checking cached actions
ERROR: /usr/src/app/main/BUILD:1:1: undeclared inclusion(s) in rule '//main:helloworld':
this rule is missing dependency declarations for the following files included by 'main/hello-world.cc':
'/usr/src/app/main/hello-world.cc'
DEBUG:root:PYTHON not defined in /root/.emscripten, using "/usr/bin/python"
DEBUG:root:EMCC_WASM_BACKEND tells us to use wasm backend
WARNING:root:invocation: external/emscripten_toolchain/emcc.py -MD -MF bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.d -frandom-seed=bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.o -iquote . -iquote bazel-out/asmjs-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/asmjs-fastbuild/bin/external/bazel_tools -isystem external/emscripten_toolchain/system/include/libcxx -isystem external/emscripten_toolchain/system/include/libc -c main/hello-world.cc -o bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.o (in /root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/sandbox/processwrapper-sandbox/1/execroot/__main__)
DEBUG:root:compiling to bitcode
DEBUG:root:emcc step "parse arguments and setup" took 0.00 seconds
DEBUG:root:compiling source file: /usr/src/app/main/hello-world.cc
DEBUG:root:running: /root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_clang/clang++ -target wasm32-unknown-unknown -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=37 -D__EMSCRIPTEN_tiny__=22 -D_LIBCPP_ABI_VERSION=2 -D__EMSCRIPTEN__ -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -nostdinc -Xclang -nobuiltininc -Xclang -nostdsysteminc -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include/libcxx -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/lib/libcxxabi/include -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include/compat -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include/SSE -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include/libc -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/lib/libc/musl/arch/emscripten -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/local/include -MD -MF bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.d -frandom-seed=bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.o -iquote . -iquote bazel-out/asmjs-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/asmjs-fastbuild/bin/external/bazel_tools -isystem external/emscripten_toolchain/system/include/libcxx -isystem external/emscripten_toolchain/system/include/libc -c -std=c++03 /usr/src/app/main/hello-world.cc -Xclang -isystem/root/.cache/bazel/_bazel_root/a14564dce24fc232216f1aef117728d1/external/emscripten_toolchain/system/include/SDL -emit-llvm -c -o bazel-out/asmjs-fastbuild/bin/main/_objs/helloworld/hello-world.o
DEBUG:root:emcc step "bitcodeize inputs" took 0.01 seconds
DEBUG:root:stopping at bitcode
Target //main:helloworld failed to build
INFO: Elapsed time: 60.763s, Critical Path: 0.67s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
我将所有内容都包裹在a github repository中,并且您可以这样做(如果已安装docker)来重制此内容
git clone https://github.com/jdrouet/bazel-emscripten-test.git
cd bazel-emscripten-test
docker build .
如果您对为什么此方法不起作用有任何想法,请先谢谢您!
答案 0 :(得分:1)
emscripten生成的.d(相关性)文件不能很好地与bazel配合使用。本教程通过添加find . -name "*.d" -exec sed -i '2d' {} \;
(删除依赖关系列表的第一行)来“修复”此问题。您没有在github项目中包含此行,这就是您遇到此问题的原因。
emscripten的依赖文件之所以不能与bazel配合使用,是因为它们使用绝对路径而不是相对路径,因此引用了bazel认为不存在的文件。
解决此问题并决定构建一个更复杂的项目后,您还会遇到其他依赖项问题,其中其他行比.d文件中的第一行以/开头。我必须创建一个脚本来删除文件中以/开头的所有行,因为我不是bash向导。您可以找到我的代码here。
您还将遇到本教程无法很好地处理cc_library规则链接的问题,因此您需要制作一个emar.sh(并将其链接到crosstool中)。 This是我所做的。
您最终将在一个更复杂的项目中遇到一个问题,当您尝试链接到必须像SDL一样自行编译的库时,bazel会抱怨。 为此,我还没有找到一个永久性的解决方案,但是如果您已经编译了没有bazel的项目并链接到这些相同的库,并且将全局emscripten_cache符号链接到了bazel项目中,那么构建将成功而无需抱怨。不幸的是,当与SDL链接时,我还没有弄清楚如何从空缓存中成功构建bazel。
编辑:
您可以使用python embuilder.py build ALL
创建完整的缓存,也可以指定各个必需的目标。我个人将带有所需目标的调用添加到存储库规则中,但是该调用非常特定于我的项目,因此我决定从环境变量中提取信息,因此我不会在此答案中包括它。真正了解embuilder.py
就是您所需要的。