Skip to content

Commit 28f9db7

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 28f9db7

File tree

9 files changed

+60
-10
lines changed

9 files changed

+60
-10
lines changed

Runtimes/Overlay/Windows/clang/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ roots:
1818
contents:
1919
- name: module.modulemap
2020
type: file
21-
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk.modulemap"
21+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk_um.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:
@@ -47,5 +53,6 @@ install(FILES
4753
ucrt.modulemap
4854
vcruntime.apinotes
4955
vcruntime.modulemap
50-
winsdk.modulemap
56+
winsdk_um.modulemap
57+
winsdk_shared.modulemap
5158
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})

Runtimes/Resync.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ message(STATUS "Windows modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT
158158
copy_files(public/Platform Overlay/Windows/clang
159159
FILES
160160
ucrt.modulemap
161-
winsdk.modulemap
161+
winsdk_um.modulemap
162+
winsdk_shared.modulemap
162163
vcruntime.modulemap
163164
vcruntime.apinotes)
164165

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,23 @@ void GetWindowsFileMappings(
482482
WindowsSDK.Path, WindowsSDK.MajorVersion,
483483
WindowsSDK.IncludeVersion,
484484
WindowsSDK.LibraryVersion)) {
485+
assert(WindowsSDK.MajorVersion > 8);
485486
llvm::SmallString<261> WinSDKInjection{WindowsSDK.Path};
486487
llvm::sys::path::append(WinSDKInjection, "Include");
487-
if (WindowsSDK.MajorVersion > 8)
488-
llvm::sys::path::append(WinSDKInjection, WindowsSDK.IncludeVersion, "um");
488+
llvm::sys::path::append(WinSDKInjection, WindowsSDK.IncludeVersion, "um");
489489
llvm::sys::path::append(WinSDKInjection, "module.modulemap");
490490

491-
AuxiliaryFile =
492-
GetPlatformAuxiliaryFile("windows", "winsdk.modulemap", SearchPathOpts);
491+
AuxiliaryFile = GetPlatformAuxiliaryFile("windows", "winsdk_um.modulemap",
492+
SearchPathOpts);
493+
if (!AuxiliaryFile.empty())
494+
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
495+
AuxiliaryFile);
496+
497+
llvm::sys::path::remove_filename(WinSDKInjection);
498+
llvm::sys::path::remove_filename(WinSDKInjection);
499+
llvm::sys::path::append(WinSDKInjection, "shared", "module.modulemap");
500+
AuxiliaryFile = GetPlatformAuxiliaryFile(
501+
"windows", "winsdk_shared.modulemap", SearchPathOpts);
493502
if (!AuxiliaryFile.empty())
494503
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
495504
AuxiliaryFile);

stdlib/cmake/WindowsVFS.yaml.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ roots:
88
contents:
99
- name: module.modulemap
1010
type: file
11-
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk.modulemap"
11+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk_um.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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ if(WINDOWS IN_LIST SWIFT_SDKS)
467467
ucrt.modulemap
468468
vcruntime.apinotes
469469
vcruntime.modulemap
470-
winsdk.modulemap
470+
winsdk_um.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/Platform/winsdk.modulemap renamed to stdlib/public/Platform/winsdk_um.modulemap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- WinSDK.modulemap -------------------------------------------------===//
1+
//===--- WinSDK_UM.modulemap ----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//

stdlib/public/Windows/WinSDK.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import ucrt
14+
@_exported import _GUID
1415
@_exported import WinSDK // Clang module
1516

1617
// 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)