Skip to content

Commit c47fbeb

Browse files
committed
[WinRT] Start exposing Windows Runtime headers to Swift
This adds an initial Clang modulemap for the WinRT module. The modulemap is injected into the `winrt/` include search path using VFS. For now, the modulemap only exposes a small number of utility headers from WinRT. It will be extended in the future to cover more of the WinRT API surface.
1 parent bc88160 commit c47fbeb

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

Runtimes/Overlay/Windows/clang/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ roots:
2525
- name: module.modulemap
2626
type: file
2727
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk_shared.modulemap"
28+
- name: "@WindowsSdkDir@/Include/@WindowsSDKVersion@/winrt"
29+
type: directory
30+
contents:
31+
- name: module.modulemap
32+
type: file
33+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/WinRT.modulemap"
2834
- name: "@UniversalCRTSdkDir@/Include/@UCRTVersion@/ucrt"
2935
type: directory
3036
contents:
@@ -55,4 +61,5 @@ install(FILES
5561
vcruntime.modulemap
5662
winsdk_um.modulemap
5763
winsdk_shared.modulemap
64+
WinRT.modulemap
5865
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})

Runtimes/Resync.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ copy_files(public/Platform Overlay/Windows/clang
160160
ucrt.modulemap
161161
winsdk_um.modulemap
162162
winsdk_shared.modulemap
163+
WinRT.modulemap
163164
vcruntime.modulemap
164165
vcruntime.apinotes)
165166

lib/ClangImporter/ClangIncludePaths.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@ void GetWindowsFileMappings(
506506
if (!AuxiliaryFile.empty())
507507
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
508508
AuxiliaryFile);
509+
510+
llvm::sys::path::remove_filename(WinSDKInjection);
511+
llvm::sys::path::remove_filename(WinSDKInjection);
512+
llvm::sys::path::append(WinSDKInjection, "winrt", "module.modulemap");
513+
AuxiliaryFile =
514+
GetPlatformAuxiliaryFile("windows", "WinRT.modulemap", SearchPathOpts);
515+
if (!AuxiliaryFile.empty())
516+
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
517+
AuxiliaryFile);
509518
}
510519

511520
struct {

stdlib/cmake/WindowsVFS.yaml.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ roots:
1515
- name: module.modulemap
1616
type: file
1717
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk_shared.modulemap"
18+
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\winrt"
19+
type: directory
20+
contents:
21+
- name: module.modulemap
22+
type: file
23+
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\WinRT.modulemap"
1824
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\ucrt"
1925
type: directory
2026
contents:

stdlib/public/Platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ if(WINDOWS IN_LIST SWIFT_SDKS)
469469
vcruntime.modulemap
470470
winsdk_um.modulemap
471471
winsdk_shared.modulemap
472+
WinRT.modulemap
472473
DESTINATION "share"
473474
COMPONENT sdk-overlay)
474475
endif()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module WinRT [system] {
2+
link "WindowsApp.lib"
3+
export *
4+
5+
module Base {
6+
header "WinRTBase.h"
7+
export *
8+
}
9+
10+
module _HSTRING {
11+
header "hstring.h"
12+
export *
13+
}
14+
15+
module RoAPI {
16+
header "roapi.h"
17+
export *
18+
}
19+
}

test/stdlib/WinRT_HSTRING.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-build-swift %s
2+
// REQUIRES: OS=windows-msvc
3+
4+
// Make sure that importing WinRT brings in the HSTRING type.
5+
6+
import WinRT
7+
8+
public func usesHSTRING(_ x: HSTRING) {}

0 commit comments

Comments
 (0)