termux-packages/packages/swift/swift-utils-build-script-im...

257 lines
13 KiB
Diff

diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index 4b202c99502..aa7b9e8f715 100644
--- a/swift/CMakeLists.txt
+++ b/swift/CMakeLists.txt
@@ -443,7 +445,7 @@
endif()
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
-if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
+if(NOT SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID AND SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT))
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
endif()
diff --git a/swift/utils/build-script b/swift/utils/build-script
index b4c3f6f6b28..27045d12eac 100755
--- a/swift/utils/build-script
+++ b/swift/utils/build-script
@@ -817,6 +817,7 @@ class BuildScriptInvocation(object):
"""
args = self.args
+ args.build_root = self.workspace.build_root
options = {}
for host_target in [args.host_target] + args.cross_compile_hosts:
@@ -838,6 +839,8 @@ class BuildScriptInvocation(object):
config.swift_benchmark_run_targets),
"SWIFT_TEST_TARGETS": " ".join(
config.swift_test_run_targets),
+ "SWIFT_FLAGS": config.swift_flags,
+ "SWIFT_TARGET_CMAKE_OPTIONS": config.cmake_options,
}
return options
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index 66a4408d066..2f6e9981252 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -137,7 +137,6 @@ KNOWN_SETTINGS=(
common-cmake-options "" "CMake options used for all targets, including LLVM/Clang"
extra-cmake-options "" "Extra options to pass to CMake for all targets"
ninja-cmake-options "" "CMake options used for all ninja targets"
- ninja-cmake-options "" "CMake options used for all ninja targets"
## Build ...
build-llvm "1" "set to 1 to build LLVM and Clang"
@@ -199,6 +198,7 @@
swift-stdlib-single-threaded-runtime "0" "whether to build stdlib as a single-threaded runtime only"
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
+ common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs"
## FREESTANDING Stdlib Options
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
@@ -224,6 +223,7 @@ KNOWN_SETTINGS=(
cross-compile-hosts "" "space-separated list of targets to cross-compile host Swift tools for"
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"
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"
@@ -1206,6 +1206,8 @@ function calculate_targets_for_host() {
SWIFT_BENCHMARK_TARGETS=($(get_host_specific_variable ${host} SWIFT_BENCHMARK_TARGETS))
SWIFT_RUN_BENCHMARK_TARGETS=($(get_host_specific_variable ${host} SWIFT_RUN_BENCHMARK_TARGETS))
SWIFT_TEST_TARGETS=($(get_host_specific_variable ${host} SWIFT_TEST_TARGETS))
+ SWIFT_FLAGS=($(get_host_specific_variable ${host} SWIFT_FLAGS))
+ SWIFT_TARGET_CMAKE_OPTIONS=($(get_host_specific_variable ${host} SWIFT_TARGET_CMAKE_OPTIONS))
}
@@ -1347,6 +1349,10 @@ function swift_c_flags() {
fi
}
+function common_swift_flags() {
+ echo -n "${SWIFT_FLAGS[@]} ${COMMON_SWIFT_FLAGS} -module-cache-path \"${module_cache}\" "
+}
+
function cmake_config_opt() {
product=$1
if [[ "${CMAKE_GENERATOR}" == "Xcode" ]] ; then
@@ -1631,6 +1637,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_BUILD_TYPE:STRING="${CMARK_BUILD_TYPE}"
"${cmark_cmake_options[@]}"
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+ fi
build_targets=(all)
;;
@@ -1751,6 +1760,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCLANG_TABLEGEN=$(build_directory "${LOCAL_HOST}" llvm)/bin/clang-tblgen
-DLLVM_NATIVE_BUILD=$(build_directory "${LOCAL_HOST}" llvm)
)
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
fi
;;
@@ -2161,7 +2171,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_CXX_COMPILER:PATH="${CLANG_BIN}/clang++"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN}
- -DCMAKE_Swift_FLAGS:STRING="-module-cache-path \"${module_cache}\""
+ -DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)"
-DLLBUILD_ENABLE_ASSERTIONS:BOOL=$(true_false "${LLBUILD_ENABLE_ASSERTIONS}")
-DLLBUILD_SUPPORT_BINDINGS:=Swift
@@ -2177,6 +2187,16 @@ for host in "${ALL_HOSTS[@]}"; do
-DFoundation_DIR:PATH=$(build_directory ${host} foundation)/cmake/modules
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+
+ # CROSS_COMPILE_DEPS_PATH is searched for the SQLite3 dependency.
+ cmake_options+=(
+ -DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
+ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ )
+ fi
+
# Ensure on Darwin platforms that we consider only the SQLite headers
# from the SDK instead of picking ones found elsewhere
# (e.g. in /usr/include )
@@ -2234,7 +2254,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_C_COMPILER:PATH="${CLANG_BIN}/clang"
-DCMAKE_CXX_COMPILER:PATH="${CLANG_BIN}/clang++"
-DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN}
- -DCMAKE_Swift_FLAGS:STRING="-module-cache-path \"${module_cache}\""
+ -DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2250,6 +2270,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DENABLE_TESTING=YES
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+ fi
;;
esac
@@ -2303,7 +2326,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_CXX_COMPILER:PATH=${CLANG_BIN}/clang++
-DCMAKE_SWIFT_COMPILER:PATH=${SWIFTC_BIN}
-DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN}
- -DCMAKE_Swift_FLAGS:STRING="-module-cache-path \"${module_cache}\""
+ -DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)"
-DCMAKE_INSTALL_PREFIX:PATH=$(get_host_install_prefix ${host})
${LIBICU_BUILD_ARGS[@]}
@@ -2319,6 +2342,21 @@ for host in "${ALL_HOSTS[@]}"; do
-DBUILD_SHARED_LIBS=$([[ ${product} == foundation_static ]] && echo "NO" || echo "YES")
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+
+ # CROSS_COMPILE_DEPS_PATH is searched for the ICU, libXML2
+ # and libcurl dependencies.
+ cmake_options+=(
+ -DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
+ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ )
+ fi
+ if [[ "${host}" == "android-"* ]]; then
+ cmake_options+=(
+ -DCMAKE_HAVE_LIBC_PTHREAD=True
+ )
+ fi
;;
libdispatch|libdispatch_static)
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
@@ -2345,7 +2383,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_CXX_COMPILER:PATH="${CLANG_BIN}/clang++"
-DCMAKE_SWIFT_COMPILER:PATH="${SWIFTC_BIN}"
-DCMAKE_Swift_COMPILER:PATH="${SWIFTC_BIN}"
- -DCMAKE_Swift_FLAGS:STRING="-module-cache-path \"${module_cache}\""
+ -DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2354,6 +2392,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DENABLE_TESTING=YES
-DBUILD_SHARED_LIBS=$([[ ${product} == libdispatch_static ]] && echo "NO" || echo "YES")
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+ fi
;;
esac
diff --git a/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py b/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py
index 9bd750657b8..1e24aee8468 100644
--- a/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py
+++ b/swift/utils/swift_build_support/swift_build_support/host_specific_configuration.py
@@ -72,6 +72,8 @@ class HostSpecificConfiguration(object):
self.swift_test_run_targets = []
self.swift_benchmark_build_targets = []
self.swift_benchmark_run_targets = []
+ self.swift_flags = ''
+ self.cmake_options = ''
for deployment_target_name in stdlib_targets_to_configure:
# Get the target object.
deployment_target = StdlibDeploymentTarget.get_target_for_name(
@@ -194,6 +196,13 @@ class HostSpecificConfiguration(object):
"check-swift{}-optimize_none_with_implicit_dynamic-{}"
.format(subset_suffix, name))
+ # Only pull in these flags when cross-compiling with
+ # --cross-compile-hosts.
+ if deployment_target_name != args.host_target and \
+ host_target != args.host_target:
+ self.swift_flags = deployment_target.swift_flags(args)
+ self.cmake_options = deployment_target.cmake_options(args)
+
def __platforms_to_skip_build(self, args):
platforms_to_skip_build = set()
if not args.build_linux:
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
index cb42f52c633..61778ad9837 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -152,6 +152,29 @@ class Target(object):
def name(self):
return "{}-{}".format(self.platform.name, self.arch)
+ def swift_flags(self, args):
+ flags = ''
+ if self.platform.name == 'android':
+ flags = '-target %s-unknown-linux-android%s ' % (self.arch,
+ args.android_api_level)
+ flags += '-resource-dir %s/swift-%s/lib/swift ' % (
+ args.build_root, self.name)
+ flags += '-sdk %s/sysroot ' % (args.android_ndk)
+ flags += '-tools-directory %s/bin' % (args.android_ndk)
+ flags += ' -Xlinker -rpath -Xlinker @TERMUX_PREFIX@/lib'
+
+ return flags
+
+ def cmake_options(self, args):
+ options = ''
+ if self.platform.name == 'android':
+ options = '-DCMAKE_SYSTEM_NAME=Android '
+ options += '-DCMAKE_SYSTEM_VERSION=%s ' % (args.android_api_level)
+ options += '-DCMAKE_SYSTEM_PROCESSOR=%s ' % (args.android_arch if not
+ args.android_arch == 'armv7' else 'armv7-a')
+ options += '-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN:PATH=%s' % (args.android_ndk)
+
+ return options
class StdlibDeploymentTarget(object):
OSX = DarwinPlatform("macosx", archs=["x86_64", "arm64", "arm64e"],