From b936799bcaa6c2e4fbb74507109f9b18d6650de3 Mon Sep 17 00:00:00 2001 From: 3405691582 Date: Mon, 29 Mar 2021 13:46:26 -0400 Subject: [PATCH] OpenBSD support. (#291) On this platform, the TIOCGWINSZ ioctl identifier is a complex macro. Since we don't have a C bridging header obviously available to get the flattened value, supply is the flattened value obtained elsewhere. This is of course brittle but this is the simplest way around this for now. Additionally, ensure we support the platform architecture name, where the x86_64 architecture is called amd64 instead. --- Sources/ArgumentParser/Usage/HelpGenerator.swift | 6 ++++++ cmake/modules/SwiftSupport.cmake | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Sources/ArgumentParser/Usage/HelpGenerator.swift b/Sources/ArgumentParser/Usage/HelpGenerator.swift index 39c041c40..eeba86e7e 100644 --- a/Sources/ArgumentParser/Usage/HelpGenerator.swift +++ b/Sources/ArgumentParser/Usage/HelpGenerator.swift @@ -325,7 +325,13 @@ func _terminalSize() -> (width: Int, height: Int) { height: Int(csbi.srWindow.Bottom - csbi.srWindow.Top) + 1) #else var w = winsize() +#if os(OpenBSD) + // TIOCGWINSZ is a complex macro, so we need the flattened value. + let tiocgwinsz = Int32(0x40087468) + let err = ioctl(STDOUT_FILENO, tiocgwinsz, &w) +#else let err = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) +#endif let width = Int(w.ws_col) let height = Int(w.ws_row) guard err == 0 else { return (80, 25) } diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index b5f2db35d..2b2ac76c6 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -27,6 +27,8 @@ function(get_swift_host_arch result_var_name) set("${result_var_name}" "armv7" PARENT_SCOPE) elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64") + set("${result_var_name}" "amd64" PARENT_SCOPE) elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") set("${result_var_name}" "x86_64" PARENT_SCOPE) elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")