Emscripten 将 grpc 库编译为 wasm(WebAssembly) 时缺少 epoll.h

问题描述 投票:0回答:1

我将使用 Emscripten 将需要使用 grpc 库 的 C++ 项目转换为 wasm。据我所知,grpc源码需要使用Emscripten编译才能得到库。

顺便说一句,我想为独立 wasm 二进制文件编译 grpc lib 并使用运行时(例如,wasmtime)运行它。

以下错误已解决,可以前往Update2

但是在编译grpc源码时出现了错误

[  7%] Linking CXX static library libabsl_bad_variant_access.a
[  7%] Built target bad_variant_access
[  7%] Building CXX object CMakeFiles/gpr.dir/src/core/lib/gpr/alloc.cc.o
In file included from /home/xxx/grpc_wasm/grpc/src/core/lib/gpr/alloc.cc:19:
/home/xxx/grpc_wasm/grpc/include/grpc/support/port_platform.h:451:2: error: "Could not auto-detect platform"
#error "Could not auto-detect platform"
 ^
/home/xxx/grpc_wasm/grpc/include/grpc/support/port_platform.h:474:2: warning: "GPR_PLATFORM_STRING not auto-detected" [-W#warnings]
#warning "GPR_PLATFORM_STRING not auto-detected"
 ^
/home/xxx/grpc_wasm/grpc/include/grpc/support/port_platform.h:541:2: error: Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
#error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WINDOWS_ATOMIC
 ^
/home/xxx/grpc_wasm/grpc/include/grpc/support/port_platform.h:545:2: error: Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
#error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64
 ^
/home/xxx/grpc_wasm/grpc/include/grpc/support/port_platform.h:551:2: error: Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
#error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WINDOWS, GPR_CPU_IPHONE, GPR_CPU_CUSTOM
 ^
1 warning and 4 errors generated.
em++: error: '/home/xxx/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mlm -disable-lsr -DEMSCRIPTEN -I/home/xxx/emsdk/upstream/emscripten/cache/sysroot/include/SDL --sysroot=/home/xxx/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I/home/xxx/grpcasm/grpc/third_party/re2 -I/home/xxx/grpc_wasm/grpc/third_party/zlib -I/home/xxx/grpc_wasm/grpc/include -I/home/xxx/grpc_wasm/grpc -I/home/xxx/grpc_wasm/grpc/third_party/address_sorting/include -I/home/xxx/grpc_wasm/grpc/cmake/build/third_party/re2 -I/home/xxx/grpc_wasm/grpc/third_party/boringssl-with-bazel/src/include -I/home/xxx/grpc_wasm/grpc/src/core/ext/upb-generated -I/home/xxx/grpc_wasm/grpc/src/core/e/upbdefs-generated -I/home/xxx/grpc_wasm/grpc/third_party/upb -I/home/xxx/grpc_wasm/grpc/third_party/xxhash -I/home/xxx/grpc_wasm/grpc/cmake/build/third_party/zlib -I/home/xxx/grpc_wasm/grpc/third_party/abil-cpp -fPIC -std=c++14 -MD -MT CMakeFiles/gpr.dir/src/core/lib/gpr/alloc.cc.o -MF CMakeFiles/gpr.dir/src/core/lib/gpr/alloc.cc.o.d -c /home/xxx/grpc_wasm/grpc/src/core/lib/gpr/alloc.cc -o CMakeFiles/gpr.d/src/core/lib/gpr/alloc.cc.o' failed (returned 1)
make[2]: *** [CMakeFiles/gpr.dir/build.make:77: CMakeFiles/gpr.dir/src/core/lib/gpr/alloc.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1046: CMakeFiles/gpr.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
emmake: error: 'make' failed (returned 2)

我导出了

GRPC_CROSS_COMPILATION=true
GRPC_CROSS_AROPTS=cr --target=wasm32-wasi
,但似乎不起作用。

更新:

注意到警告:

CMake Warning at third_party/abseil-cpp/absl/copts/AbseilConfigureCopts.cmake:70 (message):
  Value of CMAKE_SYSTEM_PROCESSOR (x86) is unknown and cannot be used to set
  ABSL_RANDOM_RANDEN_COPTS
Call Stack (most recent call first):
  third_party/abseil-cpp/CMake/AbseilHelpers.cmake:18 (include)
  third_party/abseil-cpp/CMakeLists.txt:81 (include)

所以我为Emscripten cmake设置了平台参数:

-DEMSCRIPTEN_SYSTEM_PROCESSOR=x86_64
但似乎不起作用。

Cmake命令参数为:

emcmake cmake ../..  
-DCMAKE_INSTALL_PREFIX=/home/xxx/grpc_wasm/grpc/mylib 
-DEMSCRIPTEN_SYSTEM_PROCESSOR=x86_64 
-DCMAKE_CXX_FLAGS=-mrelaxed-simd 
-DCMAKE_C_FLAGS=-mrelaxed-simd 
-DCMAKE_BUILD_TYPE=Relese 
-DgRPC_PROTOBUF_PROVIDER=package 
-DProtobuf_INCLUDE_DIR=/home/xxx/protobuf_wasm/protobuf_src/src 
-DProtobuf_LIBRARIES=/home/xxx/protobuf_wasm/protobuf_src/src/.libs 
-DProtobuf_PROTOC_LIBRARY:/home/xxx/protobuf_wasm/protobuf_src/src/.libs

由于我已经使用 Emscripten 编译了 protobuf lib,因此我手动指定 libprotobuf 的 lib 和 include 目录。

更新2:

关于

error: "Could not auto-detect platform"
,我在grpc/include/grpc/support/port_platform.h中添加了
#define __linux__ 1

之后,我又遇到了一个错误:emscripten libc缺少epoll.h(详细信息和我所做的可以在这里找到)。

我在

emsdk include/sys
目录下创建了 epoll.h 和 eventfd.h,虽然 grpc 编译成功并得到了 libgrpc.a,但是在链接阶段却出现了 undefined symbol 的错误(也是这里)。这是因为libc中没有epoll.h和eventfd.h中函数的定义。

事实证明,Emscripten libc 不支持 epoll 系统调用,而我未能重新编译 libc(也这里)来支持它。

有人知道如何解决 epoll 问题吗?感谢任何回复和建议。谢谢!

webassembly emscripten
1个回答
0
投票

你能解决这个问题吗? 是否有任何进展? 谢谢。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.