Skip to content

[5.6][build] Make it easier to cross-compile the stdlib and use it #40976

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
wants to merge 2 commits into from
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
11 changes: 9 additions & 2 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,23 @@ if(SWIFT_BUILD_STATIC_STDLIB)
PATTERN "*.h")
endif()

if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER OR SWIFT_PREBUILT_CLANG)
# This will still link against the Swift-forked clang headers if the Swift
# toolchain was built with SWIFT_INCLUDE_TOOLS.
set(symlink_dir ${clang_headers_location})
else()
set(symlink_dir "../clang/${CLANG_VERSION}")
endif()

swift_install_symlink_component(clang-resource-dir-symlink
LINK_NAME clang
TARGET ../clang/${CLANG_VERSION}
TARGET ${symlink_dir}
DESTINATION "lib/swift")

if(SWIFT_BUILD_STATIC_STDLIB)
swift_install_symlink_component(clang-resource-dir-symlink
LINK_NAME clang
TARGET ../clang/${CLANG_VERSION}
TARGET ${symlink_dir}
DESTINATION "lib/swift_static")
endif()

Expand Down
7 changes: 5 additions & 2 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ KNOWN_SETTINGS=(
cross-compile-with-host-tools "" "set to use the clang we build for the host to then build the cross-compile hosts"
cross-compile-install-prefixes "" "semicolon-separated list of install prefixes to use for the cross-compiled hosts. The list expands, so if there are more cross-compile hosts than prefixes, unmatched hosts use the last prefix in the list"
cross-compile-deps-path "" "path for CMake to look for cross-compiled library dependencies, such as libXML2"
cross-compile-append-host-target-to-destdir "1" "turns on appending the host target name of each cross-compiled toolchain to its install-destdir, to keep them separate from the natively-built toolchain"
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
coverage-db "" "If set, coverage database to use when prioritizing testing"
skip-local-host-install "" "If we are cross-compiling multiple targets, skip an install pass locally if the hosts match"
Expand Down Expand Up @@ -1130,8 +1131,10 @@ function get_host_install_destdir() {
if [[ $(should_include_host_in_lipo ${host}) ]]; then
# If this is one of the hosts we should lipo, install in to a temporary subdirectory.
local host_install_destdir="${BUILD_DIR}/intermediate-install/${host}"
elif [[ "${host}" == "merged-hosts" ]]; then
# This assumes that all hosts are merged to the lipo.
elif [[ "${host}" == "merged-hosts" ]] ||
[[ "$(true_false ${CROSS_COMPILE_APPEND_HOST_TARGET_TO_DESTDIR})" == "FALSE" ]]; then
# This assumes that all hosts are merged to the lipo, or the build
# was told not to append anything.
local host_install_destdir="${INSTALL_DESTDIR}"
else
local host_install_destdir="${INSTALL_DESTDIR}/${host}"
Expand Down
6 changes: 6 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ def create_argument_parser():
help='A space separated list of targets to cross-compile host '
'Swift tools for. Can be used multiple times.')

option('--cross-compile-append-host-target-to-destdir', toggle_true,
default=True,
help="Append each cross-compilation host target's name as a subdirectory "
"for each cross-compiled toolchain's destdir, useful when building "
"multiple toolchains and can be disabled if only cross-compiling one.")

option('--stdlib-deployment-targets', store,
type=argparse.ShellSplitType(),
default=None,
Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
'cmark_build_variant': 'Debug',
'compiler_vendor': defaults.COMPILER_VENDOR,
'coverage_db': None,
'cross_compile_append_host_target_to_destdir': True,
'cross_compile_hosts': [],
'darwin_deployment_version_ios':
defaults.DARWIN_DEPLOYMENT_VERSION_IOS,
Expand Down Expand Up @@ -532,6 +533,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--build-swift-static-stdlib'),
EnableOption('--build-swift-stdlib-unittest-extra'),
EnableOption('--build-swift-stdlib-static-print'),
EnableOption('--cross-compile-append-host-target-to-destdir'),
EnableOption('--distcc'),
EnableOption('--sccache'),
EnableOption('--enable-asan'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def convert_to_impl_arguments(self):
"--lldb-assertions", str(
args.lldb_assertions).lower(),
"--cmake-generator", args.cmake_generator,
"--cross-compile-append-host-target-to-destdir", str(
args.cross_compile_append_host_target_to_destdir).lower(),
"--build-jobs", str(args.build_jobs),
"--common-cmake-options=%s" % ' '.join(
pipes.quote(opt) for opt in cmake.common_options()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ def host_install_destdir(self, host_target):
# install in to a temporary subdirectory.
return '%s/intermediate-install/%s' % \
(os.path.dirname(self.build_dir), host_target)
elif host_target == "merged-hosts":
# This assumes that all hosts are merged to the lipo.
elif host_target == "merged-hosts" or \
not self.args.cross_compile_append_host_target_to_destdir:
# This assumes that all hosts are merged to the lipo, or the build
# was told not to append anything.
return self.args.install_destdir
else:
return '%s/%s' % (self.args.install_destdir, host_target)
Expand Down