2020-06-13 14:45:59 +02:00
|
|
|
TERMUX_PKG_HOMEPAGE=https://swift.org/
|
2020-02-17 18:24:10 +01:00
|
|
|
TERMUX_PKG_DESCRIPTION="Swift is a high-performance system programming language"
|
|
|
|
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
|
2020-08-06 19:52:08 +02:00
|
|
|
TERMUX_PKG_VERSION=5.2.5
|
2020-08-21 08:38:55 +02:00
|
|
|
TERMUX_PKG_REVISION=2
|
2020-02-17 18:24:10 +01:00
|
|
|
SWIFT_RELEASE="RELEASE"
|
|
|
|
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
|
2020-08-06 19:52:08 +02:00
|
|
|
TERMUX_PKG_SHA256=2353bb00dada11160945729a33af94150b7cf0a6a38fbe975774a6e244dbc548
|
2020-02-17 18:24:10 +01:00
|
|
|
TERMUX_PKG_HOSTBUILD=true
|
2020-07-10 08:05:58 +02:00
|
|
|
TERMUX_PKG_DEPENDS="binutils-gold, clang, libc++, ndk-sysroot, libandroid-glob, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild"
|
2020-02-17 18:24:10 +01:00
|
|
|
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_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"
|
|
|
|
|
2020-04-30 13:56:12 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
|
2020-06-13 14:45:59 +02:00
|
|
|
SWIFT_BUILD_FLAGS="--build-swift-static-stdlib --swift-install-components='$SWIFT_COMPONENTS;stdlib;sdk-overlay'"
|
2020-04-30 13:56:12 +02:00
|
|
|
else
|
2020-07-28 09:48:36 +02:00
|
|
|
SWIFT_BIN="swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE-ubuntu20.04"
|
|
|
|
SWIFT_BINDIR="$TERMUX_PKG_HOSTBUILD_DIR/$SWIFT_BIN/usr/bin"
|
2020-02-17 18:24:10 +01:00
|
|
|
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"
|
2020-07-28 09:48:36 +02:00
|
|
|
SWIFT_BUILD_FLAGS="$SWIFT_ANDROID_NDK_FLAGS --build-toolchain-only --skip-build-android
|
2020-04-30 13:56:12 +02:00
|
|
|
--cross-compile-hosts=android-$TERMUX_ARCH --swift-install-components='$SWIFT_COMPONENTS'
|
2020-07-28 09:48:36 +02:00
|
|
|
--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"
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
|
2020-07-16 23:58:48 +02:00
|
|
|
termux_step_post_get_source() {
|
2020-02-17 18:24:10 +01:00
|
|
|
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
|
|
|
|
# The Swift build-script requires a particular organization of source directories,
|
|
|
|
# which the following sets up.
|
|
|
|
mkdir .temp
|
|
|
|
mv [a-zA-Z]* .temp/
|
|
|
|
mv .temp swift
|
|
|
|
|
|
|
|
declare -A library_checksums
|
2020-08-06 19:52:08 +02:00
|
|
|
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
|
2020-02-17 18:24:10 +01:00
|
|
|
|
|
|
|
for library in "${!library_checksums[@]}"; do \
|
|
|
|
termux_download \
|
|
|
|
https://github.com/apple/$library/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz \
|
|
|
|
$TERMUX_PKG_CACHEDIR/$library-$TERMUX_PKG_VERSION.tar.gz \
|
|
|
|
${library_checksums[$library]}
|
|
|
|
tar xf $TERMUX_PKG_CACHEDIR/$library-$TERMUX_PKG_VERSION.tar.gz
|
2020-05-09 13:09:43 +02:00
|
|
|
mv $library-swift-${TERMUX_PKG_VERSION}-$SWIFT_RELEASE $library
|
2020-02-17 18:24:10 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
mv swift-cmark cmark
|
|
|
|
mv swift-llbuild llbuild
|
|
|
|
mv swift-package-manager swiftpm
|
|
|
|
|
2020-04-30 13:56:12 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
|
|
|
termux_download \
|
2020-07-28 09:48:36 +02:00
|
|
|
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 \
|
2020-08-06 19:52:08 +02:00
|
|
|
1350f1775469bc129dc4b53e324c5748c5f63eff922c581faf38a02e41e4bb15
|
2020-04-30 13:56:12 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-17 18:24:10 +01:00
|
|
|
# The Swift compiler searches for the clang headers so symlink against them.
|
2020-06-13 14:45:59 +02:00
|
|
|
export TERMUX_CLANG_VERSION=$(grep ^TERMUX_PKG_VERSION= $TERMUX_PKG_BUILDER_DIR/../libllvm/build.sh | cut -f2 -d=)
|
2020-02-17 18:24:10 +01:00
|
|
|
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.
|
2020-07-07 20:06:41 +02:00
|
|
|
ln -s $(command -v python2) $TERMUX_PKG_BUILDDIR/python
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
2020-04-26 11:52:25 +02:00
|
|
|
export PATH=$TERMUX_PKG_BUILDDIR:$PATH
|
2020-02-17 18:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_host_build() {
|
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
2020-04-26 11:52:25 +02:00
|
|
|
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
|
2020-07-28 09:48:36 +02:00
|
|
|
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz
|
2020-04-26 11:52:25 +02:00
|
|
|
fi
|
2020-02-17 18:24:10 +01:00
|
|
|
|
|
|
|
termux_setup_cmake
|
|
|
|
termux_setup_ninja
|
|
|
|
termux_setup_standalone_toolchain
|
|
|
|
|
2020-04-26 11:52:25 +02:00
|
|
|
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
|
2020-04-30 13:56:12 +02:00
|
|
|
# to clang-10 instead.
|
2020-04-26 11:52:25 +02:00
|
|
|
if [ -z "$CLANG" ]; then
|
2020-04-30 13:56:12 +02:00
|
|
|
CLANG=$(command -v clang-10)
|
|
|
|
CLANGXX=$(command -v clang++-10)
|
2020-04-26 11:52:25 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-17 18:24:10 +01:00
|
|
|
# Natively compile llvm-tblgen and some other files needed later, and cross-compile
|
|
|
|
# the Swift stdlib.
|
|
|
|
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 \
|
2020-04-26 11:52:25 +02:00
|
|
|
--host-cc=$CLANG --host-cxx=$CLANGXX
|
2020-06-13 14:45:59 +02:00
|
|
|
|
|
|
|
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
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_pre_configure() {
|
|
|
|
if [ "$TERMUX_PKG_QUICK_REBUILD" = "false" ]; then
|
|
|
|
cd llbuild
|
|
|
|
# A single patch needed from the existing llbuild package
|
|
|
|
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../llbuild/lib-llvm-Support-CmakeLists.txt.patch
|
|
|
|
|
2020-04-30 13:56:12 +02:00
|
|
|
cd ../llvm-project
|
|
|
|
patch -p2 < $TERMUX_PKG_BUILDER_DIR/../libllvm/tools-clang-lib-Driver-ToolChain.cpp.patch
|
|
|
|
cd llvm
|
|
|
|
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/include-llvm-ADT-Triple.h.patch
|
2020-07-07 20:06:41 +02:00
|
|
|
cd ../..
|
2020-04-30 13:56:12 +02:00
|
|
|
|
2020-07-28 09:48:36 +02:00
|
|
|
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
|
2020-06-13 14:45:59 +02:00
|
|
|
|
2020-08-21 08:38:55 +02:00
|
|
|
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
|
2020-06-13 14:45:59 +02:00
|
|
|
$TERMUX_PKG_BUILDER_DIR/swiftpm-Utilities-bootstrap | \
|
2020-08-21 08:38:55 +02:00
|
|
|
sed "s%\@TERMUX_PKG_BUILDDIR\@%${TERMUX_PKG_BUILDDIR}%g" | \
|
2020-06-13 14:45:59 +02:00
|
|
|
sed "s%\@TERMUX_ARCH\@%${TERMUX_ARCH}%g" | patch -p1
|
2020-08-21 08:38:55 +02:00
|
|
|
|
|
|
|
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
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_make() {
|
2020-06-13 14:45:59 +02:00
|
|
|
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 \
|
|
|
|
-L$TERMUX_STANDALONE_TOOLCHAIN/lib/gcc/$TERMUX_HOST_PLATFORM/4.9.x \
|
|
|
|
-tools-directory $TERMUX_STANDALONE_TOOLCHAIN/$TERMUX_HOST_PLATFORM/bin \
|
2020-07-07 20:06:41 +02:00
|
|
|
-Xlinker -rpath -Xlinker $TERMUX_PREFIX/lib"
|
2020-07-28 09:48:36 +02:00
|
|
|
export HOST_SWIFTC="$SWIFT_BINDIR/swiftc"
|
2020-06-13 14:45:59 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2020-04-30 13:56:12 +02:00
|
|
|
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
|
2020-06-13 14:45:59 +02:00
|
|
|
$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
|
2020-02-17 18:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_make_install() {
|
2020-06-13 14:45:59 +02:00
|
|
|
rm $TERMUX_PREFIX/lib/swift/pm/llbuild/libllbuild.so
|
2020-07-28 09:48:36 +02:00
|
|
|
rm $TERMUX_PREFIX/lib/swift/android/lib{dispatch,BlocksRuntime}.so
|
2020-06-13 14:45:59 +02:00
|
|
|
|
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
|
|
|
cp $TERMUX_PKG_BUILDDIR/glibc-native.modulemap \
|
|
|
|
$TERMUX_PREFIX/lib/swift/android/$TERMUX_ARCH/glibc.modulemap
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
}
|