Skip to content

Commit

Permalink
OpenBSD support. (apple#291)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
3405691582 authored Mar 29, 2021
1 parent 0fccec7 commit b936799
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/ArgumentParser/Usage/HelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/SwiftSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b936799

Please sign in to comment.