使用bazel和emscripten构建web组件



我一直在尝试使用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

我把所有东西都封装在github存储库中,你可以通过来复制它(如果你安装了docker)

git clone https://github.com/jdrouet/bazel-emscripten-test.git
cd bazel-emscripten-test
docker build .

如果你知道为什么这不起作用,请提前感谢!

emscripten生成的.d(依赖项)文件与bazel不兼容。本教程通过添加find . -name "*.d" -exec sed -i '2d' {} ;(删除依赖项列表的第一行)来"修复"此问题。您没有在github项目中包含这一行,这就是您遇到此问题的原因。

emscripten的依赖文件不适合bazel的原因是它们使用绝对路径而不是相对路径,因此引用了bazel认为不存在的文件。

在您解决了这个问题并决定构建一个更复杂的项目后,您还会遇到额外的依赖性问题,在.d文件中,除了第一行以外的其他行都以/开头。我必须创建一个脚本来删除文件中所有以/开头的行,因为我不是bash向导。你可以在这里找到我的代码。

您还会遇到这样的问题,即教程没有很好地处理cc_library规则的链接,因此您需要制作emar.sh(并将其链接到交叉工具中)。这就是我所做的。

在更复杂的项目中,当你试图链接到一个必须像SDL一样自己编译的库时,你最终会遇到bazel抱怨的问题对此,我还没有找到一个永久的解决方案,但如果你已经编译了没有bazel的项目,这些项目链接到这些相同的库,并将你的全局emscripten_cache符号链接到你的bazel项目中,那么构建将毫无怨言地成功。不幸的是,当链接到SDL时,我还没有弄清楚如何让bazel从空缓存中成功构建

编辑:您可以使用python embuilder.py build ALL创建一个完整的缓存,也可以指定单独的所需目标。我个人在存储库规则中添加了一个带有所需目标的类似调用,但它非常特定于我的项目,我决定从环境变量中提取信息,所以我不会将其包含在这个答案中。了解embuilder.py实际上是您自己实现所需要的全部内容。

相关内容

  • 没有找到相关文章

最新更新