diff --git a/Runtimes/Overlay/Windows/clang/CMakeLists.txt b/Runtimes/Overlay/Windows/clang/CMakeLists.txt index 1d88b8ed024ad..4118d42dfe32b 100644 --- a/Runtimes/Overlay/Windows/clang/CMakeLists.txt +++ b/Runtimes/Overlay/Windows/clang/CMakeLists.txt @@ -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: @@ -55,4 +61,5 @@ install(FILES vcruntime.modulemap winsdk_um.modulemap winsdk_shared.modulemap + WinRT.modulemap DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}) diff --git a/Runtimes/Resync.cmake b/Runtimes/Resync.cmake index 9b93b807e85a2..400b4f8131a15 100644 --- a/Runtimes/Resync.cmake +++ b/Runtimes/Resync.cmake @@ -160,6 +160,7 @@ copy_files(public/Platform Overlay/Windows/clang ucrt.modulemap winsdk_um.modulemap winsdk_shared.modulemap + WinRT.modulemap vcruntime.modulemap vcruntime.apinotes) diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index 13fb11e164f96..5ce83f35acf23 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -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 { diff --git a/stdlib/cmake/WindowsVFS.yaml.in b/stdlib/cmake/WindowsVFS.yaml.in index 9a728125ebd74..c1bb9226745f9 100644 --- a/stdlib/cmake/WindowsVFS.yaml.in +++ b/stdlib/cmake/WindowsVFS.yaml.in @@ -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: diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index 083b5578eb42c..b7ec1975637ef 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -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() diff --git a/stdlib/public/Platform/WinRT.modulemap b/stdlib/public/Platform/WinRT.modulemap new file mode 100644 index 0000000000000..c1b4bc53e78cd --- /dev/null +++ b/stdlib/public/Platform/WinRT.modulemap @@ -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 * + } +} diff --git a/test/stdlib/WinRT_HSTRING.swift b/test/stdlib/WinRT_HSTRING.swift new file mode 100644 index 0000000000000..6f1c6b32148ae --- /dev/null +++ b/test/stdlib/WinRT_HSTRING.swift @@ -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) {}