From 11a1611d7ecb301be50715d03788d9157d9637aa Mon Sep 17 00:00:00 2001 From: Butta Date: Sun, 26 Dec 2021 16:59:21 +0530 Subject: [PATCH 1/2] [build] Link the Swift resource directory against the headers from a prebuilt clang, if building with one --- stdlib/public/SwiftShims/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stdlib/public/SwiftShims/CMakeLists.txt b/stdlib/public/SwiftShims/CMakeLists.txt index fa1296fb9ef17..9d64126463473 100644 --- a/stdlib/public/SwiftShims/CMakeLists.txt +++ b/stdlib/public/SwiftShims/CMakeLists.txt @@ -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() From ec55f4bb2a626335935185e417f16d2243673c86 Mon Sep 17 00:00:00 2001 From: Butta Date: Mon, 20 Dec 2021 20:47:55 +0530 Subject: [PATCH 2/2] [build] Add a flag that allows disabling appending the host target's name to the install-destdir for a cross-compiled toolchain This is useful if you're cross-compiling the toolchain for a single host and don't want your specified install path modified. --- utils/build-script-impl | 7 +++++-- utils/build_swift/build_swift/driver_arguments.py | 6 ++++++ utils/build_swift/tests/expected_options.py | 2 ++ .../swift_build_support/build_script_invocation.py | 2 ++ .../swift_build_support/products/product.py | 6 ++++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/utils/build-script-impl b/utils/build-script-impl index 074e6f6cad2cc..7f23762512ee8 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -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" @@ -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}" diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index c18340e149ca4..03c120d411b61 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -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, diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index 40cb6ac88da62..32fba8cc842ac 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -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, @@ -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'), diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py index 941ba842fad87..08f56d10d8dd4 100644 --- a/utils/swift_build_support/swift_build_support/build_script_invocation.py +++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py @@ -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()), diff --git a/utils/swift_build_support/swift_build_support/products/product.py b/utils/swift_build_support/swift_build_support/products/product.py index 405f479546171..9e6f0eaf4b55d 100644 --- a/utils/swift_build_support/swift_build_support/products/product.py +++ b/utils/swift_build_support/swift_build_support/products/product.py @@ -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)