I’m trying to target WASM for a library that was not originally written with compilation to WASM as a goal. The existing CMakeLists.txt builds protobuf and executes protoc. WASM doesn’t have subprocess calls or <sys/wait.h>. The build fails at the protobuf build and subprocess calls using WASI-SDK’s clang++ and Emscripten.
My limited understanding of protobuf is that is builds C++ from templates. My idea is to use some kind of condition to use g++ or LLVM Project’s clang++ to do the protobuf stuff while the rest of the build uses WASI-SDK clang++ or Emsciptens’s em++. Is that a reasonable and possible workaround to use as much as the already written build process as possible, while targeting WASM?
This is what I think are causing the WASM compilers to exit with errors
set(protobuf_INSTALL OFF CACHE BOOL “Install protobuf off” FORCE)
add_subdirectory(third_party/protobuf EXCLUDE_FROM_ALL)
if(APPLE)
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE HOST_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set_target_properties(protoc libprotoc libprotobuf
PROPERTIES
OSX_ARCHITECTURES “${HOST_ARCH}”
)
endif()
and this part
add_custom_command(
OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/cached_network_parameters.pb.h
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/crypto_server_config.pb.h
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/source_address_token.pb.h
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/cached_network_parameters.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/crypto_server_config.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/source_address_token.pb.cc
DEPENDS protobuf::protoc ${filename} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/cached_network_parameters.proto
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/crypto_server_config.proto
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/source_address_token.proto
COMMAND protobuf::protoc --proto_path=${PROTOMODEL_PATH} --cpp_out=${PROTOBINDING_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/cached_network_parameters.proto
COMMAND protobuf::protoc --proto_path=${PROTOMODEL_PATH} --cpp_out=${PROTOBINDING_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/crypto_server_config.proto
COMMAND protobuf::protoc --proto_path=${PROTOMODEL_PATH} --cpp_out=${PROTOBINDING_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quiche/quiche/quic/core/proto/source_address_token.proto
)