Skip to content

Commit 06f277a

Browse files
committed
cmake: enable SwiftCompilerSources on Windows
1 parent 49dd95f commit 06f277a

File tree

10 files changed

+54
-1
lines changed

10 files changed

+54
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,17 @@ option(SWIFT_ENABLE_BACKTRACING
730730
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST "14.5" CACHE STRING
731731
"Minimum deployment target version for macCatalyst")
732732

733+
# A tempoarary hack: force enabling HOSTTOOLS mode on Windows.
734+
# Right now, SwiftCompilerSources cannot be enabled for lldb because the
735+
# Windows build script builds lldb before swift and that fails with a missing
736+
# dependency on swiftrt (which is built within swift).
737+
# Swift and lldb are configured with the same cmake invocation and therefore
738+
# enabling bootstrapping for swift and disabling it for lldb only works
739+
# by hardcoding the bootstrapping mode in the cmake file.
740+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
741+
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
742+
endif()
743+
733744
#
734745
# End of user-configurable options.
735746
#
@@ -898,6 +909,10 @@ if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
898909
# This is the normal case. We are not cross-compiling.
899910
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
900911
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
912+
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
913+
message(WARNING "BOOSTRAPPING set to OFF because no Swift compiler is defined")
914+
set(BOOTSTRAPPING_MODE "OFF")
915+
endif()
901916
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
902917
# If cross-compiling, we don't have to bootstrap. We can just use the previously
903918
# built native swiftc to build the swift compiler modules.

SwiftCompilerSources/CMakeLists.txt

Lines changed: 15 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,20 @@ 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+
175+
# For some reason the compiler doesn't find the libraries in the SDK directory when
176+
# running inside the build script. Therefore we need `-resource-dir`.
177+
string(REGEX REPLACE
178+
"(.*/)Toolchains/([^+]*).*"
179+
"\\1/Platforms/\\2/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift"
180+
resource_dir "${ALS_WIFT_EXEC}")
181+
list(APPEND sdk_option "-resource-dir" "${resource_dir}")
182+
else()
183+
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
184+
endif()
171185

172186
set(all_obj_files)
173187
set(all_module_targets)

test/embedded/optionset2.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// REQUIRES: optimized_stdlib
66
// REQUIRES: CODEGENERATOR=ARM
77

8+
// https://github.com/apple/swift/issues/73249
9+
// UNSUPPORTED: OS=windows-msvc
10+
811
protocol MyOptionSet: Equatable {
912
init(rawValue: Int)
1013
init()

test/embedded/ouroboros-bug.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// REQUIRES: optimized_stdlib
1111
// REQUIRES: CODEGENERATOR=ARM
1212

13+
// https://github.com/apple/swift/issues/73249
14+
// UNSUPPORTED: OS=windows-msvc
15+
1316
public func test() {}
1417
test()
1518

test/embedded/stdlib-array.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// REQUIRES: optimized_stdlib
66
// REQUIRES: CODEGENERATOR=ARM
77

8+
// https://github.com/apple/swift/issues/73249
9+
// UNSUPPORTED: OS=windows-msvc
10+
811
public func test() {
912
var array: [Int] = [1, 2, 3]
1013
array.append(42)

test/embedded/stdlib-basic.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// REQUIRES: swift_in_compiler
55
// REQUIRES: CODEGENERATOR=ARM
66

7+
// https://github.com/apple/swift/issues/73249
8+
// UNSUPPORTED: OS=windows-msvc
9+
710
public func bool() -> Bool {
811
return true
912
}

test/embedded/stdlib-dictionary.swift

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

7+
// https://github.com/apple/swift/issues/73249
8+
// UNSUPPORTED: OS=windows-msvc
9+
710
public func test() {
811
var d: [Int:Int] = [1: 2, 3: 4, 5: 6]
912
d[8] = 9

test/embedded/stdlib-random.swift

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

7+
// https://github.com/apple/swift/issues/73249
8+
// UNSUPPORTED: OS=windows-msvc
9+
710
public func test() {
811
Bool.random()
912
Int.random(in: 0 ..< 100)

test/embedded/stdlib-set.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// REQUIRES: optimized_stdlib
66
// REQUIRES: CODEGENERATOR=ARM
77

8+
// https://github.com/apple/swift/issues/73249
9+
// UNSUPPORTED: OS=windows-msvc
10+
811
public func test() {
912
var s: Set<Int> = [1, 2, 3]
1013
s.insert(42)

test/embedded/stdlib-types.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// REQUIRES: optimized_stdlib
66
// REQUIRES: CODEGENERATOR=ARM
77

8+
// https://github.com/apple/swift/issues/73249
9+
// UNSUPPORTED: OS=windows-msvc
10+
811
class MyClass {}
912

1013
public func test() {

0 commit comments

Comments
 (0)