add mingw_gcc_compiler config_setting to zlib.BUILD
Fixes #16024
Workaround to avoid bazel build failure using MinGW GCC toolchain under Windows. These changes suppress [-fpermissive] errors while compiling zlib external dependency with mingw-gcc toolchain.
It looks like -fpermissive will treat errors like warnings.
I don't think we want to do this. What errors are you getting in the mingw build?
@haberman
It looks like
-fpermissivewill treat errors like warnings.I don't think we want to do this. What errors are you getting in the mingw build?
Thanks for reply. I'm getting these errors building protobuf with Bazel with mingw toolchain:
external/zlib~1.3.1/gzlib.c: In function 'gzFile_s* gz_open(const void*, int, const char*)':
external/zlib~1.3.1/gzlib.c:183:30: error: invalid conversion from 'const void*' to 'const wchar_t*' [-fpermissive]
183 | len = wcstombs(NULL, path, 0);
| ^~~~
| |
| const void*
In file included from C:/msys64/ucrt64/include/c++/13.2.0/cstdlib:79,
from C:/msys64/ucrt64/include/c++/13.2.0/stdlib.h:36,
from external/zlib~1.3.1/gzguts.h:24,
from external/zlib~1.3.1/gzlib.c:6:
C:/msys64/ucrt64/include/stdlib.h:531:82: note: initializing argument 2 of 'size_t wcstombs(char*, const wchar_t*, size_t)'
531 | size_t __cdecl wcstombs(char * __restrict__ _Dest,const wchar_t * __restrict__ _Source,size_t _MaxCount) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
external/zlib~1.3.1/gzlib.c:198:35: error: invalid conversion from 'const void*' to 'const wchar_t*' [-fpermissive]
198 | wcstombs(state->path, path, len + 1);
| ^~~~
| |
| const void*
C:/msys64/ucrt64/include/stdlib.h:531:82: note: initializing argument 2 of 'size_t wcstombs(char*, const wchar_t*, size_t)'
531 | size_t __cdecl wcstombs(char * __restrict__ _Dest,const wchar_t * __restrict__ _Source,size_t _MaxCount) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
external/zlib~1.3.1/gzlib.c:233:27: error: invalid conversion from 'const void*' to 'const wchar_t*' [-fpermissive]
233 | fd == -2 ? _wopen(path, oflag, 0666) :
| ^~~~
| |
| const void*
In file included from C:/msys64/ucrt64/include/fcntl.h:8,
from external/zlib~1.3.1/gzguts.h:31:
C:/msys64/ucrt64/include/io.h:316:45: note: initializing argument 1 of 'int _wopen(const wchar_t*, int, ...)'
316 | _CRTIMP int __cdecl _wopen(const wchar_t *_Filename,int _OpenFlag,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
| ~~~~~~~~~~~~~~~^~~~~~~~~
Full explanation is here: #16024
@haberman These default opts:
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-Wno-deprecated-non-prototype",
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
}),
look more clang-specific. I use GCC, so -Wno-deprecated-non-prototype is unrecognized. May be some other options should be set specifically for GCC? Anyway, trick with -fpermissive works only after commenting -Werror in protobuf\build_defs\cpp_opts.bzl because -Werror somehow overrides options provided in protobuf\third_party\zlib.BUILD.
@haberman
If I add following flags :
"-Wno-maybe-uninitialized",
"-Wno-unused-parameter",
"-Wno-missing-field-initializers",
"-Wno-implicit-fallthrough",
"-Wno-redundant-move",
to protobuf\build_defs\cpp_opts.bzl right after -Werror, protoc compiles successfully. But, anyway, I have to keep -fpermissive in protobuf\third_party\zlib.BUILD as external zlib won't compile without it.
I chatted with some people on the team, and I don't think we intended for user builds to get -Werror.
I think we'd prefer to remove -Werror from the build rather than add mingw-specific flags.
We triage inactive PRs and issues in order to make it easier to find active work. If this PR should remain active, please add a comment.
This PR is labeled inactive because the last activity was over 90 days ago. This PR will be closed and archived after 14 additional days without activity.