msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

Redefinition error in windows.foundation.h #22160

Open raedrizqie opened 1 month ago

raedrizqie commented 1 month ago

Description / Steps to reproduce the issue

Got redefinition error when compiling qt6-webengine:

2024-10-10T10:10:44.2246546Z In file included from gen/base/base_jumbo_44.cc:7:
2024-10-10T10:10:44.2559932Z In file included from ./../../../../../qtwebengine-everywhere-src-6.7.2/src/3rdparty/chromium/base/time/time_win.cc:36:
2024-10-10T10:10:44.3191789Z D:/M/msys64/clang64/include/windows.foundation.h:11730:13: error: redefinition of 'IReference<unsigned char>'
2024-10-10T10:10:44.3681854Z  11730 |             IReference<boolean > : IReference_impl<boolean >
2024-10-10T10:10:44.4331546Z        |             ^~~~~~~~~~~~~~~~~~~~
2024-10-10T10:10:44.4559114Z D:/M/msys64/clang64/include/windows.foundation.h:10022:13: note: previous definition is here
2024-10-10T10:10:44.5218434Z  10022 |             IReference<BYTE > : IReference_impl<BYTE >
2024-10-10T10:10:44.5958990Z        |             ^
2024-10-10T10:10:44.6170092Z D:/M/msys64/clang64/include/windows.foundation.h:11738:1: error: redefinition of '__mingw_uuidof_s<ABI::Windows::Foundation::IReference<BYTE>>'
2024-10-10T10:10:44.6628143Z  11738 | __CRT_UUID_DECL(__FIReference_1_boolean, 0x3c00fd60, 0x2950, 0x5939, 0xa2,0x1a, 0x2d,0x12,0xc5,0xa0,0x1b,0x8a)
2024-10-10T10:10:44.7097306Z        | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-10-10T10:10:44.7572017Z D:/M/msys64/clang64/include/_mingw.h:534:23: note: expanded from macro '__CRT_UUID_DECL'
2024-10-10T10:10:44.7879347Z   534 |     template<> struct __mingw_uuidof_s<type> {                   \
2024-10-10T10:10:44.8657538Z       |                       ^~~~~~~~~~~~~~~~~~~~~~
2024-10-10T10:10:44.8971877Z D:/M/msys64/clang64/include/windows.foundation.h:10030:1: note: previous definition is here
2024-10-10T10:10:44.9127173Z  10030 | __CRT_UUID_DECL(__FIReference_1_BYTE, 0xe5198cc8, 0x2873, 0x55f5, 0xb0,0xa1, 0x84,0xff,0x9e,0x4a,0xad,0x62)
2024-10-10T10:10:44.9594902Z        | ^
2024-10-10T10:10:44.9908560Z D:/M/msys64/clang64/include/_mingw.h:534:23: note: expanded from macro '__CRT_UUID_DECL'
2024-10-10T10:10:45.0689448Z   534 |     template<> struct __mingw_uuidof_s<type> {                   \
2024-10-10T10:10:45.1157802Z       |                       ^

Expected behavior

Compiles without error.

Actual behavior

Compile error.

Verification

Windows Version

MINGW64_NT-10.0-19045

MINGW environments affected

Are you willing to submit a PR?

No response

cgutman commented 1 month ago

The colliding definitions are:

#ifdef __cplusplus
#define __FIReference_1_BYTE ABI::Windows::Foundation::IReference<BYTE >
#endif /* __cplusplus */

and

#ifdef __cplusplus
#define __FIReference_1_boolean ABI::Windows::Foundation::IReference<boolean >
#endif /* __cplusplus */

because boolean and BYTE are both typedefed to unsigned char.

This breakage was introduced by the change in windows.foundation.idl in https://github.com/mingw-w64/mingw-w64/commit/77eaa959e2a66abdf0893d4d6b187036a9d7ed52 which added interface Windows.Foundation.IReference<boolean>

Biswa96 commented 1 month ago

I have asked about this issue in the relevant upstream merge request https://gitlab.winehq.org/wine/wine/-/merge_requests/6594

zzhiyi commented 1 month ago

I don't think this is a bug in Wine. Native headers have both Windows.Foundation.IReference<BYTE> and Windows.Foundation.IReference<boolean> and no conflicts.

alvinhochun commented 1 month ago

windows.foundation.h in wInsdk does not have the string IReference at all from what I can see.

Biswa96 commented 1 month ago

It's in windows.foundation.idl

raedrizqie commented 1 month ago

it seems slightly different here, no?

struct __declspec(uuid("3c00fd60-2950-5939-a21a-2d12c5a01b8a"))
IReference<bool> : IReference_impl<ABI::Windows::Foundation::Internal::AggregateType<bool, boolean>> {
static const wchar_t* z_get_rc_name_impl() {
return L"Windows.Foundation.IReference`1<Boolean>"; }
};
typedef IReference<bool> __FIReference_1_boolean_t;
#define ____FIReference_1_boolean_FWD_DEFINED__
#define __FIReference_1_boolean ABI::Windows::Foundation::__FIReference_1_boolean_t

https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.14393.0/winrt/windows.foundation.h#L8895-L8902

alvinhochun commented 1 month ago

In both the latest winsdk 10.0.22621.0 and the 4-year-old winsdk 10.0.19041.0, windows.foundation.h does not contain IReference. 10.0.14393.0 is ancient at this point.

Frankly I don't quite understand how the different instantiations of IReference are being handled in the winsdk. It seems in the winsdk they are spread across different headers, practically being defined "on demand" only if a header file requires a specific instantiation (an example being windows.ui.xaml.controls.primitives.h).

However it is possible that we can ignore this difference here. Practically speaking, it doesn't matter as long as the generated definitions are actually correct...

...But it looks like the definition of IReference<boolean> is wrong. Instead of becoming

struct IReference<boolean > : IReference_impl<boolean >

it should become

struct IReference<bool> : IReference_impl<ABI::Windows::Foundation::Internal::AggregateType<bool, boolean>>

WinRT has a native boolean type which, according to https://learn.microsoft.com/en-us/windows/win32/winrt/base-data-types is supposed to be mapped to bool in C++. In fact, anything that uses boolean in the IDL probably needs special handling in WIDL.

I would argue interface Windows.Foundation.IReference<boolean> should be removed from the IDL until WIDL can handle it properly.

lhmouse commented 1 month ago

[19:37:14] WIDL generates GUID e5198cc8-2873-55f5-b0a1-84ff9e4aad62 for IReference<BYTE>, which matches IReference<byte> in windows.device.usb.h from Windows SDK. [19:38:17] WIDL also generates GUID 3c00fd60-2950-5939-a21a-2d12c5a01b8a for IReference<boolean>, which matches IReference<bool> in windows.media.import.h from Windows SDK. [19:39:34] the second one is incorrect. the GUID 3c00fd60-2950-5939-a21a-2d12c5a01b8a belongs to IReference<Boolean>. [19:40:17] IReference<boolean> shall be the same as IReference<BYTE>; it's a redeclaration and no class should be generated.

Biswa96 commented 1 month ago

Congrats! This issue breaks both Firefox and Chromium.

Click here to see the compiler error while cross-compiling gecko ``` In file included from mozilla/mozilla-unified/widget/windows/OSKInputPaneManager.cpp:13: In file included from mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.ui.viewmanagement.h:475: mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:12242:13: error: redefinition of 'IReference' 12242 | IReference : IReference_impl | ^~~~~~~~~~~~~~~~~~~~ mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:10534:13: note: previous definition is here 10534 | IReference : IReference_impl | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:12250:1: error: redefinition of '__mingw_uuidof_s>' 12250 | __CRT_UUID_DECL(__FIReference_1_boolean, 0x3c00fd60, 0x2950, 0x5939, 0xa2,0x1a, 0x2d,0x12,0xc5,0xa0,0x1b,0x8a) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:534:23: note: expanded from macro '__CRT_UUID_DECL' 534 | template<> struct __mingw_uuidof_s { \ | ^~~~~~~~~~~~~~~~~~~~~~ mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:10542:1: note: previous definition is here 10542 | __CRT_UUID_DECL(__FIReference_1_BYTE, 0xe5198cc8, 0x2873, 0x55f5, 0xb0,0xa1, 0x84,0xff,0x9e,0x4a,0xad,0x62) | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:534:23: note: expanded from macro '__CRT_UUID_DECL' 534 | template<> struct __mingw_uuidof_s { \ | ^ In file included from mozilla/mozilla-unified/widget/windows/OSKInputPaneManager.cpp:13: In file included from mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.ui.viewmanagement.h:475: mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:12250:1: error: redefinition of '__mingw_uuidof>' 12250 | __CRT_UUID_DECL(__FIReference_1_boolean, 0x3c00fd60, 0x2950, 0x5939, 0xa2,0x1a, 0x2d,0x12,0xc5,0xa0,0x1b,0x8a) | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:539:38: note: expanded from macro '__CRT_UUID_DECL' 539 | template<> constexpr const GUID &__mingw_uuidof() { \ | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:10542:1: note: previous definition is here 10542 | __CRT_UUID_DECL(__FIReference_1_BYTE, 0xe5198cc8, 0x2873, 0x55f5, 0xb0,0xa1, 0x84,0xff,0x9e,0x4a,0xad,0x62) | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:539:38: note: expanded from macro '__CRT_UUID_DECL' 539 | template<> constexpr const GUID &__mingw_uuidof() { \ | ^ In file included from mozilla/mozilla-unified/widget/windows/OSKInputPaneManager.cpp:13: In file included from mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.ui.viewmanagement.h:475: mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:12250:1: error: redefinition of '__mingw_uuidof *>' 12250 | __CRT_UUID_DECL(__FIReference_1_boolean, 0x3c00fd60, 0x2950, 0x5939, 0xa2,0x1a, 0x2d,0x12,0xc5,0xa0,0x1b,0x8a) | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:542:38: note: expanded from macro '__CRT_UUID_DECL' 542 | template<> constexpr const GUID &__mingw_uuidof() { \ | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:10542:1: note: previous definition is here 10542 | __CRT_UUID_DECL(__FIReference_1_BYTE, 0xe5198cc8, 0x2873, 0x55f5, 0xb0,0xa1, 0x84,0xff,0x9e,0x4a,0xad,0x62) | ^ mozilla/clang/bin/../x86_64-w64-mingw32/include/_mingw.h:542:38: note: expanded from macro '__CRT_UUID_DECL' 542 | template<> constexpr const GUID &__mingw_uuidof() { \ | ^ ```
lhmouse commented 1 month ago

I think that you can try patching WIDL. The quick, dirty and improper fix would be to tamper with the tokenizer so it treats boolean as BYTE.

raedrizqie commented 1 month ago

nodejs is also affected by this bug

Biswa96 commented 1 month ago

Would it be a proper workaround to remove the IReference<boolean> in the IDL file? I can create a PR to remove that.

Biswa96 commented 3 weeks ago

I have added a pull request to workaround the issue. The workaround will fail if IReference<boolean> is used in any other winrt IDL files.