Skip to content

Commit d154f8f

Browse files
committed
[WinSDK] Modularize <guiddef.h>
This fixes modularization errors that arise when importing a C++ header that contains `#include <guiddef.h>`, which might hijack this header from the WinSDK module where it belongs.
1 parent 521c2ce commit d154f8f

File tree

8 files changed

+54
-0
lines changed

8 files changed

+54
-0
lines changed

Runtimes/Overlay/Windows/clang/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ roots:
1919
- name: module.modulemap
2020
type: file
2121
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk.modulemap"
22+
- name: "@WindowsSdkDir@/Include/@WindowsSDKVersion@/shared"
23+
type: directory
24+
contents:
25+
- name: module.modulemap
26+
type: file
27+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk_shared.modulemap"
2228
- name: "@UniversalCRTSdkDir@/Include/@UCRTVersion@/ucrt"
2329
type: directory
2430
contents:
@@ -48,4 +54,5 @@ install(FILES
4854
vcruntime.apinotes
4955
vcruntime.modulemap
5056
winsdk.modulemap
57+
winsdk_shared.modulemap
5158
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})

Runtimes/Resync.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ copy_files(public/Platform Overlay/Windows/clang
159159
FILES
160160
ucrt.modulemap
161161
winsdk.modulemap
162+
winsdk_shared.modulemap
162163
vcruntime.modulemap
163164
vcruntime.apinotes)
164165

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,17 @@ void GetWindowsFileMappings(
493493
if (!AuxiliaryFile.empty())
494494
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
495495
AuxiliaryFile);
496+
497+
if (WindowsSDK.MajorVersion > 8) {
498+
llvm::sys::path::remove_filename(WinSDKInjection);
499+
llvm::sys::path::remove_filename(WinSDKInjection);
500+
llvm::sys::path::append(WinSDKInjection, "shared", "module.modulemap");
501+
AuxiliaryFile = GetPlatformAuxiliaryFile(
502+
"windows", "winsdk_shared.modulemap", SearchPathOpts);
503+
if (!AuxiliaryFile.empty())
504+
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
505+
AuxiliaryFile);
506+
}
496507
}
497508

498509
struct {

stdlib/cmake/WindowsVFS.yaml.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ roots:
99
- name: module.modulemap
1010
type: file
1111
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk.modulemap"
12+
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\shared"
13+
type: directory
14+
contents:
15+
- name: module.modulemap
16+
type: file
17+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk_shared.modulemap"
1218
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\ucrt"
1319
type: directory
1420
contents:

stdlib/public/Platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ if(WINDOWS IN_LIST SWIFT_SDKS)
468468
vcruntime.apinotes
469469
vcruntime.modulemap
470470
winsdk.modulemap
471+
winsdk_shared.modulemap
471472
DESTINATION "share"
472473
COMPONENT sdk-overlay)
473474
endif()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===--- WinSDK_Shared.modulemap ------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
module _GUID {
14+
header "guiddef.h"
15+
export *
16+
}

stdlib/public/Windows/WinSDK.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import ucrt
14+
#if canImport(_GUID)
15+
@_exported import _GUID
16+
#endif
1417
@_exported import WinSDK // Clang module
1518

1619
// WinBase.h

test/stdlib/WinSDK_GUID.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-build-swift %s
2+
// REQUIRES: OS=windows-msvc
3+
4+
// Make sure that importing WinSDK brings in the GUID type, which is declared in
5+
// /shared and not in /um.
6+
7+
import WinSDK
8+
9+
public func usesGUID(_ x: GUID) {}

0 commit comments

Comments
 (0)