Skip to content

Commit eb38d80

Browse files
committed
[Backtracing] Fix Windows build.
While I was doing this, it turns out Saleem was fixing things to avoid having to patch the Windows include directories, which is awesome but necessitates an extra change to the backtracing stuff to make the build not fail on Windows. rdar://105409147
1 parent 43ac069 commit eb38d80

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,11 @@ function(_add_swift_target_executable_single name)
25672567

25682568
string(MAKE_C_IDENTIFIER "${name}" module_name)
25692569

2570+
if(SWIFTEXE_SINGLE_SDK STREQUAL WINDOWS)
2571+
list(APPEND SWIFTEXE_SINGLE_COMPILE_FLAGS
2572+
-vfsoverlay;"${SWIFT_WINDOWS_VFS_OVERLAY}")
2573+
endif()
2574+
25702575
handle_swift_sources(
25712576
dependency_target
25722577
unused_module_dependency_target
@@ -2602,7 +2607,6 @@ function(_add_swift_target_executable_single name)
26022607
${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE)
26032608
target_include_directories(${name} SYSTEM PRIVATE
26042609
${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE})
2605-
26062610
if(NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC)
26072611
# MSVC doesn't support -Xclang. We don't need to manually specify
26082612
# the dependent libraries as `cl` does so.
@@ -2612,6 +2616,7 @@ function(_add_swift_target_executable_single name)
26122616
"SHELL:-Xclang --dependent-lib=msvcrt$<$<CONFIG:Debug>:d>")
26132617
endif()
26142618
endif()
2619+
26152620
target_compile_options(${name} PRIVATE
26162621
${c_compile_flags})
26172622
target_link_directories(${name} PRIVATE

stdlib/public/Backtracing/Context.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ extension arm_gprs {
268268
}
269269
#endif
270270

271-
#if arch(x86_64)
271+
#if os(Windows)
272+
struct NotYetImplemented: Error {}
273+
public static func withCurrentContext<T>(fn: (X86_64Context) throws -> T) throws -> T {
274+
throw NotYetImplemented()
275+
}
276+
#elseif arch(x86_64)
272277
@_silgen_name("_swift_get_cpu_context")
273278
static func _swift_get_cpu_context() -> X86_64Context
274279

@@ -418,7 +423,12 @@ extension arm_gprs {
418423

419424
public static var registerCount: Int { return 50 }
420425

421-
#if arch(i386)
426+
#if os(Windows)
427+
struct NotYetImplemented: Error {}
428+
public static func withCurrentContext<T>(fn: (I386Context) throws -> T) throws -> T {
429+
throw NotYetImplemented()
430+
}
431+
#elseif arch(i386)
422432
@_silgen_name("_swift_get_cpu_context")
423433
static func _swift_get_cpu_context() -> I386Context
424434

@@ -614,7 +624,12 @@ extension arm_gprs {
614624
}
615625
#endif
616626

617-
#if arch(arm64)
627+
#if os(Windows)
628+
struct NotYetImplemented: Error {}
629+
public static func withCurrentContext<T>(fn: (ARM64Context) throws -> T) throws -> T {
630+
throw NotYetImplemented()
631+
}
632+
#elseif arch(arm64)
618633
@_silgen_name("_swift_get_cpu_context")
619634
static func _swift_get_cpu_context() -> ARM64Context
620635

@@ -748,14 +763,19 @@ extension arm_gprs {
748763

749764
public static var registerCount: Int { return 16 }
750765

751-
#if arch(arm)
766+
#if os(Windows)
767+
struct NotYetImplemented: Error {}
768+
public static func withCurrentContext<T>(fn: (ARMContext) throws -> T) throws -> T {
769+
throw NotYetImplemented()
770+
}
771+
#elseif arch(arm)
752772
@_silgen_name("_swift_get_cpu_context")
753773
static func _swift_get_cpu_context() -> ARMContext
754774

755775
public static func withCurrentContext<T>(fn: (ARMContext) throws -> T) rethrows -> T {
756776
return try fn(_swift_get_cpu_context())
757777
}
758-
#endif
778+
#endif
759779

760780
private func isValid(_ register: Register) -> Bool {
761781
if register.rawValue < 16 {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
;;; Placeholder for Windows assembly code
22
;;; This uses different syntax from everywhere else :-(
3+
4+
end

stdlib/public/libexec/swift-backtrace/Utils.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ internal func parseUInt64<S: StringProtocol>(_ s: S) -> UInt64? {
5151
}
5252
}
5353

54+
#if os(macOS)
55+
5456
struct PosixError: Error {
5557
var errno: Int32
5658

@@ -137,3 +139,4 @@ internal func spawn(_ path: String, args: [String]) throws {
137139
}
138140
}
139141

142+
#endif // os(macOS)

0 commit comments

Comments
 (0)