swift: update from 5.2.5 to 5.3

This commit is contained in:
Butta 2020-09-07 21:53:03 +05:30 committed by buttaface
parent fce7ca9739
commit 0017d3e1df
20 changed files with 609 additions and 636 deletions

View File

@ -1,6 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-corelibs-libdispatch
TERMUX_PKG_DESCRIPTION="The libdispatch project, for concurrency on multicore hardware"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@buttaface"
_VERSION=5.3
TERMUX_PKG_VERSION=1:${_VERSION}
TERMUX_PKG_SRCURL=https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${_VERSION}-RELEASE.tar.gz

View File

@ -1,6 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-llbuild
TERMUX_PKG_DESCRIPTION="A low-level build system, used by the Swift Package Manager"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION=5.3
TERMUX_PKG_SRCURL=https://github.com/apple/swift-llbuild/archive/swift-${TERMUX_PKG_VERSION}-RELEASE.tar.gz
TERMUX_PKG_SHA256=6fddae33feb77cc13c797069cb91ac091af54cb6b267267f0de2bb45ceef1b78

View File

@ -1,35 +1,33 @@
TERMUX_PKG_HOMEPAGE=https://swift.org/
TERMUX_PKG_DESCRIPTION="Swift is a high-performance system programming language"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_VERSION=5.2.5
TERMUX_PKG_REVISION=2
TERMUX_PKG_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION=5.3
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=2353bb00dada11160945729a33af94150b7cf0a6a38fbe975774a6e244dbc548
TERMUX_PKG_SHA256=f9e5bd81441c4ec13dd9ea290e2d7b8fe9b30ef66ad68947481022ea5179f83a
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_DEPENDS="binutils-gold, clang, libc++, ndk-sysroot, libandroid-glob, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild"
TERMUX_PKG_BUILD_DEPENDS="cmake, ninja, perl, pkg-config, python2, rsync"
TERMUX_PKG_BLACKLISTED_ARCHES="arm, i686, x86_64"
TERMUX_PKG_NO_STATICSPLIT=true
SWIFT_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;swift-remote-mirror;parser-lib;license;sourcekit-inproc"
SWIFT_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;swift-remote-mirror;parser-lib;license;sourcekit-inproc;stdlib;sdk-overlay"
SWIFT_TOOLCHAIN_FLAGS="-R --no-assertions --llvm-targets-to-build='X86;ARM;AArch64' -j $TERMUX_MAKE_PROCESSES"
SWIFT_PATH_FLAGS="--build-subdir=. --install-destdir=/ --install-prefix=$TERMUX_PREFIX"
SWIFT_BUILD_FLAGS="$SWIFT_TOOLCHAIN_FLAGS $SWIFT_PATH_FLAGS"
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
SWIFT_BUILD_FLAGS="--build-swift-static-stdlib --swift-install-components='$SWIFT_COMPONENTS;stdlib;sdk-overlay'"
else
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
SWIFT_BIN="swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE-ubuntu20.04"
SWIFT_BINDIR="$TERMUX_PKG_HOSTBUILD_DIR/$SWIFT_BIN/usr/bin"
SWIFT_ANDROID_NDK_FLAGS="--android --android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $TERMUX_ARCH
--android-api-level $TERMUX_PKG_API_LEVEL --android-icu-uc $TERMUX_PREFIX/lib/libicuuc.so
--android-icu-uc-include $TERMUX_PREFIX/include/ --android-icu-i18n $TERMUX_PREFIX/lib/libicui18n.so
--android-icu-i18n-include $TERMUX_PREFIX/include/ --android-icu-data $TERMUX_PREFIX/lib/libicudata.so"
SWIFT_BUILD_FLAGS="$SWIFT_ANDROID_NDK_FLAGS --build-toolchain-only --skip-build-android
--cross-compile-hosts=android-$TERMUX_ARCH --swift-install-components='$SWIFT_COMPONENTS'
--native-swift-tools-path=$SWIFT_BINDIR --native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin
--build-swift-dynamic-stdlib=0 --build-swift-dynamic-sdk-overlay=0 --skip-local-build
--skip-local-host-install"
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android --android-ndk $TERMUX_STANDALONE_TOOLCHAIN
--android-arch $TERMUX_ARCH --android-api-level $TERMUX_PKG_API_LEVEL
--android-icu-uc $TERMUX_PREFIX/lib/libicuuc.so --android-icu-uc-include $TERMUX_PREFIX/include/
--android-icu-i18n $TERMUX_PREFIX/lib/libicui18n.so --android-icu-i18n-include $TERMUX_PREFIX/include/
--android-icu-data $TERMUX_PREFIX/lib/libicudata.so --build-toolchain-only
--skip-local-build --skip-local-host-install --build-runtime-with-host-compiler
--cross-compile-hosts=android-$TERMUX_ARCH --cross-compile-deps-path=$TERMUX_PREFIX
--native-swift-tools-path=$SWIFT_BINDIR --native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin"
fi
termux_step_post_get_source() {
@ -41,13 +39,13 @@ termux_step_post_get_source() {
mv .temp swift
declare -A library_checksums
library_checksums[swift-cmark]=71ef5641ebbb60ddd609320bdbf4d378cdcd89941b6f17f658ee5be40c98a232
library_checksums[llvm-project]=f3e6bf2657edf7c290befdfc9d534ed776c0f344c0df373ccecc60ab2c928a51
library_checksums[swift-corelibs-libdispatch]=df86f7cf005b9f06f365f5d39bc952ecc50ffc11f2382ab12b46fed2b83bb26e
library_checksums[swift-corelibs-foundation]=47961693711812f6e0a2525192aebdf1aa7a08323f6061e3defcd1639d09b429
library_checksums[swift-corelibs-xctest]=37c1dec78fab3f98a9f106d4d4a7f35268004f4c1e157ab97a6c76aa4dbcb845
library_checksums[swift-llbuild]=07db561275697634f4790d9cd7d817272ffa37ebd7a69e0abc5de51bcdb4efb7
library_checksums[swift-package-manager]=f7197556bf299f4fc7b88e63fed78797fd85f94bf590f34e3de845ad5e62afbe
library_checksums[swift-cmark]=a1982e4407bc70a07c86e2cacf0727215d5eae82cdae9eacad32298f3e798b5c
library_checksums[llvm-project]=ccf263a8e8b82ae3d904d69ac37b7e239bf0511071540216e75cb2144d812446
library_checksums[swift-corelibs-libdispatch]=6805b555aab65d740fccaa99570fd29b32efa6c310fd42524913e44509dc4969
library_checksums[swift-corelibs-foundation]=f42906de3d21db10d7847786fc423c7d3318c70f6a31bb36ee172aff4fb9cdaf
library_checksums[swift-corelibs-xctest]=f12c8d26e2280f2aba7a9c69c9371050f936282114b4e4a5474625fec0ca8312
library_checksums[swift-llbuild]=6fddae33feb77cc13c797069cb91ac091af54cb6b267267f0de2bb45ceef1b78
library_checksums[swift-package-manager]=bc91ed638457bbf87317c610657c57c94715c7cb70ba680d9c6a067ff0962e06
for library in "${!library_checksums[@]}"; do \
termux_download \
@ -66,58 +64,27 @@ termux_step_post_get_source() {
termux_download \
https://swift.org/builds/swift-$TERMUX_PKG_VERSION-release/ubuntu2004/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE/$SWIFT_BIN.tar.gz \
$TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz \
1350f1775469bc129dc4b53e324c5748c5f63eff922c581faf38a02e41e4bb15
acd424635c93cede10526d4de1e55bd429e30c14e85f75b5562397800ca5a685
fi
# The Swift compiler searches for the clang headers so symlink against them.
export TERMUX_CLANG_VERSION=$(grep ^TERMUX_PKG_VERSION= $TERMUX_PKG_BUILDER_DIR/../libllvm/build.sh | cut -f2 -d=)
sed "s%\@TERMUX_CLANG_VERSION\@%${TERMUX_CLANG_VERSION}%g" $TERMUX_PKG_BUILDER_DIR/swift-stdlib-public-SwiftShims-CMakeLists.txt | \
patch -p1
# The Swift build scripts still depend on Python 2, so make sure it's used.
ln -s $(command -v python2) $TERMUX_PKG_BUILDDIR/python
fi
export PATH=$TERMUX_PKG_BUILDDIR:$PATH
# The Swift compiler searches for the clang headers so symlink against them.
export TERMUX_CLANG_VERSION=$(grep ^TERMUX_PKG_VERSION= $TERMUX_PKG_BUILDER_DIR/../libllvm/build.sh | cut -f2 -d=)
}
termux_step_host_build() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz
fi
termux_setup_cmake
termux_setup_ninja
termux_setup_standalone_toolchain
local CLANG=$(command -v clang)
local CLANGXX=$(command -v clang++)
# The Ubuntu CI may not have clang/clang++ in its path so explicitly set it
# to clang-10 instead.
if [ -z "$CLANG" ]; then
CLANG=$(command -v clang-10)
CLANGXX=$(command -v clang++-10)
fi
# Natively compile llvm-tblgen and some other files needed later, and cross-compile
# the Swift stdlib.
# Natively compile llvm-tblgen and some other files needed later.
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
-R --no-assertions -j $TERMUX_MAKE_PROCESSES $SWIFT_ANDROID_NDK_FLAGS $SWIFT_PATH_FLAGS \
--build-runtime-with-host-compiler --skip-build-llvm --build-swift-tools=0 \
--native-swift-tools-path=$SWIFT_BINDIR --native-llvm-tools-path=$SWIFT_BINDIR \
--native-clang-tools-path=$SWIFT_BINDIR --build-swift-static-stdlib \
--build-swift-static-sdk-overlay --stdlib-deployment-targets=android-$TERMUX_ARCH \
--swift-primary-variant-sdk=ANDROID --swift-primary-variant-arch=$TERMUX_ARCH \
--swift-install-components="stdlib;sdk-overlay" --install-swift \
--host-cc=$CLANG --host-cxx=$CLANGXX
-R --no-assertions -j $TERMUX_MAKE_PROCESSES $SWIFT_PATH_FLAGS \
--skip-build-cmark --skip-build-llvm --skip-build-swift \
--host-cc=$TERMUX_STANDALONE_TOOLCHAIN/bin/clang \
--host-cxx=$TERMUX_STANDALONE_TOOLCHAIN/bin/clang++
cp $TERMUX_PREFIX/lib/swift/android/$TERMUX_ARCH/glibc.modulemap \
$TERMUX_PKG_BUILDDIR/glibc-native.modulemap
# This is installed later with the compiler, but it's needed before that
# to cross-compile the corelibs.
ln -s ../clang/$TERMUX_CLANG_VERSION $TERMUX_PREFIX/lib/swift/clang
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz -C $TERMUX_PKG_HOSTBUILD_DIR
fi
}
@ -133,46 +100,39 @@ termux_step_pre_configure() {
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/include-llvm-ADT-Triple.h.patch
cd ../..
sed "s%\@TERMUX_STANDALONE_TOOLCHAIN\@%${TERMUX_STANDALONE_TOOLCHAIN}%g" \
$TERMUX_PKG_BUILDER_DIR/swift-utils-build-script-impl | \
sed "s%\@TERMUX_PKG_API_LEVEL\@%${TERMUX_PKG_API_LEVEL}%g" | \
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" | \
sed "s%\@TERMUX_ARCH\@%${TERMUX_ARCH}%g" | patch -p1
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-Utilities-bootstrap | \
sed "s%\@TERMUX_PKG_BUILDDIR\@%${TERMUX_PKG_BUILDDIR}%g" | \
sed "s%\@TERMUX_ARCH\@%${TERMUX_ARCH}%g" | patch -p1
sed "s%\@TERMUX_STANDALONE_TOOLCHAIN\@%${TERMUX_STANDALONE_TOOLCHAIN}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-android-flags.json | \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | \
sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" | \
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" | \
sed "s%\@TERMUX_ARCH\@%${TERMUX_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
sed "s%\@TERMUX_STANDALONE_TOOLCHAIN\@%${TERMUX_STANDALONE_TOOLCHAIN}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-android-flags.json | \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | \
sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" | \
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" | \
sed "s%\@TERMUX_ARCH\@%${TERMUX_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json
fi
fi
}
termux_step_make() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
export TERMUX_SWIFT_FLAGS="-target $CCTERMUX_HOST_PLATFORM \
-resource-dir $TERMUX_PREFIX/lib/swift -sdk $TERMUX_STANDALONE_TOOLCHAIN/sysroot \
export TERMUX_SWIFTPM_FLAGS="-target $CCTERMUX_HOST_PLATFORM \
-sdk $TERMUX_STANDALONE_TOOLCHAIN/sysroot \
-L$TERMUX_STANDALONE_TOOLCHAIN/lib/gcc/$TERMUX_HOST_PLATFORM/4.9.x \
-tools-directory $TERMUX_STANDALONE_TOOLCHAIN/$TERMUX_HOST_PLATFORM/bin \
-Xlinker -rpath -Xlinker $TERMUX_PREFIX/lib"
export TERMUX_SWIFT_FLAGS="$TERMUX_SWIFTPM_FLAGS -resource-dir \
$TERMUX_PKG_BUILDDIR/swift-android-$TERMUX_ARCH/lib/swift"
export HOST_SWIFTC="$SWIFT_BINDIR/swiftc"
# Use the modulemap that points to the sysroot headers in the standalone NDK
# when cross-compiling, rather than the one meant for running natively on Termux,
# then install the native modulemap at the end.
cp $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib/swift/android/$TERMUX_ARCH/glibc.modulemap \
$TERMUX_PREFIX/lib/swift/android/$TERMUX_ARCH/
fi
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
$SWIFT_TOOLCHAIN_FLAGS $SWIFT_PATH_FLAGS --xctest -b -p --llvm-install-components=IndexStore \
--install-swift --install-libdispatch --install-foundation --install-xctest \
--install-llbuild --install-swiftpm $SWIFT_BUILD_FLAGS
$SWIFT_BUILD_FLAGS --xctest -b -p --build-swift-static-stdlib --install-swift \
--swift-install-components=$SWIFT_COMPONENTS --llvm-install-components=IndexStore \
--install-libdispatch --install-foundation --install-xctest --install-llbuild \
--install-swiftpm
}
termux_step_make_install() {
@ -180,7 +140,7 @@ termux_step_make_install() {
rm $TERMUX_PREFIX/lib/swift/android/lib{dispatch,BlocksRuntime}.so
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
cp $TERMUX_PKG_BUILDDIR/glibc-native.modulemap \
mv $TERMUX_PREFIX/glibc-native.modulemap \
$TERMUX_PREFIX/lib/swift/android/$TERMUX_ARCH/glibc.modulemap
fi
}

View File

@ -1,49 +1,43 @@
diff --git a/swift-corelibs-foundation/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Foundation/CMakeLists.txt
index cf80e7dd..2cf41b62 100644
--- a/swift-corelibs-foundation/Foundation/CMakeLists.txt
+++ b/swift-corelibs-foundation/Foundation/CMakeLists.txt
@@ -161,7 +161,7 @@ target_link_libraries(Foundation PUBLIC
swiftDispatch)
# TODO(compnerd) properly propogate `BUILD_RPATH` to the target using CMake
-if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
+if(NOT CMAKE_SYSTEM_NAME STREQUAL Android AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_options(Foundation PRIVATE
"SHELL:-Xlinker -rpath -Xlinker $<TARGET_FILE_DIR:swiftDispatch>")
endif()
@@ -173,6 +173,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
Shell32
pathcch)
endif()
+target_link_options(Foundation PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
set_target_properties(Foundation PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
@@ -223,6 +224,7 @@ target_link_libraries(FoundationNetworking PRIVATE
${ZLIB_LIBRARIES}
Foundation
CFURLSessionInterface)
+target_link_options(FoundationNetworking PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
set_target_properties(FoundationNetworking PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
@@ -248,6 +250,7 @@ target_link_libraries(FoundationXML PRIVATE
${LIBXML2_LIBRARIES}
Foundation
CFXMLInterface)
+target_link_options(FoundationXML PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
set_target_properties(FoundationXML PROPERTIES
INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift
diff --git a/swift-corelibs-foundation/Tools/plutil/CMakeLists.txt b/swift-corelibs-foundation/Tools/plutil/CMakeLists.txt
index bb746639..ff1b74e6 100644
--- a/swift-corelibs-foundation/Tools/plutil/CMakeLists.txt
+++ b/swift-corelibs-foundation/Tools/plutil/CMakeLists.txt
@@ -3,6 +3,7 @@ add_executable(plutil
commit 82ee1f5c31a618d3fb167953e0516dce28b52263
Date: Thu May 7 15:29:46 2020 +0530
[CMake] fix runpath for ELF platforms
Remove the absolute path to the host toolchain's stdlib from plutil, and add
it as a CMake BUILD_PATH, so that it's removed upon installation.
diff --git a/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt b/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
index 7f2913b3..3c9163c1 100644
--- a/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
+++ b/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
@@ -2,6 +2,30 @@ add_executable(plutil
main.swift)
target_link_libraries(plutil PRIVATE
Foundation)
+target_link_options(plutil PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+
+# On ELF platforms, remove the absolute rpath to the host toolchain's stdlib, then add it
+# back temporarily as a BUILD_RPATH just for the tests.
+if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
+ target_link_options(plutil PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+
+ # This assumes the host is the target, pass a target flag when cross-compiling.
+ execute_process(
+ COMMAND ${CMAKE_Swift_COMPILER} -print-target-info
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE error_output
+ RESULT_VARIABLE result
+ )
+ if(NOT ${result} EQUAL 0)
+ message(FATAL_ERROR "Error getting target info with\n"
+ " `${CMAKE_Swift_COMPILER} -print-target-info`\n"
+ "Error:\n"
+ " ${error_output}")
+ endif()
+
+ string(REGEX MATCH "\"runtimeLibraryPaths\": \\[\n\ +\"([^\"]+)\"" path ${output})
+ set_target_properties(plutil PROPERTIES BUILD_RPATH ${CMAKE_MATCH_1})
+endif()
+
set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

View File

@ -1,25 +0,0 @@
diff --git a/swift-corelibs-libdispatch/src/CMakeLists.txt b/swift-corelibs-libdispatch/src/CMakeLists.txt
index c88b430..ac2e82c 100644
--- a/swift-corelibs-libdispatch/src/CMakeLists.txt
+++ b/swift-corelibs-libdispatch/src/CMakeLists.txt
@@ -95,6 +95,8 @@ endif()
set_target_properties(dispatch PROPERTIES
POSITION_INDEPENDENT_CODE YES)
+set_target_properties(dispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
+
target_include_directories(dispatch PUBLIC
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}
diff --git a/swift-corelibs-libdispatch/src/swift/CMakeLists.txt b/swift-corelibs-libdispatch/src/swift/CMakeLists.txt
index ba987e7..1c864fd 100644
--- a/swift-corelibs-libdispatch/src/swift/CMakeLists.txt
+++ b/swift-corelibs-libdispatch/src/swift/CMakeLists.txt
@@ -59,4 +59,7 @@ if(NOT BUILD_SHARED_LIBS)
install(TARGETS DispatchStubs
EXPORT dispatchExports
DESTINATION ${INSTALL_TARGET_DIR})
+else()
+ target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()

View File

@ -1,15 +0,0 @@
diff --git a/llbuild/products/llbuildSwift/CMakeLists.txt b/llbuild/products/llbuildSwift/CMakeLists.txt
index 1e6dad1..d5cc02f 100644
--- a/llbuild/products/llbuildSwift/CMakeLists.txt
+++ b/llbuild/products/llbuildSwift/CMakeLists.txt
@@ -57,8 +57,9 @@ else()
swiftDispatch
Foundation)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
+ target_link_options(llbuildSwift PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
set_target_properties(llbuildSwift PROPERTIES
- INSTALL_RPATH "$ORIGIN:$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
+ INSTALL_RPATH "$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
endif()
endif()
set_target_properties(llbuildSwift PROPERTIES

View File

@ -2,30 +2,6 @@ diff --git a/swift/utils/build-script b/swift/utils/build-script
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script
+++ b/swift/utils/build-script
@@ -221,7 +221,11 @@ class BuildScriptInvocation(object):
android_tgts = [tgt for tgt in args.stdlib_deployment_targets
if StdlibDeploymentTarget.Android.contains(tgt)]
if not args.android and len(android_tgts) > 0:
- args.android = True
+ # If building natively on an Android host, avoid the NDK
+ # cross-compilation configuration.
+ if not StdlibDeploymentTarget.Android.contains(StdlibDeploymentTarget
+ .host_target().name):
+ args.android = True
args.build_android = False
# Include the Darwin supported architectures in the CMake options.
@@ -572,6 +576,10 @@ class BuildScriptInvocation(object):
"--android-icu-i18n-include", args.android_icu_i18n_include,
"--android-icu-data", args.android_icu_data,
]
+ # If building natively on an Android host, only pass the API level.
+ if StdlibDeploymentTarget.Android.contains(StdlibDeploymentTarget
+ .host_target().name):
+ impl_args += ["--android-api-level", args.android_api_level]
if args.android_deploy_device_path:
impl_args += [
"--android-deploy-device-path",
@@ -799,8 +807,7 @@
self._execute_install_action(host_target, product_class)
@ -36,6 +12,21 @@ index b1d060328bc..218c9215260 100755
for product_class in product_classes:
if product_class.is_build_script_impl_product():
continue
diff --git a/swift/utils/gen-static-stdlib-link-args b/swift/utils/gen-static-stdlib-link-args
index 0fa009d67d3..abd98c2493f 100755
--- a/swift/utils/gen-static-stdlib-link-args
+++ b/swift/utils/gen-static-stdlib-link-args
@@ -60,9 +60,8 @@ function write_linkfile {
fi
cat >$OUTPUTFILE <<EOF
-ldl
--lpthread
-lswiftCore
--lswiftImageInspectionShared
+-llog
$ICU_LIBS
-lstdc++
-lm
diff --git a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py b/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
index 475483618f1..2bea230012b 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/swiftpm.py
@ -43,48 +34,23 @@ index 475483618f1..2bea230012b 100644
@@ -31,8 +31,11 @@ class SwiftPM(product.Product):
def run_bootstrap_script(self, action, host_target, additional_params=[]):
script_path = os.path.join(
self.source_dir, 'Utilities', 'new-bootstrap')
- toolchain_path = self.install_toolchain_path()
- swiftc = os.path.join(toolchain_path, "usr", "bin", "swiftc")
self.source_dir, 'Utilities', 'bootstrap')
- toolchain_path = self.install_toolchain_path(host_target)
- swiftc = os.path.join(toolchain_path, "bin", "swiftc")
+ if os.getenv("HOST_SWIFTC"):
+ swiftc = os.getenv("HOST_SWIFTC")
+ else:
+ toolchain_path = self.install_toolchain_path()
+ toolchain_path = self.install_toolchain_path(host_target)
+ swiftc = os.path.join(toolchain_path, "bin", "swiftc")
# FIXME: We require llbuild build directory in order to build. Is
# there a better way to get this?
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 5e4f30ef194..16ef23f40da 100644
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
@@ -280,4 +280,6 @@ def toolchain_path(install_destdir, install_prefix):
if platform.system() == 'Darwin':
# The prefix is an absolute path, so concatenate without os.path.
built_toolchain_path += darwin_toolchain_prefix(install_prefix)
+ else:
+ built_toolchain_path += install_prefix
return built_toolchain_path
diff --git a/swift/utils/swift_build_support/swift_build_support/which.py b/swift/utils/swift_build_support/swift_build_support/which.py
index 8b329cc95cc..14df9d0aff0 100644
--- a/swift/utils/swift_build_support/swift_build_support/which.py
+++ b/swift/utils/swift_build_support/swift_build_support/which.py
@@ -17,6 +17,7 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import
+import os
from . import cache_util
from . import shell
@@ -34,7 +35,9 @@ def which(cmd):
We provide our own implementation because shutil.which() has not
been backported to Python 2.7, which we support.
"""
- out = shell.capture(['which', cmd],
+
+ which = 'which' if 'ANDROID_DATA' not in os.environ else '/system/bin/which'
+ out = shell.capture([which, cmd],
dry_run=False, echo=False,
optional=True, stderr=shell.DEVNULL)
if out is None:
@@ -83,7 +86,7 @@ class SwiftPM(product.Product):
@classmethod
def get_install_destdir(self, args, host_target, build_dir):
install_destdir = args.install_destdir
- if self.has_cross_compile_hosts(args):
+ if self.has_cross_compile_hosts(args) and not os.getenv("HOST_SWIFTC"):
build_root = os.path.dirname(build_dir)
install_destdir = '%s/intermediate-install/%s' % (build_root, host_target)
return install_destdir

View File

@ -1,33 +0,0 @@
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -1782,6 +1782,13 @@
-DSWIFT_ANDROID_DEPLOY_DEVICE_PATH:STRING="${ANDROID_DEPLOY_DEVICE_PATH}"
-DSWIFT_SDK_ANDROID_ARCHITECTURES:STRING="${ANDROID_ARCH}"
)
+ if [[ "${host}" == "${LOCAL_HOST}" ]] ; then
+ cmake_options=(
+ "${cmake_options[@]}"
+ -DCMAKE_FIND_ROOT_PATH=@TERMUX_PREFIX@
+ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ )
+ fi
fi
if [[ "${DARWIN_OVERLAY_TARGET}" != "" ]]; then
diff --git a/swift/utils/gen-static-stdlib-link-args b/swift/utils/gen-static-stdlib-link-args
index 0fa009d67d3..abd98c2493f 100755
--- a/swift/utils/gen-static-stdlib-link-args
+++ b/swift/utils/gen-static-stdlib-link-args
@@ -60,9 +60,8 @@ function write_linkfile {
fi
cat >$OUTPUTFILE <<EOF
-ldl
--lpthread
-lswiftCore
--lswiftImageInspectionShared
+-llog
$ICU_LIBS
-lstdc++
-lm

View File

@ -51,60 +51,6 @@ index b40bd4d881e..8c51c6b6857 100644
swift_android_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
list(APPEND library_search_directories ${path})
@@ -1114,11 +1113,14 @@ function(_add_swift_library_single target name)
endif()
# Only set the install RPATH if cross-compiling the host tools, in which
# case both the NDK and Sysroot paths must be set.
- if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "" AND
- NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
+ if(NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
set_target_properties("${target}"
PROPERTIES
INSTALL_RPATH "$ORIGIN")
+ else()
+ set_target_properties("${target}"
+ PROPERTIES
+ INSTALL_RPATH "@TERMUX_PREFIX@/lib:$ORIGIN")
endif()
endif()
@@ -1909,6 +1903,14 @@ function(add_swift_target_library name)
endif()
endif()
+ set(SWIFTLIB_${sdk}_SOURCES ${SWIFTLIB_SOURCES})
+ if(name STREQUAL swiftRuntime)
+ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
+ list(REMOVE_ITEM SWIFTLIB_${sdk}_SOURCES ImageInspectionELF.cpp)
+ swift_runtime_static_libraries(${sdk})
+ endif()
+ endif()
+
set(sdk_supported_archs
${SWIFT_SDK_${sdk}_ARCHITECTURES}
${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
@@ -1937,6 +1931,12 @@ function(add_swift_target_library name)
set(swiftlib_module_dependency_targets)
set(swiftlib_private_link_libraries_targets)
+ if(name STREQUAL swiftCore)
+ # This initializes swiftlib_private_link_libraries_targets for swiftCore,
+ # so don't move it away from the variable declaration just above.
+ swift_core_private_libraries(${sdk} ${arch} swiftlib_private_link_libraries_targets)
+ endif()
+
if(NOT BUILD_STANDALONE)
foreach(mod ${swiftlib_module_depends_flattened})
list(APPEND swiftlib_module_dependency_targets
@@ -1972,7 +1981,7 @@ function(add_swift_target_library name)
${SWIFTLIB_STATIC_keyword}
${SWIFTLIB_OBJECT_LIBRARY_keyword}
${SWIFTLIB_INSTALL_WITH_SHARED_keyword}
- ${SWIFTLIB_SOURCES}
+ ${SWIFTLIB_${sdk}_SOURCES}
TARGET_LIBRARY
MODULE_TARGET ${MODULE_VARIANT_NAME}
SDK ${sdk}
diff --git a/swift/cmake/modules/SwiftAndroidSupport.cmake b/swift/cmake/modules/SwiftAndroidSupport.cmake
index 9379031947d..91cecf46a37 100644
--- a/swift/cmake/modules/SwiftAndroidSupport.cmake
@ -247,11 +193,75 @@ index 9f3cf240d3d..d2ce14d5f47 100644
endif()
function(swift_create_stdlib_targets name variant define_all_alias)
diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
index a2f682ece68..95e2c6e8a99 100644
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -85,6 +85,10 @@ function(_add_target_variant_c_compile_link_flags)
endif()
endif()
+ if("${CFLAGS_SDK}" STREQUAL "ANDROID")
+ set(DEPLOYMENT_VERSION "${SWIFT_SDK_${CFLAGS_SDK}_DEPLOYMENT_VERSION}")
+ endif()
+
# MSVC, clang-cl, gcc don't understand -target.
if(CMAKE_C_COMPILER_ID MATCHES "^Clang|AppleClang$" AND
NOT SWIFT_COMPILER_IS_MSVC_LIKE)
@@ -359,11 +359,6 @@ function(_add_target_variant_link_flags)
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
list(APPEND link_libraries ${cxx_link_libraries})
- # link against the ICU libraries
- list(APPEND link_libraries
- ${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_I18N}
- ${SWIFT_ANDROID_${LFLAGS_ARCH}_ICU_UC})
-
swift_android_lib_for_arch(${LFLAGS_ARCH} ${LFLAGS_ARCH}_LIB)
foreach(path IN LISTS ${LFLAGS_ARCH}_LIB)
list(APPEND library_search_directories ${path})
@@ -1767,6 +1762,14 @@ function(add_swift_target_library name)
list(APPEND swiftlib_link_flags_all "-dynamiclib -Wl,-headerpad_max_install_names")
endif()
+ set(SWIFTLIB_${sdk}_SOURCES ${SWIFTLIB_SOURCES})
+ if(name STREQUAL swiftRuntime)
+ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
+ list(REMOVE_ITEM SWIFTLIB_${sdk}_SOURCES ImageInspectionELF.cpp)
+ swift_runtime_static_libraries(${sdk})
+ endif()
+ endif()
+
set(sdk_supported_archs
${SWIFT_SDK_${sdk}_ARCHITECTURES}
${SWIFT_SDK_${sdk}_MODULE_ARCHITECTURES})
@@ -1804,6 +1807,12 @@ function(add_swift_target_library name)
set(swiftlib_module_dependency_targets)
set(swiftlib_private_link_libraries_targets)
+ if(name STREQUAL swiftCore)
+ # This initializes swiftlib_private_link_libraries_targets for swiftCore,
+ # so don't move it away from the variable declaration just above.
+ swift_core_private_libraries(${sdk} ${arch} swiftlib_private_link_libraries_targets)
+ endif()
+
if(NOT BUILD_STANDALONE)
foreach(mod ${swiftlib_module_depends_flattened})
if(DEFINED maccatalyst_build_flavor)
@@ -1920,7 +1929,7 @@ function(add_swift_target_library name)
${SWIFTLIB_STATIC_keyword}
${SWIFTLIB_OBJECT_LIBRARY_keyword}
${SWIFTLIB_INSTALL_WITH_SHARED_keyword}
- ${SWIFTLIB_SOURCES}
+ ${SWIFTLIB_${sdk}_SOURCES}
TARGET_LIBRARY
MODULE_TARGETS ${module_variant_names}
SDK ${sdk}
diff --git a/swift/stdlib/public/Platform/CMakeLists.txt b/swift/stdlib/public/Platform/CMakeLists.txt
index 90fba95ec1b..48c39a7b9a1 100644
index 8ded40c5791..c811000b1d1 100644
--- a/swift/stdlib/public/Platform/CMakeLists.txt
+++ b/swift/stdlib/public/Platform/CMakeLists.txt
@@ -86,25 +86,29 @@ foreach(sdk ${SWIFT_SDKS})
@@ -97,6 +97,7 @@ foreach(sdk ${SWIFT_SDKS})
OUTPUT "${glibc_modulemap_out}"
FLAGS
"-DCMAKE_SDK=${sdk}"
@ -259,16 +269,12 @@ index 90fba95ec1b..48c39a7b9a1 100644
"-DGLIBC_INCLUDE_PATH=${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_INCLUDE_DIRECTORY}"
"-DGLIBC_ARCH_INCLUDE_PATH=${SWIFT_SDK_${sdk}_ARCH_${arch}_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY}")
list(APPEND glibc_modulemap_target_list ${glibc_modulemap_target})
- # If this SDK is a target for a non-native host, create a native modulemap
- # without a sysroot prefix. This is the one we'll install instead.
- if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/")
+ # If this SDK is a target for a non-native host, except if it's for Android
+ # with its own native sysroot, create a native modulemap without a sysroot
+ # prefix. This is the one we'll install instead.
+ if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/" AND
+ NOT (${sdk} STREQUAL ANDROID AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL ""))
@@ -106,18 +107,19 @@ foreach(sdk ${SWIFT_SDKS})
# with its own native sysroot, create a native modulemap without a sysroot
# prefix. This is the one we'll install instead.
if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/" AND
- NOT (${sdk} STREQUAL ANDROID AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL ""))
+ (${sdk} STREQUAL ANDROID AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL ""))
set(glibc_sysroot_relative_modulemap_out "${module_dir}/sysroot-relative-modulemaps/glibc.modulemap")
- string(REPLACE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}"
@ -288,6 +294,19 @@ index 90fba95ec1b..48c39a7b9a1 100644
"-DGLIBC_INCLUDE_PATH=${absolute_libc_include_path}"
"-DGLIBC_ARCH_INCLUDE_PATH=${absolute_libc_arch_include_path}")
diff --git a/swift/stdlib/public/SwiftShims/CMakeLists.txt b/swift/stdlib/public/SwiftShims/CMakeLists.txt
index 23ac72bcda5..23aecfc9bc5 100644
--- a/swift/stdlib/public/SwiftShims/CMakeLists.txt
+++ b/swift/stdlib/public/SwiftShims/CMakeLists.txt
@@ -206,7 +206,7 @@ endif()
swift_install_symlink_component(clang-resource-dir-symlink
LINK_NAME clang
- TARGET ../clang/${CLANG_VERSION}
+ TARGET ../clang/$ENV{TERMUX_CLANG_VERSION}
DESTINATION "lib/swift")
# Possibly install Clang headers under Clang's resource directory in case we
diff --git a/swift/stdlib/public/core/CMakeLists.txt b/swift/stdlib/public/core/CMakeLists.txt
index 7ab092655c7..494d4d62aa3 100644
--- a/swift/stdlib/public/core/CMakeLists.txt
@ -423,8 +442,8 @@ index 001d97d5174..0b51e56f631 100644
-endif()
+endfunction()
add_swift_target_library(swiftRuntime OBJECT_LIBRARY
${swift_runtime_sources}
if(SWIFT_STDLIB_USE_NONATOMIC_RC)
set(_RUNTIME_NONATOMIC_FLAGS -DSWIFT_STDLIB_USE_NONATOMIC_RC)
@@ -174,7 +174,7 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY
set(ELFISH_SDKS)
@ -444,15 +463,53 @@ index 001d97d5174..0b51e56f631 100644
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
diff --git a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
index 8efd5971030..ab306f47fd8 100644
index 7a77e125f95..7eddfea2054 100644
--- a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
+++ b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
@@ -164,7 +164,7 @@ macro(add_sourcekit_library name)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if(SOURCEKITLIB_SHARED)
set_target_properties(${name} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
- set_target_properties(${name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib/swift/linux:/usr/lib/swift/linux")
+ set_target_properties(${name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib/swift/android")
@@ -79,6 +79,9 @@ function(add_sourcekit_default_compiler_flags target)
endif()
target_compile_options(${target} PRIVATE
${c_compile_flags} -fblocks)
+ # Look in Termux sysroot for dispatch/dispatch.h from libdispatch
+ target_include_directories("${target}" SYSTEM PRIVATE
+ ${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include)
target_link_options(${target} PRIVATE
${link_flags})
target_link_directories(${target} PRIVATE
@@ -165,7 +168,7 @@ macro(add_sourcekit_library name)
endif()
endif()
- if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
if(SOURCEKITLIB_SHARED)
set_target_properties(${name} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
set_target_properties(${name} PROPERTIES INSTALL_RPATH "$ORIGIN/../lib/swift/linux:/usr/lib/swift/linux")
diff --git a/swift/tools/libSwiftSyntaxParser/CMakeLists.txt b/swift/tools/libSwiftSyntaxParser/CMakeLists.txt
index 42dda212164..2338df9072a 100644
--- a/swift/tools/libSwiftSyntaxParser/CMakeLists.txt
+++ b/swift/tools/libSwiftSyntaxParser/CMakeLists.txt
@@ -13,6 +13,9 @@ add_swift_host_library(libSwiftSyntaxParser SHARED
if(NOT SWIFT_BUILT_STANDALONE AND NOT CMAKE_C_COMPILER_ID MATCHES Clang)
add_dependencies(libSwiftSyntaxParser clang)
endif()
+# Look in Termux sysroot for Block.h from libdispatch
+target_include_directories(libSwiftSyntaxParser SYSTEM PRIVATE
+ ${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include)
target_link_libraries(libSwiftSyntaxParser PRIVATE
swiftParse)
set_target_properties(libSwiftSyntaxParser
diff --git a/swift/tools/swift-ide-test/CMakeLists.txt b/swift/tools/swift-ide-test/CMakeLists.txt
index 095e97d5f15..dae9946aba8 100644
--- a/swift/tools/swift-ide-test/CMakeLists.txt
+++ b/swift/tools/swift-ide-test/CMakeLists.txt
@@ -13,7 +13,8 @@ target_link_libraries(swift-ide-test
# If libxml2 is available, make it available for swift-ide-test.
if(LibXml2_FOUND)
- include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
+ # No way to not build this, so look in Termux sysroot for iconv.h from libiconv
+ include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR} ${SWIFT_ANDROID_NATIVE_SYSROOT}/usr/include)
target_link_libraries(swift-ide-test PRIVATE ${LIBXML2_LIBRARIES})
target_compile_definitions(swift-ide-test PRIVATE SWIFT_HAVE_LIBXML=1)
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "OpenBSD" AND NOT CMAKE_CROSSCOMPILING)

View File

@ -1,14 +1,22 @@
commit 25ee7e8f610bf71816717f45946ee8e543889e89
Date: Wed May 6 12:06:09 2020 +0530
[CMake] fix runpath for ELF platforms
Remove the absolute path to the host toolchain's stdlib from libXCTest.so and add $ORIGIN.
diff --git a/swift-corelibs-xctest/CMakeLists.txt b/swift-corelibs-xctest/CMakeLists.txt
index 289f940..9830bbb 100644
index 531e7c0..589930f 100644
--- a/swift-corelibs-xctest/CMakeLists.txt
+++ b/swift-corelibs-xctest/CMakeLists.txt
@@ -50,7 +50,9 @@ add_library(XCTest
target_link_libraries(XCTest PRIVATE
dispatch
Foundation)
+target_link_options(XCTest PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
@@ -56,6 +56,10 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(XCTest PRIVATE
dispatch
Foundation)
+ if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
+ target_link_options(XCTest PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
+ set_target_properties(XCTest PROPERTIES INSTALL_RPATH "$ORIGIN")
+ endif()
endif()
set_target_properties(XCTest PROPERTIES
+ INSTALL_RPATH "$ORIGIN"
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swift
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/swift)

View File

@ -2,28 +2,12 @@ diff --git a/swift/lib/Driver/UnixToolChains.cpp b/swift/lib/Driver/UnixToolChai
index bdc63d1ca72..971e5ded1e2 100644
--- a/swift/lib/Driver/UnixToolChains.cpp
+++ b/swift/lib/Driver/UnixToolChains.cpp
@@ -209,7 +209,8 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
getRuntimeLibraryPaths(RuntimeLibPaths, context.Args, context.OI.SDKPath,
/*Shared=*/!(staticExecutable || staticStdlib));
- if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker()) {
+ if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker() &&
+ !context.Args.hasArg(options::OPT_no_toolchain_stdlib_rpath)) {
// FIXME: We probably shouldn't be adding an rpath here unless we know
// ahead of time the standard library won't be copied.
for (auto path : RuntimeLibPaths) {
@@ -356,7 +357,13 @@ std::string toolchains::Android::getTargetForLinker() const {
}
@@ -133,7 +133,7 @@ bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T,
// copied into the bundle.
return Args.hasFlag(options::OPT_toolchain_stdlib_rpath,
options::OPT_no_toolchain_stdlib_rpath,
- !T.isAndroid());
+ true);
}
-bool toolchains::Android::shouldProvideRPathToLinker() const { return false; }
+bool toolchains::Android::shouldProvideRPathToLinker() const {
+#if defined(__ANDROID__)
+ return true;
+#else
+ return false;
+#endif
+}
std::string toolchains::Cygwin::getDefaultLinker() const {
// Cygwin uses the default BFD linker, even on ARM.
ToolChain::InvocationInfo

View File

@ -1,13 +0,0 @@
diff --git a/swift/stdlib/public/SwiftShims/CMakeLists.txt b/swift/stdlib/public/SwiftShims/CMakeLists.txt
index da408df6bae..73fd1cdfa30 100644
--- a/swift/stdlib/public/SwiftShims/CMakeLists.txt
+++ b/swift/stdlib/public/SwiftShims/CMakeLists.txt
@@ -121,7 +121,7 @@ swift_install_in_component(clang-builtin-headers
swift_install_symlink_component(clang-resource-dir-symlink
LINK_NAME clang
- TARGET ../clang/${CLANG_VERSION}
+ TARGET ../clang/@TERMUX_CLANG_VERSION@
DESTINATION "lib/swift")
# Possibly install Clang headers under Clang's resource directory in case we

View File

@ -1,212 +0,0 @@
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -690,6 +690,8 @@ function set_build_options_for_host() {
;;
android-aarch64)
SWIFT_HOST_VARIANT_ARCH="aarch64"
+ SWIFT_HOST_TRIPLE="aarch64-unknown-linux-android"
+ llvm_target_arch="AArch64"
;;
esac
;;
@@ -703,6 +705,8 @@ function set_build_options_for_host() {
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
+ -DDEFAULT_SYSROOT:STRING="$(dirname @TERMUX_PREFIX@)"
+ -DCOMPILER_RT_INCLUDE_TESTS:BOOL="OFF"
)
# If we are asked to not generate test targets for LLVM and or Swift,
@@ -1028,7 +1032,7 @@ function make_relative_symlink() {
CROSS_COMPILE_HOSTS=($CROSS_COMPILE_HOSTS)
for t in "${CROSS_COMPILE_HOSTS[@]}"; do
case ${t} in
- iphone* | appletv* | watch* | linux-armv6 | linux-armv7 )
+ iphone* | appletv* | watch* | linux-armv6 | linux-armv7 | android-aarch64 )
;;
*)
echo "Unknown host to cross-compile for: ${t}"
@@ -1060,7 +1064,7 @@ function get_host_install_destdir() {
# 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}"
else
- local host_install_destdir="${INSTALL_DESTDIR}/${host}"
+ local host_install_destdir="${INSTALL_DESTDIR}"
fi
else
local host_install_destdir="${INSTALL_DESTDIR}"
@@ -1422,6 +1426,26 @@ function swift_c_flags() {
fi
}
+function android_cross_cmake_options() {
+ local -n options=$1
+ options+=(
+ -DCMAKE_SYSTEM_NAME=Android
+ -DCMAKE_SYSTEM_VERSION=@TERMUX_PKG_API_LEVEL@
+ -DCMAKE_SYSTEM_PROCESSOR=@TERMUX_ARCH@
+ -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN="@TERMUX_STANDALONE_TOOLCHAIN@"
+ -DCMAKE_C_FLAGS="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_CXX_FLAGS="$CXXFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_MODULE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_FIND_ROOT_PATH=@TERMUX_PREFIX@
+ -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
+ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
+ -DCMAKE_HAVE_LIBC_PTHREAD=True
+ )
+}
+
function cmake_config_opt() {
product=$1
if [[ "${CMAKE_GENERATOR}" == "Xcode" ]] ; then
@@ -1653,6 +1682,13 @@ 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=(
+ "${cmake_options[@]}"
+ -DCMAKE_C_FLAGS="$(cmark_c_flags ${host}) --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_CXX_FLAGS="$(cmark_c_flags ${host}) --target=$CCTERMUX_HOST_PLATFORM"
+ )
+ fi
skip_build=${SKIP_BUILD_CMARK}
build_targets=(all)
;;
@@ -1758,6 +1794,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)
)
+ android_cross_cmake_options cmake_options
fi
;;
@@ -1768,12 +1812,18 @@ for host in "${ALL_HOSTS[@]}"; do
swift)
- if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
+ if [[ "${ANDROID_API_LEVEL}" ]]; then
+ cmake_options=(
+ "${cmake_options[@]}"
+ -DSWIFT_ANDROID_API_LEVEL:STRING="${ANDROID_API_LEVEL}"
+ )
+ fi
+
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
-DSWIFT_ANDROID_NDK_GCC_VERSION:STRING="${ANDROID_NDK_GCC_VERSION}"
- -DSWIFT_ANDROID_API_LEVEL:STRING="${ANDROID_API_LEVEL}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC:STRING="${ANDROID_ICU_UC}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_UC_INCLUDE:STRING="${ANDROID_ICU_UC_INCLUDE}"
-DSWIFT_ANDROID_${ANDROID_ARCH}_ICU_I18N:STRING="${ANDROID_ICU_I18N}"
@@ -2116,6 +2163,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="${TERMUX_SWIFT_FLAGS}"
-DLLBUILD_ENABLE_ASSERTIONS:BOOL=$(true_false "${LLBUILD_ENABLE_ASSERTIONS}")
-DLLBUILD_SUPPORT_BINDINGS:=Swift
@@ -2144,6 +2192,11 @@ for host in "${ALL_HOSTS[@]}"; do
-DSQLite3_LIBRARY:PATH="/usr/lib/libsqlite3.dylib"
)
fi
+
+ build_targets=(llbuildSwift)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ android_cross_cmake_options cmake_options
+ fi
;;
xctest)
XCTEST_BUILD_DIR=$(build_directory ${host} xctest)
@@ -2189,6 +2242,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="${TERMUX_SWIFT_FLAGS}"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2204,6 +2258,10 @@ for host in "${ALL_HOSTS[@]}"; do
-DENABLE_TESTING=YES
)
+
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ android_cross_cmake_options cmake_options
+ fi
;;
esac
@@ -2268,6 +2326,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="${TERMUX_SWIFT_FLAGS}"
-DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN}
-DCMAKE_INSTALL_PREFIX:PATH=$(get_host_install_prefix ${host})
@@ -2281,6 +2340,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DBUILD_SHARED_LIBS=$([[ ${product} == foundation_static ]] && echo "NO" || echo "YES")
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ android_cross_cmake_options cmake_options
+ fi
;;
libdispatch|libdispatch_static)
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
@@ -2307,6 +2369,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="${TERMUX_SWIFT_FLAGS}"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2315,6 +2378,11 @@ for host in "${ALL_HOSTS[@]}"; do
-DENABLE_TESTING=YES
-DBUILD_SHARED_LIBS=$([[ ${product} == libdispatch_static ]] && echo "NO" || echo "YES")
)
+
+ build_targets=(swiftDispatch)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ android_cross_cmake_options cmake_options
+ fi
;;
esac
@@ -2452,6 +2520,8 @@ for host in "${ALL_HOSTS[@]}"; do
HOST_CXX_HEADERS_DIR="$HOST_CXX_DIR/../../usr/include/c++"
elif [[ "$(uname -s)" == "Haiku" ]] ; then
HOST_CXX_HEADERS_DIR="/boot/system/develop/headers/c++"
+ elif [[ "${ANDROID_DATA}" ]] ; then
+ HOST_CXX_HEADERS_DIR="$PREFIX/include/c++"
else # Linux
HOST_CXX_HEADERS_DIR="/usr/include/c++"
fi
@@ -2929,7 +2999,14 @@ for host in "${ALL_HOSTS[@]}"; do
if [[ -z "${INSTALL_LLBUILD}" ]] ; then
continue
fi
- INSTALL_TARGETS="install-swift-build-tool install-libllbuildSwift"
+ INSTALL_TARGETS="install-libllbuildSwift"
+ # Remove most libdispatch products before building the package manager.
+ rm -rf @TERMUX_PREFIX@/lib/swift{,_static}/{Block,os}
+ rm @TERMUX_PREFIX@/lib/swift{,_static}/dispatch/*.h
+ sed -i -e "s%dispatch\.h%@TERMUX_PREFIX@/include/dispatch/dispatch.h%" \
+ -e "s%introspection\.h%@TERMUX_PREFIX@/include/dispatch/introspection.h%" \
+ @TERMUX_PREFIX@/lib/swift/dispatch/module.modulemap
+ cp @TERMUX_PREFIX@/lib/swift/dispatch/module.modulemap @TERMUX_PREFIX@/lib/swift_static/dispatch/module.modulemap
;;
# Products from this here install themselves; they don't fall-through.
lldb)

View File

@ -24,8 +24,8 @@ index 7f39ff97459..af310ec8cbf 100755
+ fi
+
for product in "${PRODUCTS[@]}"; do
# Check if we should perform this action.
tmp_product=${product}
[[ $(should_execute_action "${host}-${product/_static}-build") ]] || continue
@@ -2066,7 +2078,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_C_FLAGS="$(llvm_c_flags ${host})"
-DCMAKE_CXX_FLAGS="$(llvm_c_flags ${host})"

View File

@ -0,0 +1,127 @@
commit 5fa1d36f4b558070fc2bf54ecde19e6a35e4839e
Date: Tue Sep 1 00:45:55 2020 +0530
[build] Add the flags to enable cross-compiling the corelibs
Pass the Swift and CMake flags needed to cross-compile Foundation and so on, with
the first example of Android AArch64. Add a new flag, --cross-compile-deps-path,
which is used to search for cross-compiled libraries, like libcurl, that the
corelibs depend on.
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index 6f0c2b5bf71..db6e0ad10d6 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -240,6 +240,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"
@@ -1543,6 +1544,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DCMAKE_BUILD_TYPE:STRING="${CMARK_BUILD_TYPE}"
"${cmark_cmake_options[@]}"
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ add_cross_cmake_options ${host} cmake_options
+ fi
build_targets=(all)
;;
@@ -1647,6 +1651,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)
)
+ add_cross_cmake_options ${host} cmake_options
fi
;;
@@ -2017,6 +2022,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="$(common_swift_flags ${host})"
-DLLBUILD_ENABLE_ASSERTIONS:BOOL=$(true_false "${LLBUILD_ENABLE_ASSERTIONS}")
-DLLBUILD_SUPPORT_BINDINGS:=Swift
@@ -2032,6 +2038,16 @@ for host in "${ALL_HOSTS[@]}"; do
-DFoundation_DIR:PATH=$(build_directory ${host} foundation)/cmake/modules
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ add_cross_cmake_options ${host} 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 )
@@ -2090,6 +2106,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="$(common_swift_flags ${host})"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2105,6 +2122,9 @@ for host in "${ALL_HOSTS[@]}"; do
-DENABLE_TESTING=YES
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ add_cross_cmake_options ${host} cmake_options
+ fi
;;
esac
@@ -2158,6 +2175,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="$(common_swift_flags ${host})"
-DCMAKE_INSTALL_PREFIX:PATH=$(get_host_install_prefix ${host})
${LIBICU_BUILD_ARGS[@]}
@@ -2173,6 +2191,17 @@ for host in "${ALL_HOSTS[@]}"; do
-DBUILD_SHARED_LIBS=$([[ ${product} == foundation_static ]] && echo "NO" || echo "YES")
)
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ add_cross_cmake_options ${host} 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
+
;;
libdispatch|libdispatch_static)
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
@@ -2199,6 +2228,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="$(common_swift_flags ${host})"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
@@ -2207,6 +2237,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
+ add_cross_cmake_options ${host} cmake_options
+ fi
;;
esac

View File

@ -0,0 +1,169 @@
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -703,6 +705,7 @@ function set_build_options_for_host() {
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
+ -DCOMPILER_RT_INCLUDE_TESTS:BOOL="OFF"
)
fi
@@ -743,6 +743,7 @@ function set_build_options_for_host() {
llvm_cmake_options+=(
-DLLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j ${BUILD_JOBS}"
+ -DDEFAULT_SYSROOT:STRING="$(dirname @TERMUX_PREFIX@)"
)
swift_cmake_options+=(
-DLLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j ${BUILD_JOBS}"
@@ -1028,7 +1032,7 @@ function make_relative_symlink() {
CROSS_COMPILE_HOSTS=($CROSS_COMPILE_HOSTS)
for t in "${CROSS_COMPILE_HOSTS[@]}"; do
case ${t} in
- macosx-arm64* | iphone* | appletv* | watch* | linux-armv6 | linux-armv7 )
+ macosx-arm64* | iphone* | appletv* | watch* | linux-armv6 | linux-armv7 | android-a* )
;;
*)
echo "Unknown host to cross-compile for: ${t}"
@@ -1060,7 +1064,7 @@ function get_host_install_destdir() {
# This assumes that all hosts are merged to the lipo.
local host_install_destdir="${INSTALL_DESTDIR}"
else
- local host_install_destdir="${INSTALL_DESTDIR}/${host}"
+ local host_install_destdir="${INSTALL_DESTDIR}"
fi
else
local host_install_destdir="${INSTALL_DESTDIR}"
@@ -1422,6 +1426,36 @@ function swift_c_flags() {
fi
}
+function common_swift_flags() {
+ local host=$1
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
+ case $host in
+ android-a*)
+ echo -n "${TERMUX_SWIFT_FLAGS}"
+ ;;
+ *)
+ echo "error: Swift cross-compilation flags for ${host} have not been set."
+ exit 1
+ ;;
+ esac
+ fi
+}
+
+function add_cross_cmake_options() {
+ local host=$1
+ local -n options=$2
+ case $host in
+ android-a*)
+ options+=(
+ -DCMAKE_SYSTEM_NAME=Android
+ -DCMAKE_SYSTEM_VERSION=${ANDROID_API_LEVEL}
+ -DCMAKE_SYSTEM_PROCESSOR=${ANDROID_ARCH}
+ -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN:PATH=${ANDROID_NDK}
+ )
+ ;;
+ esac
+}
+
function cmake_config_opt() {
product=$1
if [[ "${CMAKE_GENERATOR}" == "Xcode" ]] ; then
@@ -1546,6 +1578,10 @@ for host in "${ALL_HOSTS[@]}"; do
)
if [[ $(is_cross_tools_host ${host}) ]] ; then
add_cross_cmake_options ${host} cmake_options
+ cmake_options+=(
+ -DCMAKE_C_FLAGS="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_CXX_FLAGS="$CXXFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ )
fi
build_targets=(all)
;;
@@ -1623,7 +1675,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DCLANG_TOOL_ARCMT_TEST_BUILD=NO
-DCLANG_TOOL_C_ARCMT_TEST_BUILD=NO
-DCLANG_TOOL_C_INDEX_TEST_BUILD=NO
- -DCLANG_TOOL_DRIVER_BUILD=$(false_true "${BUILD_RUNTIME_WITH_HOST_COMPILER}")
+ -DCLANG_TOOL_DRIVER_BUILD=TRUE
-DCLANG_TOOL_DIAGTOOL_BUILD=NO
-DCLANG_TOOL_SCAN_BUILD_BUILD=NO
-DCLANG_TOOL_SCAN_VIEW_BUILD=NO
@@ -1652,6 +1688,10 @@ for host in "${ALL_HOSTS[@]}"; do
-DLLVM_NATIVE_BUILD=$(build_directory "${LOCAL_HOST}" llvm)
)
add_cross_cmake_options ${host} cmake_options
+ cmake_options+=(
+ -DCMAKE_CXX_FLAGS="$CXXFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ )
fi
;;
@@ -1768,7 +1812,7 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi
- if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
+ if [[ $(is_cross_tools_host ${host}) ]] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
@@ -2045,6 +2045,8 @@ for host in "${ALL_HOSTS[@]}"; do
cmake_options+=(
-DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ -DCMAKE_CXX_FLAGS="$CXXFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
)
fi
@@ -2199,6 +2201,9 @@ for host in "${ALL_HOSTS[@]}"; do
cmake_options+=(
-DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER
+ -DCMAKE_C_FLAGS="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_HAVE_LIBC_PTHREAD=True
)
fi
@@ -2239,6 +2243,11 @@ for host in "${ALL_HOSTS[@]}"; do
)
if [[ $(is_cross_tools_host ${host}) ]] ; then
add_cross_cmake_options ${host} cmake_options
+ cmake_options+=(
+ -DCMAKE_C_FLAGS="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS"
+ -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ -DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS --target=$CCTERMUX_HOST_PLATFORM"
+ )
fi
;;
esac
@@ -2929,7 +2999,20 @@ for host in "${ALL_HOSTS[@]}"; do
if [[ -z "${INSTALL_LLBUILD}" ]] ; then
continue
fi
- INSTALL_TARGETS="install-swift-build-tool install-libllbuildSwift"
+ INSTALL_TARGETS="install-libllbuildSwift"
+ # Remove most libdispatch products before building the package manager.
+ rm -rf @TERMUX_PREFIX@/lib/swift{,_static}/{Block,os}
+ rm @TERMUX_PREFIX@/lib/swift{,_static}/dispatch/*.h
+ sed -i -e "s%dispatch\.h%@TERMUX_PREFIX@/include/dispatch/dispatch.h%" \
+ -e "s%introspection\.h%@TERMUX_PREFIX@/include/dispatch/introspection.h%" \
+ @TERMUX_PREFIX@/lib/swift/dispatch/module.modulemap
+ sed -i -e "s%dispatch\.h%@TERMUX_PREFIX@/include/dispatch/dispatch.h%" \
+ -e "s%introspection\.h%@TERMUX_PREFIX@/include/dispatch/introspection.h%" \
+ @TERMUX_PREFIX@/lib/swift_static/dispatch/module.modulemap
+ if [[ -z "${ANDROID_DATA}" ]] ; then
+ mv @TERMUX_PREFIX@/lib/swift/${host/-//}/glibc.modulemap @TERMUX_PREFIX@/glibc-native.modulemap
+ cp $(build_directory ${host} swift)/lib/swift/${host/-//}/glibc.modulemap @TERMUX_PREFIX@/lib/swift/${host/-//}/glibc.modulemap
+ fi
;;
# Products from this here install themselves; they don't fall-through.
lldb)
if [[ -z "${INSTALL_LLDB}" ]] ; then

View File

@ -2,6 +2,15 @@ diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index f7439427..5f284c48 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -167,7 +167,7 @@ def parse_build_args(args):
args.clang_path = get_clang_path(args)
args.cmake_path = get_cmake_path(args)
args.ninja_path = get_ninja_path(args)
- if args.cross_compile_hosts: # Use XCBuild target directory when building for multiple arches.
+ if args.cross_compile_hosts and not args.cross_compiling: # Use XCBuild target directory when building for multiple arches.
args.target_dir = os.path.join(args.build_dir, "apple/Products")
else:
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
@@ -232,7 +232,7 @@ def get_ninja_path(args):
def get_build_target(args):
"""Returns the target-triple of the current machine."""
@ -31,12 +40,12 @@ index f7439427..5f284c48 100755
@@ -366,7 +368,13 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
"""Runs CMake if needed, then builds with Ninja."""
cache_path = os.path.join(build_dir, "CMakeCache.txt")
if not os.path.isfile(cache_path) or args.reconfigure:
if args.reconfigure or not os.path.isfile(cache_path) or not args.swiftc_path in open(cache_path).read():
- swift_flags = ""
+ if args.cross_compiling:
+ # The termux prefix flag is needed because the Swift flags pass the
+ # standalone toolchain as the sdk, ie the sysroot.
+ swift_flags = os.getenv("TERMUX_SWIFT_FLAGS") + " -Xcc -I@TERMUX_PREFIX@/include"
+ swift_flags = os.getenv("TERMUX_SWIFTPM_FLAGS") + " -resource-dir @TERMUX_PREFIX@/lib/swift -Xcc -I@TERMUX_PREFIX@/include"
+ else:
+ swift_flags = ""
+
@ -65,35 +74,33 @@ index f7439427..5f284c48 100755
+ cmake_flags.append("-DTSC_DIR=" + os.path.join(args.tsc_build_dir, "cmake/modules"))
+
if platform.system() == 'Darwin':
cmake_flags.append("-DCMAKE_C_FLAGS=-target x86_64-apple-macosx10.10")
cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=10.10")
@@ -451,12 +465,17 @@ def build_swiftpm_with_swiftpm(args):
cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target))
cmake_flags.append("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)
@@ -451,12 +465,15 @@ def build_swiftpm_with_swiftpm(args):
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
note("Building SwiftPM (with swift-build)")
- call_swiftpm(args, [
- swiftpm_args = [
- "SWIFT_EXEC=" + args.swiftc_path,
- "SWIFTPM_PD_LIBS=" + os.path.join(args.bootstrap_dir, "pm"),
- os.path.join(args.bootstrap_dir, "bin/swift-build"),
- "--disable-sandbox",
- ])
- ]
+ swiftpm_args = [ "SWIFT_EXEC=" + args.swiftc_path ]
+
+ if args.cross_compiling:
+ swiftpm_args.append(os.path.join(os.path.split(args.swiftc_path)[0] + "/swift-build"))
+ swiftpm_args.append(os.path.join(os.path.split(args.swiftc_path)[0], "swift-build"))
+ else:
+ swiftpm_args.append("SWIFTPM_PD_LIBS=" + os.path.join(args.bootstrap_dir, "pm"))
+ swiftpm_args.append(os.path.join(args.bootstrap_dir, "bin/swift-build"))
+
+ swiftpm_args.append("--disable-sandbox")
+
+ call_swiftpm(args, swiftpm_args)
# Setup symlinks that'll allow using swiftpm from the build directory.
symlink_force(args.swiftc_path, os.path.join(args.target_dir, args.conf, "swiftc"))
build_target = get_build_target(args)
cross_compile_hosts = args.cross_compile_hosts
@@ -510,15 +529,16 @@ def get_swiftpm_env_cmd(args):
env_cmd.append("SWIFTPM_LLBUILD_FWK=1")
env_cmd.append("SWIFTCI_USE_LOCAL_DEPS=1")
env_cmd.append("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)
- libs_joined = ":".join([
- os.path.join(args.bootstrap_dir, "lib"),
@ -114,29 +121,26 @@ index f7439427..5f284c48 100755
env_cmd.append("LD_LIBRARY_PATH=%s" % libs_joined)
return env_cmd
@@ -531,6 +551,13 @@ def get_swiftpm_flags(args):
"--build-path", args.build_dir,
]
@@ -600,13 +618,20 @@ def get_swiftpm_flags(args):
)
+ if args.cross_compiling:
# Don't use GNU strerror_r on Android.
- if 'ANDROID_DATA' in os.environ:
- build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xswiftc", "-no-toolchain-stdlib-rpath"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
build_target = get_build_target(args)
cross_compile_hosts = args.cross_compile_hosts
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
build_flags += ["--arch", "x86_64", "--arch", "arm64"]
+ elif args.cross_compiling and "android-@TERMUX_ARCH@" in cross_compile_hosts:
+ build_flags.extend([
+ "--destination", "@TERMUX_PKG_BUILDDIR@/swiftpm-android-flags.json",
+ "-Xlinker", "-rpath", "-Xlinker", "@TERMUX_PREFIX@/lib",
+ "-Xcc", "-I@TERMUX_PREFIX@/include",
+ ])
+
if args.release:
build_flags.extend([
"--configuration", "release",
@@ -571,8 +598,10 @@ def get_swiftpm_flags(args):
error("the command `%s -print-target-info` didn't return a valid runtime library path" % args.swiftc_path)
# Don't use GNU strerror_r on Android.
- if 'ANDROID_DATA' in os.environ:
+ if 'ANDROID_DATA' in os.environ or args.cross_compiling:
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xswiftc", "-no-toolchain-stdlib-rpath"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
return build_flags
elif cross_compile_hosts:
error("cannot cross-compile for %s" % cross_compile_hosts)

View File

@ -7,7 +7,7 @@
"-fPIC"
],
"extra-swiftc-flags": [
"-sdk", "@TERMUX_STANDALONE_TOOLCHAIN@/sysroot", "-resource-dir", "@TERMUX_PREFIX@/lib/swift",
"-resource-dir", "@TERMUX_PREFIX@/lib/swift",
"-tools-directory", "@TERMUX_STANDALONE_TOOLCHAIN@/@TERMUX_HOST_PLATFORM@/bin",
"-Xclang-linker", "--target=@CCTERMUX_HOST_PLATFORM@", "-L@TERMUX_PREFIX@/lib",
"-L@TERMUX_STANDALONE_TOOLCHAIN@/lib/gcc/@TERMUX_HOST_PLATFORM@/4.9.x"

View File

@ -32,10 +32,10 @@ index b6d925e1..3e546554 100644
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}
OUTPUT_NAME PackageDescription
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/${PACKAGE_DESCRIPTION_VERSION}
diff --git a/swiftpm/TSC/Sources/TSCBasic/CMakeLists.txt b/swiftpm/TSC/Sources/TSCBasic/CMakeLists.txt
index 50e1ba60..e47b87e7 100644
--- a/swiftpm/TSC/Sources/TSCBasic/CMakeLists.txt
+++ b/swiftpm/TSC/Sources/TSCBasic/CMakeLists.txt
diff --git a/swiftpm/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt b/swiftpm/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
index bbc43d98..bc5ee576 100644
--- a/swiftpm/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
+++ b/swiftpm/swift-tools-support-core/Sources/TSCBasic/CMakeLists.txt
@@ -53,7 +53,7 @@ target_link_libraries(TSCBasic PUBLIC
TSCLibc)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)