Search code examples
grpccross-platformwebassemblyemscripten

gRPC Web compilation with Emscripten


Can I compile gRPC to the Web with Emscripten?

NOTE: I'm trying to compile it but it keeps giving errors, please help,

NOTE: Without gRPC-Web.

Thanks.

I am compiling gRPC cross platform and I was able to compile it everywhere except the Web side. I'm getting a few general errors, I'm solving them as a result of research, but new ones are being added:

  • clang++: error: unsupported argument '-g' to option '-Wa,'
  • error: "Could not auto-detect platform"
  • grpc error: unknown type name 'gpr_atm'
  • emcc: error: libz.a: No such file or directory ("libz.a" was expected to be an input file, based on the commandline arguments provided)
  • wasm-ld: error: --shared-memory is disallowed by ex_data.c.o because it was not compiled with 'atomics' or 'bulk-memory' features.
  • fatal error: 'sys/eventfd.h' file not found and fatal error: 'sys/epoll.h' file not found

Solution

  • I don't think you realize the amount of work that is needed to port it to WASM. It is a platform after all. It is comparable to a port to Windows or macOS.

    You will need to understand and modify the makefiles to fix the compiler options.

    But this is only the beginning.

    libz for example has been ported - you will have to get it, compile it and include it in your project.

    But when it comes to epoll or eventfd - well, these simply do not have direct equivalents in the web world. You will have to reimplement parts of the code.

    Shared memory requires that you compile with -pthread and your web server has COOP/COEP enabled - google it for more information - you will need SharedArrayBuffer.

    This is an absolutely huge undertaking and you will have to learn a lot about both gRPC internals and the WASM world.