Skip to content

Commit 74ed041

Browse files
authored
Merge pull request #73247 from eeckstein/windows-enable-swift
Enable SwiftCompilerSources on Windows
2 parents fca4bef + dcf27a1 commit 74ed041

28 files changed

+109
-4
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,18 @@ option(SWIFT_ENABLE_BACKTRACING
736736
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST "14.5" CACHE STRING
737737
"Minimum deployment target version for macCatalyst")
738738

739+
# A tempoarary hack: force enabling HOSTTOOLS mode on Windows.
740+
# Right now, SwiftCompilerSources cannot be enabled for lldb because on Windows
741+
# swift and lldb are built in a unified build and there is a missing dependency
742+
# on swiftrt.
743+
# Swift and lldb are configured with the same cmake invocation and therefore
744+
# enabling bootstrapping for swift and disabling it for lldb only works by
745+
# hardcoding the bootstrapping mode in the cmake file.
746+
# https://github.com/apple/swift/issues/73322
747+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
748+
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
749+
endif()
750+
739751
#
740752
# End of user-configurable options.
741753
#
@@ -904,6 +916,10 @@ if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
904916
# This is the normal case. We are not cross-compiling.
905917
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
906918
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
919+
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
920+
message(WARNING "BOOSTRAPPING set to OFF because no Swift compiler is defined")
921+
set(BOOTSTRAPPING_MODE "OFF")
922+
endif()
907923
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
908924
# If cross-compiling, we don't have to bootstrap. We can just use the previously
909925
# built native swiftc to build the swift compiler modules.

SwiftCompilerSources/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function(add_swift_compiler_modules_library name)
106106
"-Xcc" "-std=c++17"
107107
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"
108108
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
109+
109110
# Prior to 5.9, we have to use the experimental flag for C++ interop.
110111
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
111112
list(APPEND swift_compile_options "-Xfrontend" "-enable-experimental-cxx-interop")
@@ -167,7 +168,17 @@ function(add_swift_compiler_modules_library name)
167168
# under `include/swift`. These are either located next to the compiler (in case of open source toolchains) or
168169
# in the SDK (in case a Swift compiler from Xcode)
169170
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
170-
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
171+
172+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
173+
list(APPEND swift_compile_options "-static")
174+
list(APPEND sdk_option "-sdk" "${SWIFT_PATH_TO_SWIFT_SDK}")
175+
176+
# Workaround a crash in the LoadableByAddress pass
177+
# https://github.com/apple/swift/issues/73254
178+
list(APPEND swift_compile_options "-Xllvm" "-sil-disable-pass=loadable-address")
179+
else()
180+
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
181+
endif()
171182

172183
set(all_obj_files)
173184
set(all_module_targets)

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
@_exported import BasicBridging
14-
import CxxStdlib
1514

1615
/// The assert function to be used in the compiler.
1716
///
@@ -52,6 +51,9 @@ public extension NoReflectionChildren {
5251
var customMirror: Mirror { Mirror(self, children: []) }
5352
}
5453

54+
#if !os(Windows)
55+
// TODO: https://github.com/apple/swift/issues/73252
56+
5557
public var standardError = CFileStream(fp: stderr)
5658

5759
#if os(Android) || canImport(Musl)
@@ -72,6 +74,8 @@ public struct CFileStream: TextOutputStream {
7274
}
7375
}
7476

77+
#endif
78+
7579
//===----------------------------------------------------------------------===//
7680
// StringRef
7781
//===----------------------------------------------------------------------===//

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ private struct DiagnoseDependence {
121121
}
122122

123123
func reportUnknown(operand: Operand) {
124+
#if !os(Windows)
125+
// TODO: https://github.com/apple/swift/issues/73252
124126
standardError.write("Unknown use: \(operand)\n\(function)")
127+
#endif
125128
reportEscaping(operand: operand)
126129
}
127130

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyConvertEscapeToNoEscape.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ private extension ConvertEscapeToNoEscapeInst {
2828
/// %3 = thin_to_thick_function %1 to $@noescape () -> ()
2929

3030
func tryCombineWithThinToThickOperand(_ context: SimplifyContext) {
31+
// compiling bridged.getFunctionTypeWithNoEscape crashes the 5.10 Windows compiler
32+
#if !os(Windows)
33+
// TODO: https://github.com/apple/swift/issues/73253
34+
3135
if let thinToThick = fromFunction as? ThinToThickFunctionInst {
3236
let builder = Builder(before: self, context)
3337
let noEscapeFnType = thinToThick.type.getFunctionType(withNoEscape: true)
@@ -36,5 +40,6 @@ private extension ConvertEscapeToNoEscapeInst {
3640
uses.replaceAll(with: newThinToThick, context)
3741
context.erase(instruction: self)
3842
}
43+
#endif
3944
}
4045
}

SwiftCompilerSources/Sources/Optimizer/Utilities/Test.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ private func functionTestThunk(
197197
let invocation = castToInvocation(fromOpaquePointer: erasedInvocation)
198198
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
199199
invocation(function.function, arguments.native, context)
200+
#if !os(Windows)
201+
// TODO: https://github.com/apple/swift/issues/73252
200202
fflush(stdout)
203+
#endif
201204
}
202205

203206
/// Bitcast a thin test closure to void *.

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ public struct Type : CustomStringConvertible, NoReflectionChildren {
142142
return idx >= 0 ? idx : nil
143143
}
144144

145+
// compiling bridged.getFunctionTypeWithNoEscape crashes the 5.10 Windows compiler
146+
#if !os(Windows)
147+
// TODO: https://github.com/apple/swift/issues/73253
145148
public func getFunctionType(withNoEscape: Bool) -> Type {
146149
bridged.getFunctionTypeWithNoEscape(withNoEscape).type
147150
}
151+
#endif
148152

149153
public var description: String {
150154
String(taking: bridged.getDebugDescription())

test/AutoDiff/SILOptimizer/vjp_and_pullback_inlining.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// REQUIRES: asserts
66
// REQUIRES: swift_in_compiler
7+
// UNSUPPORTED: OS=windows-msvc
78

89
import _Differentiation
910
#if canImport(Glibc)

test/IRGen/linker_set_low_level_exec.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// REQUIRES: executable_test
44
// REQUIRES: swift_in_compiler
55

6+
// https://github.com/apple/swift/issues/73321
7+
// UNSUPPORTED: OS=windows-msvc
8+
69
@_used
710
#if canImport(Darwin)
811
@_section("__TEXT,__mysection")

test/IRGen/loadable_by_address_address_assignment.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// RUN: %target-swift-frontend %s -O -Xllvm -sil-print-after=loadable-address -c -o %t/t.o 2>&1 | %FileCheck %s
22

3-
// XFAIL: OS=windows-msvc
4-
53
public struct LargeThing {
64
var s0 : String = ""
75
var s1 : String = ""

0 commit comments

Comments
 (0)