On 2026/10/09 11:03, Trevor Gross wrote:
> On Aug 5, 2026, 3:18 AM, Zhongteng Gui <[email protected]> wrote:
>> [...]
>> diff --git a/gcc/config.gcc b/gcc/config.gcc
>> index 8fe99616f82..55339363c6c 100644
>> --- a/gcc/config.gcc
>> +++ b/gcc/config.gcc
>> @@ -1331,7 +1331,6 @@ aarch64-*-mingw*)
>>      tm_file="${tm_file} mingw/winnt-dll.h"
>>      tmake_file="${tmake_file} aarch64/t-aarch64"
>>      tmake_file="${tmake_file} aarch64/t-aarch64-mingw"
>> -        native_system_header_dir=/mingw/include
>>      target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
>>      target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt-dll.cc"
>>      extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
>> @@ -2339,7 +2338,6 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
>>                      tmake_file="${tmake_file} i386/t-mingw-w32"
>>                      ;;
>>      esac
>> -        native_system_header_dir=/mingw/include
>>      target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
>>      target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt-dll.cc"
>>      extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"
>> [...]
>> diff --git a/gcc/config/mingw/mingw32.h b/gcc/config/mingw/mingw32.h
>> index 1d319b77bf8..3afbee65974 100644
>> --- a/gcc/config/mingw/mingw32.h
>> +++ b/gcc/config/mingw/mingw32.h
>> @@ -231,17 +231,9 @@ along with GCC; see the file COPYING3.  If not see
>>    crtend.o%s"
>>
>>  /* Override startfile prefix defaults.  */
>> -#ifndef STANDARD_STARTFILE_PREFIX_1
>> -#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
>> +#if !defined(STANDARD_STARTFILE_PREFIX_2) && 
>> !defined(CROSS_DIRECTORY_STRUCTURE)
>> +#define STANDARD_STARTFILE_PREFIX_2 "" /* MSYS2 doesn't use /usr/lib for 
>> MINGW */
>>  #endif
>> -#ifndef STANDARD_STARTFILE_PREFIX_2
>> -#define STANDARD_STARTFILE_PREFIX_2 ""
>> -#endif
>> -
>> -/* For native mingw-version we need to take care that 
>> NATIVE_SYSTEM_HEADER_DIR
>> -   macro contains POSIX-style path.  See bug 52947.  */
>> -#undef NATIVE_SYSTEM_HEADER_DIR
>> -#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
>>
>>  /* Output STRING, a string representing a filename, to FILE.
>>     We canonicalize it to be in Unix format (backslashes are replaced
> 
> For what it's worth, I have been using the two similar but slightly
> different patches and have been able to bootstrap on Windows
> successfully, it doesn't work without them. I don't know enough about
> how these paths work to know what's best, though.

Actually, my patch above IS based on the older patch by mingwandroid. You can 
see the full evolution at
https://github.com/msys2/MINGW-packages/pull/29280, you can also find many 
other attempts I've tried here
(some are collapsed to make the overview cleaner).

This patch have already been used by MSYS2 for several months, and also shared 
to conda-forge, so I think
there's no problem that it bootstrap successfully for both pure MinGW-w64 (both 
host and target is MinGW-w64),
or completely cross MinGW-w64 (host is Linux/Darwin, target is MinGW-w64, 
tested by conda-forge's CI).

The remaining triplet to test is Cygwin-MinGW cross compiler. I'll try 
bootstrap it locally these days.

> 
> They're also on my branch at [1]. Disregard the patches changing output,
> that's an unsuccessful attempt to resolve [2].
> 
> [1]: 
> https://github.com/gcc-mirror/gcc/compare/master...tgross35:gcc:patch-win-build
> [2]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121943

IMHO this bug is unrelated to our patches? Though it'd be nice if it can be 
resolved one day,

> 
> ---
> 
>  From 750152814459ad56eeaac7de569378905cc0d24b Mon Sep 17 00:00:00 2001
> From: Trevor Gross <[email protected]>
> Date: Sat, 30 Aug 2025 16:09:38 -0400
> Subject: [PATCH] Fix the MinGW system prefix (send this upstream)
> 
> The current directory doesn't seem to exist, see [1].
> 
> [1]: 
> https://github.com/msys2/MINGW-packages/blob/5a23c744b85e58a624b3bc3ba0ba70669aebd305/mingw-w64-gcc/PKGBUILD#L192-L195
> ---
>   gcc/config/mingw/mingw32.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/config/mingw/mingw32.h b/gcc/config/mingw/mingw32.h
> index 1d319b77bf832..1b5e59399fdc9 100644
> --- a/gcc/config/mingw/mingw32.h
> +++ b/gcc/config/mingw/mingw32.h
> @@ -232,7 +232,7 @@ along with GCC; see the file COPYING3.  If not see
> 
>   /* Override startfile prefix defaults.  */
>   #ifndef STANDARD_STARTFILE_PREFIX_1
> -#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
> +#define STANDARD_STARTFILE_PREFIX_1 "C:/msys64/ucrt64/lib/"
>   #endif
>   #ifndef STANDARD_STARTFILE_PREFIX_2
>   #define STANDARD_STARTFILE_PREFIX_2 ""
> @@ -241,7 +241,7 @@ along with GCC; see the file COPYING3.  If not see
>   /* For native mingw-version we need to take care that 
> NATIVE_SYSTEM_HEADER_DIR
>      macro contains POSIX-style path.  See bug 52947.  */
>   #undef NATIVE_SYSTEM_HEADER_DIR
> -#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
> +#define NATIVE_SYSTEM_HEADER_DIR "C:/msys64/ucrt64/include"
> 
>   /* Output STRING, a string representing a filename, to FILE.
>      We canonicalize it to be in Unix format (backslashes are replaced
> 
> ---
> 
>  From 4c1ef30f26281168292cb5c8a45b5901fa2e9736 Mon Sep 17 00:00:00 2001
> From: Ray Donnelly <[email protected]>
> Date: Wed, 5 Aug 2015 23:36:11 +0100
> Subject: [PATCH] Windows: Don't ignore native system header dir
> 
> ---
>   gcc/config.gcc | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 036baa714d704..3224a052d36c7 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -2339,7 +2339,10 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
>                       tmake_file="${tmake_file} i386/t-mingw-w32"
>                       ;;
>       esac
> -        native_system_header_dir=/mingw/include
> +     # Don't ignore values passed in to configure via 
> --native-system-header-dir
> +     if test x$native_system_header_dir = x ; then
> +             native_system_header_dir=/mingw/include
> +     fi
>       target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt.cc"
>       target_gtfiles="$target_gtfiles \$(srcdir)/config/mingw/winnt-dll.cc"
>       extra_options="${extra_options} mingw/cygming.opt mingw/mingw.opt"

The main shortage of these 2 patches (mainly from original MSYS2) is that it 
hardcodes the
build directory (C:/msys64/ucrt64), so this can't be upstreamed, espcially the 
first one (because
even MSYS2 itself uses not only ucrt64 but also mingw64 and mingw32. and the CI 
prefix is D:/M, not
C:/msys64).

Reply via email to