google / glog

C++ implementation of the Google logging module
http://google.github.io/glog/
BSD 3-Clause "New" or "Revised" License
7.01k stars 2.05k forks source link

bazel compilation with emscripten failed #1081

Closed wzheng21 closed 7 months ago

wzheng21 commented 7 months ago

Hi we are recently trying to compile glog to wasm using bazel. The commit we are compiling is this. The crucial part of the error message is

Compiling src/raw_logging.cc failed: (Exit 1): emcc.sh failed: error executing command external/emsdk/emscripten_toolchain/emcc.sh '--sysroot=external/emscripten_bin_linux/emscripten/cache/sysroot' -fdiagnostics-color -fno-exceptions -fno-strict-aliasing -funsigned-char ... (remaining 53 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/com_googlesource_code_glog/src/raw_logging.cc:162:14: error: use of undeclared identifier 'STDERR_FILENO'
  safe_write(STDERR_FILENO, buffer, strlen(buffer));
             ^
1 error generated.

The root cause seems to be that wasm_copts misses -DHAVE_MODE_T and -DHAVE_UNISTD_H, both of which are defined in linux_or_darwin_copts, so when the platform is wasm, then compilation failed.

The quick fix I did is to move those two macro definitions to wasm_copts. Let me know if there's a more correct way of handling this or I missed anything.

drigz commented 7 months ago

Hey Victor! Let me know if you feel comfortable sending a PR to https://github.com/google/glog/blob/master/bazel/glog.bzl to fix this - also, if you depend on the wasm support maybe you could think about how to add CI for this in either https://github.com/google/glog/blob/master/.bazelci/presubmit.yml or https://github.com/google/glog/tree/master/.github/workflows, as I'm not sure how we can prevent future wasm breakage (it was added by a contributor but I haven't heard anything from them for some time).

wzheng21 commented 7 months ago

Hi @drigz I'm happy to send a PR. There's really not much to do. But it's a bit hard for me to do the CICD stuff with bazel + WASM.

drigz commented 7 months ago

But it's a bit hard for me to do the CICD stuff with bazel + WASM.

NP, don't block the fix on CI suggestion. Feel free to ignore that (and maybe revisit if you observe more breakage in future).