Skip to content

Commit c3074df

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 c3074df

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- WinRT.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 WinRT [system] {
14+
link "WindowsApp.lib"
15+
export *
16+
17+
module Base {
18+
header "WinRTBase.h"
19+
export *
20+
}
21+
22+
module hstring {
23+
header "hstring.h"
24+
export *
25+
}
26+
27+
module RoAPI {
28+
header "roapi.h"
29+
export *
30+
}
31+
}

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)