Skip to content

Commit 58981a8

Browse files
committed
Disable pipes code on WASI.
WASI does not support pipes. Resolves #698.
1 parent 265a7ed commit 58981a8

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

Diff for: Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extension Array where Element == PackageDescription.SwiftSetting {
133133
.define("SWT_NO_EXIT_TESTS", .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android])),
134134
.define("SWT_NO_SNAPSHOT_TYPES", .when(platforms: [.linux, .windows, .wasi])),
135135
.define("SWT_NO_DYNAMIC_LINKING", .when(platforms: [.wasi])),
136+
.define("SWT_NO_PIPES", .when(platforms: [.wasi])),
136137
]
137138
}
138139

Diff for: Sources/Testing/ABI/EntryPoints/EntryPoint.swift

+2
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,14 @@ extension Event.ConsoleOutputRecorder.Options {
660660
return true
661661
}
662662

663+
#if !SWT_NO_PIPES
663664
// If the file handle is a pipe, assume the other end is using it to forward
664665
// output from this process to its own stderr file. This is how `swift test`
665666
// invokes the testing library, for example.
666667
if fileHandle.isPipe {
667668
return true
668669
}
670+
#endif
669671

670672
return false
671673
}

Diff for: Sources/Testing/ExitTests/ExitTest.swift

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
private import _TestingInternals
1212

1313
#if !SWT_NO_EXIT_TESTS
14+
#if SWT_NO_PIPES
15+
#error("Support for exit tests requires support for (anonymous) pipes.")
16+
#endif
17+
1418
/// A type describing an exit test.
1519
///
1620
/// Instances of this type describe an exit test defined by the test author and

Diff for: Sources/Testing/Support/FileHandle.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ extension FileHandle {
425425
}
426426
}
427427

428+
#if !SWT_NO_PIPES
428429
// MARK: - Pipes
429430

430431
extension FileHandle {
@@ -495,6 +496,7 @@ extension FileHandle {
495496
}
496497
}
497498
}
499+
#endif
498500

499501
// MARK: - Attributes
500502

@@ -525,9 +527,10 @@ extension FileHandle {
525527
#endif
526528
}
527529

530+
#if !SWT_NO_PIPES
528531
/// Is this file handle a pipe or FIFO?
529532
var isPipe: Bool {
530-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || os(WASI)
533+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android)
531534
withUnsafePOSIXFileDescriptor { fd in
532535
guard let fd else {
533536
return false
@@ -547,6 +550,7 @@ extension FileHandle {
547550
return false
548551
#endif
549552
}
553+
#endif
550554
}
551555

552556
// MARK: - General path utilities

Diff for: Tests/TestingTests/ExitTestTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private import _TestingInternals
2323
}
2424
}
2525
await #expect(exitsWith: .success) {
26+
sleep(100)
2627
exit(EXIT_SUCCESS)
2728
}
2829
await #expect(exitsWith: .exitCode(123)) {

Diff for: Tests/TestingTests/Support/FileHandleTests.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ struct FileHandleTests {
149149
}
150150
#endif
151151

152+
#if !SWT_NO_PIPES
152153
@Test("Can recognize opened pipe")
153154
func isPipe() throws {
154155
let pipe = try FileHandle.Pipe()
155156
#expect(pipe.readEnd.isPipe as Bool)
156157
#expect(pipe.writeEnd.isPipe as Bool)
157158
}
159+
#endif
158160

159-
#if SWT_TARGET_OS_APPLE
161+
#if SWT_TARGET_OS_APPLE && !SWT_NO_PIPES
160162
@Test("Can close ends of a pipe")
161163
func closeEndsOfPipe() async throws {
162164
try await confirmation("File handle closed", expectedCount: 2) { closed in
@@ -175,7 +177,9 @@ struct FileHandleTests {
175177
func devNull() throws {
176178
let fileHandle = try FileHandle.null(mode: "wb")
177179
#expect(!Bool(fileHandle.isTTY))
180+
#if !SWT_NO_PIPES
178181
#expect(!Bool(fileHandle.isPipe))
182+
#endif
179183
}
180184

181185
#if !os(Windows)
@@ -186,7 +190,9 @@ struct FileHandleTests {
186190
let file = try #require(fmemopen(nil, 1, "wb+"))
187191
let fileHandle = FileHandle(unsafeCFILEHandle: file, closeWhenDone: true)
188192
#expect(!Bool(fileHandle.isTTY))
193+
#if !SWT_NO_PIPES
189194
#expect(!Bool(fileHandle.isPipe))
195+
#endif
190196
}
191197
#endif
192198
}

Diff for: cmake/modules/shared/CompilerSettings.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ endif()
2727
if(NOT APPLE)
2828
add_compile_definitions("SWT_NO_SNAPSHOT_TYPES")
2929
endif()
30+
if(WASI)
31+
add_compile_definitions("SWT_NO_DYNAMIC_LINKING")
32+
add_compile_definitions("SWT_NO_PIPES")
33+
endif()

0 commit comments

Comments
 (0)