Обсуждение: MinGW cross compilation failure on Debian trixie

Поиск
Список
Период
Сортировка

MinGW cross compilation failure on Debian trixie

От
Nazir Bilal Yavuz
Дата:
Hi,

I am working on upgrading Debian bookworm CI images to Debian trixie.
CompilerWarnings CI task's mingw_cross_warning_script failed with [1]:

```
make -s -j${BUILD_JOBS} clean
time make -s -j${BUILD_JOBS} world-bin
In file included from ../../../../src/include/port.h:16,
from ../../../../src/include/c.h:1353,
from ../../../../src/include/postgres.h:48,
from pg_locale_libc.c:12:
pg_locale_libc.c: In function ‘wc_isdigit_libc_mb’:
../../../../src/include/port/win32_port.h:438:20: error: implicit
declaration of function ‘_iswctype_l’; did you mean ‘_isctype_l’?
[-Wimplicit-function-declaration]
438 | #define iswdigit_l _iswdigit_l
| ^~~~~~~~~~~
pg_locale_libc.c:178:16: note: in expansion of macro ‘iswdigit_l’
178 | return iswdigit_l((wint_t) wc, locale->info.lt);
| ^~~~~~~~~~
make[4]: *** [<builtin>: pg_locale_libc.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [../../../src/backend/common.mk:37: adt-recursive] Error 2
make[2]: *** [common.mk:37: utils-recursive] Error 2
make[1]: *** [Makefile:42: all-backend-recurse] Error 2
make: *** [GNUmakefile:21: world-bin-src-recurse] Error 2
```

I am not sure if this problem is about Postgres or Debian yet; but I
wanted to share it.

I can reproduce this problem on my Debian sid machine on upstream,
REL_18_STABLE and REL_17_STABLE branches. REL_16_STABLE compiles
successfully. My specs are:
- Linux nbyavuz 6.16.7+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.16.7-1 (2025-09-11) x86_64 GNU/Linux
- gcc version 15.2.0 (Debian 15.2.0-4)
- mingw-w64-tools 12.0.0-5
- gcc-mingw-w64-x86-64-win32 14.2.0-19+27+b1
- g++-mingw-w64-x86-64-win32 14.2.0-19+27+b1

[1] https://cirrus-ci.com/task/6240816059908096

--
Regards,
Nazir Bilal Yavuz
Microsoft



Re: MinGW cross compilation failure on Debian trixie

От
Thomas Munro
Дата:
On Fri, Sep 19, 2025 at 8:13 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote::
> pg_locale_libc.c: In function ‘wc_isdigit_libc_mb’:
> ../../../../src/include/port/win32_port.h:438:20: error: implicit
> declaration of function ‘_iswctype_l’; did you mean ‘_isctype_l’?
> [-Wimplicit-function-declaration]
> 438 | #define iswdigit_l _iswdigit_l
> | ^~~~~~~~~~~
> pg_locale_libc.c:178:16: note: in expansion of macro ‘iswdigit_l’
> 178 | return iswdigit_l((wint_t) wc, locale->info.lt);
> | ^~~~~~~~~~

It looks like version 12 of mingw-w64-x86-64-dev, currently shipping
in Debian trixie and sid, must have broken something that worked in
version 8 from bullseye.  Several different headers apparently compete
to provide that family of functions, with a common guard
_WCTYPE_DEFINED:

https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/ctype.h
https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/wchar.h
https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/wctype.h

I suspect that if you define _CTYPE_DISABLE_MACROS (for example in
CPPFLAGS) then it might work.  Assuming <ctype.h> wins (I guess so,
it's included at the top of port.h), then I suppose it must use this
definition, hiding the function of the same name:

#define _iswdigit_l(_c,_p) (_iswctype_l(_c,_DIGIT,_p))

But _iswctype_l is only declared if:

#if __MSVCRT_VERSION__ >= 0x800

It looks like the default __MSVCRT_VERSION__ is 0x700
(/usr/x86_64-w64-mingw32/include/_mingw.h).  Hmm, so does UCRT
make the problem go away?  We wanted to do that already -- see
pgql-bugs #18940.  Try installing gcc-mingw-w64-ucrt64 and
g++-mingw-w64-ucrt64 on the CI image, and changing the compilers like
this, perhaps?

-        CC="ccache x86_64-w64-mingw32-gcc" \
-        CXX="ccache x86_64-w64-mingw32-g++"
+        CC="ccache x86_64-w64-mingw32ucrt-gcc" \
+        CXX="ccache x86_64-w64-mingw32ucrt-g++"



Re: MinGW cross compilation failure on Debian trixie

От
Andres Freund
Дата:
Hi,

On 2025-09-20 00:51:55 +1200, Thomas Munro wrote:
> On Fri, Sep 19, 2025 at 8:13 PM Nazir Bilal Yavuz <byavuz81@gmail.com> wrote::
> > pg_locale_libc.c: In function ‘wc_isdigit_libc_mb’:
> > ../../../../src/include/port/win32_port.h:438:20: error: implicit
> > declaration of function ‘_iswctype_l’; did you mean ‘_isctype_l’?
> > [-Wimplicit-function-declaration]
> > 438 | #define iswdigit_l _iswdigit_l
> > | ^~~~~~~~~~~
> > pg_locale_libc.c:178:16: note: in expansion of macro ‘iswdigit_l’
> > 178 | return iswdigit_l((wint_t) wc, locale->info.lt);
> > | ^~~~~~~~~~
> 
> It looks like version 12 of mingw-w64-x86-64-dev, currently shipping
> in Debian trixie and sid, must have broken something that worked in
> version 8 from bullseye.  Several different headers apparently compete
> to provide that family of functions, with a common guard
> _WCTYPE_DEFINED:
> 
> https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/ctype.h
> https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/wchar.h
> https://github.com/mingw-w64/mingw-w64/blob/v12.x/mingw-w64-headers/crt/wctype.h
> 
> I suspect that if you define _CTYPE_DISABLE_MACROS (for example in
> CPPFLAGS) then it might work.  Assuming <ctype.h> wins (I guess so,
> it's included at the top of port.h), then I suppose it must use this
> definition, hiding the function of the same name:
> 
> #define _iswdigit_l(_c,_p) (_iswctype_l(_c,_DIGIT,_p))
> 
> But _iswctype_l is only declared if:
> 
> #if __MSVCRT_VERSION__ >= 0x800
> 
> It looks like the default __MSVCRT_VERSION__ is 0x700
> (/usr/x86_64-w64-mingw32/include/_mingw.h).  Hmm, so does UCRT
> make the problem go away?

Yes, I actually just got this far - if I add -D_UCRT the build
succeeds. That's not the right actual solution, but confirms this much.


> We wanted to do that already -- see pgql-bugs #18940.  Try installing
> gcc-mingw-w64-ucrt64 and g++-mingw-w64-ucrt64 on the CI image, and changing
> the compilers like this, perhaps?
> 
> -        CC="ccache x86_64-w64-mingw32-gcc" \
> -        CXX="ccache x86_64-w64-mingw32-g++"
> +        CC="ccache x86_64-w64-mingw32ucrt-gcc" \
> +        CXX="ccache x86_64-w64-mingw32ucrt-g++"

The "--host=x86_64-w64-mingw32" would need to be adjusted too. The only reason
we also specify CC/CXX explicitly is to use ccache...

Switching to the ucrt binaries does fix the build with meson on debian
unstable, fwiw.  Nice.

Greetings,

Andres Freund