Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Runtimes/Overlay/Windows/clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ roots:
- name: module.modulemap
type: file
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/winsdk_shared.modulemap"
- name: "@WindowsSdkDir@/Include/@WindowsSDKVersion@/winrt"
type: directory
contents:
- name: module.modulemap
type: file
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/WinRT.modulemap"
- name: "@UniversalCRTSdkDir@/Include/@UCRTVersion@/ucrt"
type: directory
contents:
Expand Down Expand Up @@ -55,4 +61,5 @@ install(FILES
vcruntime.modulemap
winsdk_um.modulemap
winsdk_shared.modulemap
WinRT.modulemap
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR})
1 change: 1 addition & 0 deletions Runtimes/Resync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ copy_files(public/Platform Overlay/Windows/clang
ucrt.modulemap
winsdk_um.modulemap
winsdk_shared.modulemap
WinRT.modulemap

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

winsdk_winrt seems like a more consistent name? it would be ideal to import WinSDK.WinRT as opposed to import WinRT. the latter can cause lots of collisions with other WINMD based projection tools which will generate code in the WinRT module

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is WinRT considered part of the Win32 SDK? I thought it was a separate parallel piece. The submodule support isn't sufficient to support that in Swift I think? So this will need to be a top-level module.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is just the "Windows SDK" . the distinction between Win32 and WinRT are the APIs used. but since the module is called WinSDK it seems appropriate to keep them all together? if WinSDK was named Win32 i would feel differently

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are other submodules in WinSDK, so that should be fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WinRT can't be a submodule of WinSDK mostly for build performance reasons. WinRT headers are huge, for instance for WinUI headers alone Clang produces a .pcm that is 300MB+ and takes over 10 minutes to precompile on my machine (with weak specs). Clang builds .pcms per top-level module, so all submodules are effectively merged into one. Similarly, Swift merges all submodules into a single module when importing them. That means that for a project that only uses Win32, clang would spend significant time prebuilding WinRT headers, and then Swift would spend time importing WinRT decls into Swift.

For this reason, I'm going to propose splitting WinRT headers into many top-level modules, e.g. having a top-level module WindowsXyz per windows.xyz.*.h. But that is out of scope of this PR ;)

the latter can cause lots of collisions with other WINMD based projection tools which will generate code in the WinRT module

Is WinRT a conventional name for some of the modules that are generated by other tools?

vcruntime.modulemap
vcruntime.apinotes)

Expand Down
9 changes: 9 additions & 0 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ void GetWindowsFileMappings(
if (!AuxiliaryFile.empty())
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
AuxiliaryFile);

llvm::sys::path::remove_filename(WinSDKInjection);
llvm::sys::path::remove_filename(WinSDKInjection);
llvm::sys::path::append(WinSDKInjection, "winrt", "module.modulemap");
AuxiliaryFile =
GetPlatformAuxiliaryFile("windows", "WinRT.modulemap", SearchPathOpts);
if (!AuxiliaryFile.empty())
fileMapping.redirectedFiles.emplace_back(std::string(WinSDKInjection),
AuxiliaryFile);
}

struct {
Expand Down
6 changes: 6 additions & 0 deletions stdlib/cmake/WindowsVFS.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ roots:
- name: module.modulemap
type: file
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\winsdk_shared.modulemap"
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\winrt"
type: directory
contents:
- name: module.modulemap
type: file
external-contents: "@PROJECT_SOURCE_DIR@\\public\\Platform\\WinRT.modulemap"
- name: "@UniversalCRTSdkDir@\\Include\\@UCRTVersion@\\ucrt"
type: directory
contents:
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ if(WINDOWS IN_LIST SWIFT_SDKS)
vcruntime.modulemap
winsdk_um.modulemap
winsdk_shared.modulemap
WinRT.modulemap
DESTINATION "share"
COMPONENT sdk-overlay)
endif()
Expand Down
31 changes: 31 additions & 0 deletions stdlib/public/Platform/WinRT.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===--- WinRT.modulemap --------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

module WinRT [system] {
link "WindowsApp.lib"
export *

module Base {
header "WinRTBase.h"
export *
}

module hstring {
header "hstring.h"
export *
}

module RoAPI {
header "roapi.h"
export *
}
}
8 changes: 8 additions & 0 deletions test/stdlib/WinRT_HSTRING.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-build-swift %s
// REQUIRES: OS=windows-msvc

// Make sure that importing WinRT brings in the HSTRING type.

import WinRT

public func usesHSTRING(_ x: HSTRING) {}