Skip to content

Commit cca8f80

Browse files
authored
Add SwiftWasm support (#363)
1 parent 90f76c1 commit cca8f80

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

Sources/ArgumentParser/Completions/CompletionsGenerator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Glibc
1515
import Darwin
1616
#elseif canImport(CRT)
1717
import CRT
18+
#elseif canImport(WASILibc)
19+
import WASILibc
1820
#endif
1921

2022
/// A shell for which the parser can generate a completion script.

Sources/ArgumentParser/Parsable Properties/Errors.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Glibc
1515
import Darwin
1616
#elseif canImport(CRT)
1717
import CRT
18+
#elseif canImport(WASILibc)
19+
import WASILibc
1820
#endif
1921

2022
#if os(Windows)
@@ -66,6 +68,8 @@ public struct ExitCode: Error, RawRepresentable, Hashable {
6668
/// An exit code that indicates that the user provided invalid input.
6769
#if os(Windows)
6870
public static let validationFailure = ExitCode(ERROR_BAD_ARGUMENTS)
71+
#elseif os(WASI)
72+
public static let validationFailure = ExitCode(EXIT_FAILURE)
6973
#else
7074
public static let validationFailure = ExitCode(EX_USAGE)
7175
#endif

Sources/ArgumentParser/Parsable Types/ParsableArguments.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ let _exit: (Int32) -> Never = Darwin.exit
1818
#elseif canImport(CRT)
1919
import CRT
2020
let _exit: (Int32) -> Never = ucrt._exit
21+
#elseif canImport(WASILibc)
22+
import WASILibc
2123
#endif
2224

2325
/// A type that can be parsed from a program's command-line arguments.

Sources/ArgumentParser/Usage/HelpGenerator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ import WinSDK
348348
#endif
349349

350350
func _terminalSize() -> (width: Int, height: Int) {
351-
#if os(Windows)
351+
#if os(WASI)
352+
// WASI doesn't yet support terminal size
353+
return (80, 25)
354+
#elseif os(Windows)
352355
var csbi: CONSOLE_SCREEN_BUFFER_INFO = CONSOLE_SCREEN_BUFFER_INFO()
353356

354357
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)

0 commit comments

Comments
 (0)