Skip to content

Add buildbot profile for cross-compiling for linux-armv7 using external sysroot #75367

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

Closed
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
2 changes: 1 addition & 1 deletion cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ macro(configure_sdk_unix name architectures)
# depending on the architecture, so having a single value is the only
# possibility right now.
set(SWIFT_SDK_${prefix}_CXX_OVERLAY_SWIFT_COMPILE_FLAGS
-Xcc --gcc-toolchain=/usr
-Xcc --gcc-toolchain=${CMAKE_SYSROOT}/usr
CACHE STRING "Extra flags for compiling the C++ overlay")

set(_default_threading_package "pthreads")
Expand Down
76 changes: 76 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,82 @@ lit-args=-v
indexstore-db=0
sourcekit-lsp=0

[preset: buildbot_linux_crosscompile_armv7,llvm]
release
reconfigure

# Disable features
build-swift-tools=0

# Skip rules
skip-build-cmark
skip-early-swift-driver
skip-early-swiftsyntax
skip-build-llvm
skip-build-swift

build-subdir=buildbot_linux_armv7

[preset: buildbot_linux_crosscompile_armv7,stdlib,corelibs]
mixin-preset=stdlib_base_standalone
release
reconfigure

install-swift
install-swiftsyntax
foundation
libdispatch
xctest
install-foundation
install-libdispatch
install-xctest

# NOTE: Backtracing does not cross compile for armv7 currently
swift-enable-backtracing=0
swift-stdlib-supports-backtrace-reporting=0

swift-install-components=autolink-driver;compiler;clang-builtin-headers;libexec;stdlib;swift-remote-mirror;sdk-overlay;dev
build-swift-static-stdlib
build-swift-static-sdk-overlay

# Cross compilation
skip-local-build
cross-compile-hosts=linux-armv7
cross-compile-deps-path=%(sysroot)s
cross-compile-append-host-target-to-destdir=False

build-subdir=buildbot_linux_armv7

# Custom flags for cross compilation
extra-cmake-options=
-DCMAKE_SYSROOT=%(sysroot)s
-DCMAKE_C_FLAGS="-w -fuse-ld=lld -target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s"
-DCMAKE_CXX_FLAGS="-w -fuse-ld=lld -target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s"
-DCMAKE_ASM_FLAGS="-target armv7-unknown-linux-gnueabihf --sysroot=%(sysroot)s"

# Set Swift flags to cross compile deps for armv7
common-swift-flags="-use-ld=lld -target armv7-unknown-linux-gnueabihf -resource-dir %(workspace_dir)s/build/buildbot_linux_armv7/swift-linux-armv7/lib/swift -sdk %(sysroot)s"

# Use lld for building Swift, set extra flags and sysroot paths
swift-cmake-options=
-DSWIFT_USE_LINKER=lld
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON
-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=ON
-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=ON
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=ON
-DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES=ON
-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION=ON
-DSWIFT_ENABLE_SYNCHRONIZATION=ON
-DSWIFT_SDK_LINUX_ARCH_armv7_PATH=%(sysroot)s

install-prefix=/usr

# Path to the root of the installation filesystem.
install-destdir=%(install_destdir)s

# Path to the .tar.gz package we would create.
installable-package=%(installable_package)s

[preset: buildbot_linux_armv7]
release
llbuild
Expand Down
4 changes: 4 additions & 0 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,10 @@ function common_swift_flags() {
echo "error: a module cache path has not been set"
exit 1
fi

# Remove quotes from COMMON_SWIFT_FLAGS before using it
COMMON_SWIFT_FLAGS=`echo ${COMMON_SWIFT_FLAGS} | xargs`

echo -n "${SWIFT_FLAGS[@]} ${COMMON_SWIFT_FLAGS} -module-cache-path \"${module_cache}\" "
}

Expand Down
1 change: 1 addition & 0 deletions utils/build_swift/tests/build_swift/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'ndk_path': '/path/to/ndk',
'arm_dir': '/path/to/arm',
'toolchain_path': '/tmp/toolchain',
'sysroot': '/path/to/sysroot'
}

SAMPLE_PRESET = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def get_linux_target_components(self, arch):
def get_linux_sysroot(self, platform, arch):
if not self.is_cross_compile_target('{}-{}'.format(platform, arch)):
return None
sysroot_arch, abi = self.get_linux_target_components(arch)
sysroot_arch, _, abi = self.get_linux_target_components(arch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change seems correct, but it might break the Alpine usecase it was added for in #61376 last year? @MaxDesiatov, wdyt?

# $ARCH-$PLATFORM-$ABI
# E.x.: aarch64-linux-gnu
sysroot_dirname = '{}-{}-{}'.format(sysroot_arch, platform, abi)
Expand Down