From b62eafd86610d75af6cafb0002915eb54646ff1d Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 6 Aug 2024 11:32:27 -0700 Subject: [PATCH 1/2] [windows] split out complex module from ucrt module, to allow new swift-foundation to import ucrt when C++ interoperability is enabled Fixes https://github.com/swiftlang/swift/issues/75691 --- stdlib/public/Platform/ucrt.modulemap | 13 +++++-------- stdlib/public/Platform/ucrt.swift | 2 ++ .../Cxx/stdlib/foundation-and-std-module.swift | 4 +--- test/stdlib/CRT.swift | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 test/stdlib/CRT.swift diff --git a/stdlib/public/Platform/ucrt.modulemap b/stdlib/public/Platform/ucrt.modulemap index 68bcbfeddfeec..ad440863ad8c6 100644 --- a/stdlib/public/Platform/ucrt.modulemap +++ b/stdlib/public/Platform/ucrt.modulemap @@ -10,16 +10,13 @@ // //===----------------------------------------------------------------------===// +module _complex [system] { + header "complex.h" + export * +} + module ucrt [system] { module C { - module complex { - /* disallow the header in C++ mode as it forwards to `ccomplex`. */ - requires !cplusplus - - header "complex.h" - export * - } - module ctype { header "ctype.h" export * diff --git a/stdlib/public/Platform/ucrt.swift b/stdlib/public/Platform/ucrt.swift index 80181db44d5cf..09eaf11c9ab3d 100644 --- a/stdlib/public/Platform/ucrt.swift +++ b/stdlib/public/Platform/ucrt.swift @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// @_exported import ucrt // Clang module +// Extra clang module that's split out from ucrt: +@_exported import _complex @available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") public let M_PI = Double.pi diff --git a/test/Interop/Cxx/stdlib/foundation-and-std-module.swift b/test/Interop/Cxx/stdlib/foundation-and-std-module.swift index 8dcc93b45c710..29d05d94e1462 100644 --- a/test/Interop/Cxx/stdlib/foundation-and-std-module.swift +++ b/test/Interop/Cxx/stdlib/foundation-and-std-module.swift @@ -3,14 +3,12 @@ // RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t // RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -// RUN: find %t | %FileCheck %s - // RUN: %empty-directory(%t) // RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB // RUN: %target-swift-frontend %s -c -enable-experimental-cxx-interop -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB -// REQUIRES: OS=macosx || OS=linux-gnu +// RUN: %{python} -c "import os, glob; print('\n'.join(glob.glob(os.path.join('%/t', '**', '*.pcm'), recursive=True)))" | %FileCheck %s #if canImport(Foundation) import Foundation diff --git a/test/stdlib/CRT.swift b/test/stdlib/CRT.swift new file mode 100644 index 0000000000000..8e43547d94915 --- /dev/null +++ b/test/stdlib/CRT.swift @@ -0,0 +1,17 @@ +// RUN: %target-run-simple-swift %t +// REQUIRES: executable_test +// REQUIRES: OS=windows-msvc + +// This file has CRT-specific C stdlib tests, that use +// some APIs present only in CRT. + +import StdlibUnittest +import CRT + +var CRTTests = TestSuite("CRT") + +CRTTests.test("complex functions available in Swift") { + let complexValue = _Cbuild(1.0, 2.0) // Construct a complex double using MSVC-specific API. + let re = creal(complexValue) + expectEqual(re, 1.0) +} From cecd4c050bdcf3b9ef728a781a2703a8727328a1 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 8 Aug 2024 09:43:48 -0700 Subject: [PATCH 2/2] Fixup the CRT api test --- test/stdlib/CRT.swift | 17 ----------------- test/stdlib/CRTWinAPIs.swift | 12 ++++++++++++ 2 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 test/stdlib/CRT.swift create mode 100644 test/stdlib/CRTWinAPIs.swift diff --git a/test/stdlib/CRT.swift b/test/stdlib/CRT.swift deleted file mode 100644 index 8e43547d94915..0000000000000 --- a/test/stdlib/CRT.swift +++ /dev/null @@ -1,17 +0,0 @@ -// RUN: %target-run-simple-swift %t -// REQUIRES: executable_test -// REQUIRES: OS=windows-msvc - -// This file has CRT-specific C stdlib tests, that use -// some APIs present only in CRT. - -import StdlibUnittest -import CRT - -var CRTTests = TestSuite("CRT") - -CRTTests.test("complex functions available in Swift") { - let complexValue = _Cbuild(1.0, 2.0) // Construct a complex double using MSVC-specific API. - let re = creal(complexValue) - expectEqual(re, 1.0) -} diff --git a/test/stdlib/CRTWinAPIs.swift b/test/stdlib/CRTWinAPIs.swift new file mode 100644 index 0000000000000..07e8fb54054c7 --- /dev/null +++ b/test/stdlib/CRTWinAPIs.swift @@ -0,0 +1,12 @@ +// RUN: %target-typecheck-verify-swift +// REQUIRES: OS=windows-msvc + +// This file has CRT-specific C stdlib tests, that use +// some APIs present only in CRT. + +import CRT + +func complexFunctionsAvailableInSwift() { + let complexValue = _Cbuild(1.0, 2.0) // Construct a complex double using MSVC-specific API. + let _ = creal(complexValue) +}