Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefinition error in windows.foundation.h #22160

Open
4 of 6 tasks
raedrizqie opened this issue Oct 11, 2024 · 13 comments
Open
4 of 6 tasks

Redefinition error in windows.foundation.h #22160

raedrizqie opened this issue Oct 11, 2024 · 13 comments

Comments

@raedrizqie
Copy link
Contributor

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

  • MINGW64
  • MINGW32
  • UCRT64
  • CLANG64
  • CLANGARM64

Are you willing to submit a PR?

No response

@cgutman
Copy link

cgutman commented Oct 12, 2024

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 mingw-w64/mingw-w64@77eaa95 which added interface Windows.Foundation.IReference<boolean>

@Biswa96
Copy link
Member

Biswa96 commented Oct 12, 2024

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

@zzhiyi
Copy link

zzhiyi commented Oct 12, 2024

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
Copy link

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

@Biswa96
Copy link
Member

Biswa96 commented Oct 12, 2024

It's in windows.foundation.idl

@raedrizqie
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor

lhmouse commented Oct 14, 2024

[19:37:14] <lh_ideapad> 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] <lh_ideapad> 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] <lh_ideapad> the second one is incorrect. the GUID 3c00fd60-2950-5939-a21a-2d12c5a01b8a belongs to IReference<Boolean>.
[19:40:17] <lh_ideapad> IReference<boolean> shall be the same as IReference<BYTE>; it's a redeclaration and no class should be generated.

dlech added a commit to dlech/pywinrt that referenced this issue Oct 19, 2024
dlech added a commit to pywinrt/pywinrt that referenced this issue Oct 19, 2024
@Biswa96
Copy link
Member

Biswa96 commented Oct 22, 2024

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<unsigned char>'
 12242 |             IReference<boolean > : IReference_impl<boolean >
       |             ^~~~~~~~~~~~~~~~~~~~
mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:10534:13: note: previous definition is here
 10534 |             IReference<BYTE > : IReference_impl<BYTE >
       |             ^
mozilla/clang/bin/../x86_64-w64-mingw32/include/windows.foundation.h:12250:1: error: redefinition of '__mingw_uuidof_s<ABI::Windows::Foundation::IReference<BYTE>>'
 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<type> {                   \
      |                       ^~~~~~~~~~~~~~~~~~~~~~
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<type> {                   \
      |                       ^
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<ABI::Windows::Foundation::IReference<BYTE>>'
 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<type>() {    \
      |                                      ^
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<type>() {    \
      |                                      ^
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<ABI::Windows::Foundation::IReference<BYTE> *>'
 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<type*>() {   \
      |                                      ^
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<type*>() {   \
      |                                      ^

@lhmouse
Copy link
Contributor

lhmouse commented Oct 22, 2024

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
Copy link
Contributor Author

nodejs is also affected by this bug

@Biswa96
Copy link
Member

Biswa96 commented Oct 27, 2024

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

@Biswa96
Copy link
Member

Biswa96 commented Nov 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants