google / mozc

Mozc - a Japanese Input Method Editor designed for multi-platform
Other
2.32k stars 329 forks source link

Build error: Can't build Mozc by gcc-14.1.1 20240507 #927

Open utuhiro78 opened 1 month ago

utuhiro78 commented 1 month ago

Description

I can't build Mozc by gcc-14.1.1 20240507.

Commit-id

d569f615fabd238b479bb6e44a8288b2eea4e0b1

Build target

  1. Docker build for Linux and Android-lib

CI build status

  1. passing

Environment

Build commands

Steps of command lines to reproduce your error.

  1. cd src/
  2. bazel build package --config oss_linux -c opt

Error logs

INFO: From Compiling src/google/protobuf/arena.cc:
external/com_google_protobuf/src/google/protobuf/arena.cc: In member function 'void* google::protobuf::internal::SerialArena::AllocateAlignedFallback(size_t)':
external/com_google_protobuf/src/google/protobuf/arena.cc:194:10: warning: 'ret' may be used uninitialized [-Wmaybe-uninitialized]
  194 |   return ret;
      |          ^~~
external/com_google_protobuf/src/google/protobuf/arena.cc:191:9: note: 'ret' was declared here
  191 |   void* ret;
      |         ^~~
ERROR: /home/user/.cache/bazel/_bazel_user/3b071445677b72e8d401337ab1a5c4ad/external/com_google_protobuf/src/google/protobuf/BUILD.bazel:548:11: Compiling src/google/protobuf/map_field.cc [for tool] failed: (Exit 1): gcc failed: error executing CppCompile command (from target @@com_google_protobuf//src/google/protobuf:protobuf) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 62 arguments skipped)

Additional context

I can build mozc by gcc-13.2.1 20240417.

cd /usr/bin/
sudo mv gcc gcc-14
sudo mv gcc-13 gcc
bazel build package --config oss_linux -c opt

Thank you for developing Mozc.

hiroyuki-komatsu commented 1 month ago

Hi utuhiro78,

Since the build failed at src/google/protobuf/map_field.cc, it could be an issue of Protocol Buffers.

To get more error logs, would you try a build with --sandbox_debug and --verbose_failures?

bazel build package --config oss_linux -c opt --sandbox_debug --verbose_failures
Nocifer commented 1 month ago

The error is indeed with Protobuf, and it is due to them unconditionally enabling -Werror, which in turn stumbles upon some innocuous -Wmaybe-uninitialized and turns them into errors which then break the build.

This was already reported back in November with https://github.com/protocolbuffers/protobuf/issues/14714 and can be fixed with https://github.com/protocolbuffers/protobuf/pull/14752, but the relevant PR was closed and so far has not been merged.

Tl;DR we just need to explicitly disable -Werror before building.

hiroyuki-komatsu commented 1 month ago

Thank you for the information,

Would you try to build Mozc with --copt="-Wno-error"?

bazel build package --config oss_linux -c opt  --copt="-Wno-error"

and also --copt="-Wno-maybe-uninitialized"?

bazel build package --config oss_linux -c opt  --copt="-Wno-maybe-uninitialized"
Nocifer commented 1 month ago

Would you try to build Mozc with --copt="-Wno-error"?

Unfortunately, passing -Wno-error won't work because Protobuf's global -Werror is applied later down the line, resulting in a build command like this:

[...] /usr/bin/gcc [...] '-std=c++20' -Wno-error [...] -Werror [...]

and also --copt="-Wno-maybe-uninitialized"?

This will work because -Wmaybe-uninitialized is not explicitly invoked, so it can be easily overridden, but it needs to be applied to Bazel's exec configuration as well, like so:

bazel build package --config oss_linux -c opt --copt="-Wno-maybe-uninitialized" --host_copt="-Wno-maybe-uninitialized"

wengxt commented 1 month ago

I personally would suggest mozc not to do any workaround, because it may introduce issue in the future if compiler did anything on the flag.

In case any found this issue, the flag that I use is

--cxxopt=-Wno-uninitialized --host_cxxopt=-Wno-uninitialized

It works with gcc and clang. (clang doesn't have maybe-uninitialized)