Skip to content

Preliminary Linux-OpenBSD cross-compile support. #60823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ macro(configure_sdk_unix name architectures)
message(STATUS "OpenBSD Version: ${openbsd_system_version}")

set(SWIFT_SDK_OPENBSD_ARCH_amd64_TRIPLE "amd64-unknown-openbsd${openbsd_system_version}")

if(CMAKE_SYSROOT)
set(SWIFT_SDK_OPENBSD_ARCH_${arch}_PATH "${CMAKE_SYSROOT}${SWIFT_SDK_OPENBSD_ARCH_${arch}_PATH}" CACHE INTERNAL "sysroot path" FORCE)
set(SWIFT_SDK_OPENBSD_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY "${CMAKE_SYSROOT}${SWIFT_SDK_OPENBSD_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}" CACHE INTERNAL "sysroot libc path" FORCE)
endif()
elseif("${prefix}" STREQUAL "CYGWIN")
if(NOT arch STREQUAL x86_64)
message(FATAL_ERROR "unsupported arch for cygwin: ${arch}")
Expand Down
16 changes: 15 additions & 1 deletion utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ function false_true() {
CROSS_COMPILE_HOSTS=($CROSS_COMPILE_HOSTS)
for t in "${CROSS_COMPILE_HOSTS[@]}"; do
case ${t} in
macosx* | iphone* | appletv* | watch* | linux-armv5 | linux-armv6 | linux-armv7 | android-* )
macosx* | iphone* | appletv* | watch* | linux-armv5 | linux-armv6 | linux-armv7 | android-* | openbsd-* )
;;
*)
echo "Unknown host to cross-compile for: ${t}"
Expand Down Expand Up @@ -1605,6 +1605,13 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_BUILD_WITH_INSTALL_RPATH="1"
)
fi

if [[ "${host}" == "openbsd-"* && -n "${OPENBSD_USE_TOOLCHAIN_FILE}" ]]; then
llvm_cmake_options=(
"${llvm_cmake_options[@]}"
-DCMAKE_TOOLCHAIN_FILE="${OPENBSD_USE_TOOLCHAIN_FILE}"
)
fi
fi

llvm_cmake_options=(
Expand Down Expand Up @@ -1887,6 +1894,13 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi

if [[ $(is_cross_tools_host ${host}) && "${host}" == "openbsd-"* && -n "${OPENBSD_USE_TOOLCHAIN_FILE}" ]]; then
cmake_options=(
"${cmake_options[@]}"
-DCMAKE_TOOLCHAIN_FILE="${OPENBSD_USE_TOOLCHAIN_FILE}"
)
fi

if [[ "${DARWIN_OVERLAY_TARGET}" != "" ]]; then
# Split LOCAL_HOST into a pair ``arch-sdk``
# Example LOCAL_HOST: macosx-x86_64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def build(self, host_target):
elif platform == "linux":
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
elif platform == "openbsd":
toolchain_file = self.get_openbsd_toolchain_file()
if toolchain_file:
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)

self.build_with_cmake(["all"], self.args.cmark_build_variant, [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ def generate_linux_toolchain_file(self, platform, arch):

return toolchain_file

def get_openbsd_toolchain_file(self):
return os.getenv('OPENBSD_USE_TOOLCHAIN_FILE')

def common_cross_c_flags(self, platform, arch):
cross_flags = []

Expand Down
10 changes: 9 additions & 1 deletion utils/swift_build_support/swift_build_support/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ def swiftpm_config(self, args, output_dir, swift_toolchain, resource_path):
return config_file


class OpenBSDPlatform(Platform):
def cmake_options(self, args):
toolchain_file = os.getenv('OPENBSD_USE_TOOLCHAIN_FILE')
if not toolchain_file:
return ''
return f'-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"'


class Target(object):
"""
Abstract representation of a target Swift can run on.
Expand Down Expand Up @@ -265,7 +273,7 @@ class StdlibDeploymentTarget(object):

FreeBSD = Platform("freebsd", archs=["x86_64"])

OpenBSD = Platform("openbsd", archs=["amd64"])
OpenBSD = OpenBSDPlatform("openbsd", archs=["amd64"])

Cygwin = Platform("cygwin", archs=["x86_64"])

Expand Down