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-09-07 18:23:03 +02:00
|
|
|
TERMUX_PKG_MAINTAINER="@buttaface"
|
2021-05-25 21:31:42 +02:00
|
|
|
TERMUX_PKG_VERSION=5.4.1
|
2021-06-16 17:50:22 +02:00
|
|
|
TERMUX_PKG_REVISION=1
|
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
|
2021-05-25 21:31:42 +02:00
|
|
|
TERMUX_PKG_SHA256=9634b9424cf8b4162e7bb7da44c475081019b1bce6b9f9d958b4780acfc0de85
|
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"
|
2021-05-25 21:31:42 +02:00
|
|
|
TERMUX_PKG_BUILD_DEPENDS="cmake, ninja, perl, pkg-config, rsync"
|
2020-11-11 07:56:38 +01:00
|
|
|
TERMUX_PKG_BLACKLISTED_ARCHES="i686"
|
2020-02-17 18:24:10 +01:00
|
|
|
TERMUX_PKG_NO_STATICSPLIT=true
|
|
|
|
|
2020-09-07 18:23:03 +02:00
|
|
|
SWIFT_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;swift-remote-mirror;parser-lib;license;sourcekit-inproc;stdlib;sdk-overlay"
|
2020-02-17 18:24:10 +01:00
|
|
|
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-09-07 18:23:03 +02:00
|
|
|
SWIFT_BUILD_FLAGS="$SWIFT_TOOLCHAIN_FLAGS $SWIFT_PATH_FLAGS"
|
2020-02-17 18:24:10 +01:00
|
|
|
|
2020-09-07 18:23:03 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
2020-07-28 09:48:36 +02:00
|
|
|
SWIFT_BIN="swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE-ubuntu20.04"
|
2021-06-02 21:56:40 +02:00
|
|
|
export SWIFT_BINDIR="$TERMUX_PKG_HOSTBUILD_DIR/$SWIFT_BIN/usr/bin"
|
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
|
2021-05-26 10:25:17 +02:00
|
|
|
# The Swift build-script requires a particular organization of source
|
|
|
|
# directories, which the following sets up.
|
2020-02-17 18:24:10 +01:00
|
|
|
mkdir .temp
|
|
|
|
mv [a-zA-Z]* .temp/
|
|
|
|
mv .temp swift
|
|
|
|
|
|
|
|
declare -A library_checksums
|
2021-05-25 21:31:42 +02:00
|
|
|
library_checksums[swift-cmark]=2fc256d5c36915634f59accc55dd478cd10d18c7ba680e9df7cbb905188b3de3
|
|
|
|
library_checksums[llvm-project]=1afc3ca829031b3b5df58dc593cbe5cfac5b1044c1d9bc35ed1d3ed0cc093d03
|
|
|
|
library_checksums[swift-corelibs-libdispatch]=2435395ac2f572fccd996b0ea6a6a467301c05387cdd8db2edfd6a0055807dcc
|
|
|
|
library_checksums[swift-corelibs-foundation]=92b351d5b10b9c663137cdb608719f34ff919c9abfb8515d868f25b392d42cf6
|
|
|
|
library_checksums[swift-corelibs-xctest]=4215e1a00302dcec907033754735db9a7e9849767ebacf759ca6ff3e36f8b11d
|
|
|
|
library_checksums[swift-llbuild]=77dcf01c0b9351aba50f6ad9448dd8e1ad03d53e14c90b62c602616fd3adb0a1
|
2021-04-30 10:06:03 +02:00
|
|
|
library_checksums[swift-argument-parser]=6743338612be50a5a32127df0a3dd1c34e695f5071b1213f128e6e2b27c4364a
|
|
|
|
library_checksums[Yams]=8bbb28ef994f60afe54668093d652e4d40831c79885fa92b1c2cd0e17e26735a
|
2021-05-25 21:31:42 +02:00
|
|
|
library_checksums[swift-driver]=904b4f03ee68f8c022919e77c83cc263df0366a42fe6da6801531756b196bc56
|
|
|
|
library_checksums[swift-tools-support-core]=fa41540de20c9f8508b357040666a5a0a5bd6b280204321f5367b3af35aa9586
|
|
|
|
library_checksums[swift-package-manager]=36ed5dd26b71e7aec0cac2ae7c6624cc4b4c1fb313c68e03b4c8f6051ab5edc2
|
2020-02-17 18:24:10 +01:00
|
|
|
|
|
|
|
for library in "${!library_checksums[@]}"; do \
|
2021-01-14 16:12:45 +01:00
|
|
|
if [ "$library" = "swift-argument-parser" ]; then
|
|
|
|
GH_ORG="apple"
|
2021-04-30 10:06:03 +02:00
|
|
|
SRC_VERSION="0.4.1"
|
2021-01-14 16:12:45 +01:00
|
|
|
TAR_NAME=$SRC_VERSION
|
|
|
|
elif [ "$library" = "Yams" ]; then
|
|
|
|
GH_ORG="jpsim"
|
2021-04-30 10:06:03 +02:00
|
|
|
SRC_VERSION="4.0.2"
|
2021-01-14 16:12:45 +01:00
|
|
|
TAR_NAME=$SRC_VERSION
|
|
|
|
else
|
|
|
|
GH_ORG="apple"
|
|
|
|
SRC_VERSION=$SWIFT_RELEASE
|
|
|
|
TAR_NAME=swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE
|
|
|
|
fi
|
|
|
|
|
2020-02-17 18:24:10 +01:00
|
|
|
termux_download \
|
2021-01-14 16:12:45 +01:00
|
|
|
https://github.com/$GH_ORG/$library/archive/$TAR_NAME.tar.gz \
|
|
|
|
$TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz \
|
2020-02-17 18:24:10 +01:00
|
|
|
${library_checksums[$library]}
|
2021-01-14 16:12:45 +01:00
|
|
|
tar xf $TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz
|
|
|
|
mv $library-$TAR_NAME $library
|
2020-02-17 18:24:10 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
mv swift-cmark cmark
|
|
|
|
mv swift-llbuild llbuild
|
2021-01-14 16:12:45 +01:00
|
|
|
mv Yams yams
|
2020-02-17 18:24:10 +01:00
|
|
|
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 \
|
2021-05-25 21:31:42 +02:00
|
|
|
2bc30169bd8a761a88b6ae2fb5bb7854f800e5dea7ff116d903347290d6b61f7
|
2020-04-30 13:56:12 +02:00
|
|
|
fi
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
2020-09-07 18:23:03 +02:00
|
|
|
# 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=)
|
2020-02-17 18:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_host_build() {
|
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
|
|
|
|
termux_setup_cmake
|
|
|
|
termux_setup_ninja
|
|
|
|
termux_setup_standalone_toolchain
|
|
|
|
|
2021-06-02 21:56:40 +02:00
|
|
|
local SKIP_BUILD=
|
|
|
|
test $TERMUX_ARCH != 'arm' && SKIP_BUILD="--skip-build-cmark --skip-build-llvm --skip-build-swift"
|
|
|
|
|
2020-09-07 18:23:03 +02:00
|
|
|
# Natively compile llvm-tblgen and some other files needed later.
|
2020-02-17 18:24:10 +01:00
|
|
|
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
|
2021-06-02 21:56:40 +02:00
|
|
|
-R --no-assertions -j $TERMUX_MAKE_PROCESSES --build-subdir=. \
|
|
|
|
$SKIP_BUILD --build-toolchain-only \
|
2020-09-07 18:23:03 +02:00
|
|
|
--host-cc=$TERMUX_STANDALONE_TOOLCHAIN/bin/clang \
|
|
|
|
--host-cxx=$TERMUX_STANDALONE_TOOLCHAIN/bin/clang++
|
|
|
|
|
|
|
|
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz -C $TERMUX_PKG_HOSTBUILD_DIR
|
2021-06-02 21:56:40 +02:00
|
|
|
if [ "$TERMUX_ARCH" == "arm" ]; then
|
|
|
|
rm $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib/swift/FrameworkABIBaseline
|
|
|
|
rm -rf $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib/swift/migrator
|
|
|
|
cp -r $SWIFT_BIN/usr/lib/swift $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib
|
|
|
|
ln -sf $SWIFT_BINDIR/../lib/clang/10.0.0 $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib/swift/clang
|
|
|
|
patchelf --set-rpath \$ORIGIN $TERMUX_PKG_BUILDDIR/swift-linux-x86_64/lib/swift/linux/libicu{uc,i18n}swift.so.65.1
|
|
|
|
fi
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_pre_configure() {
|
2020-09-23 22:16:17 +02:00
|
|
|
export SWIFT_ARCH=$TERMUX_ARCH
|
|
|
|
test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7'
|
2020-02-17 18:24:10 +01:00
|
|
|
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
|
2020-12-22 19:47:36 +01:00
|
|
|
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/clang-lib-Driver-ToolChain.cpp.patch
|
|
|
|
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/clang-lib-Driver-ToolChains-Linux.cpp.patch
|
2020-12-16 02:57:00 +01:00
|
|
|
cd ..
|
2020-04-30 13:56:12 +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 | \
|
2021-01-14 16:12:45 +01:00
|
|
|
sed "s%\@TERMUX_PKG_BUILDDIR\@%${TERMUX_PKG_BUILDDIR}%g" | patch -p1
|
2020-08-21 08:38:55 +02:00
|
|
|
|
2020-09-07 18:23:03 +02:00
|
|
|
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" | \
|
2020-09-23 22:16:17 +02:00
|
|
|
sed "s%\@SWIFT_ARCH\@%${SWIFT_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json
|
2020-09-07 18:23:03 +02:00
|
|
|
fi
|
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
|
2021-06-02 21:56:40 +02:00
|
|
|
local SWIFT_TOOLCHAIN=
|
|
|
|
test $SWIFT_ARCH != 'armv7' && SWIFT_TOOLCHAIN="--native-swift-tools-path=$SWIFT_BINDIR"
|
|
|
|
|
2020-11-06 17:02:29 +01:00
|
|
|
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android
|
|
|
|
--android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_ARCH
|
2021-01-14 16:12:45 +01:00
|
|
|
--android-icu-uc $TERMUX_PREFIX/lib/libicuuc.so
|
2020-09-23 22:16:17 +02:00
|
|
|
--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
|
2020-11-06 17:02:29 +01:00
|
|
|
--skip-local-build --skip-local-host-install
|
2020-09-23 22:16:17 +02:00
|
|
|
--cross-compile-hosts=android-$SWIFT_ARCH --cross-compile-deps-path=$TERMUX_PREFIX
|
2021-06-02 21:56:40 +02:00
|
|
|
$SWIFT_TOOLCHAIN
|
2020-09-23 22:16:17 +02:00
|
|
|
--native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin"
|
2020-06-13 14:45:59 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-30 13:56:12 +02:00
|
|
|
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
|
2021-01-14 16:12:45 +01:00
|
|
|
$SWIFT_BUILD_FLAGS --xctest -b -p --android-api-level $TERMUX_PKG_API_LEVEL \
|
|
|
|
--build-swift-static-stdlib --swift-install-components=$SWIFT_COMPONENTS \
|
|
|
|
--llvm-install-components=IndexStore --install-llvm --install-swift \
|
2020-09-07 18:23:03 +02:00
|
|
|
--install-libdispatch --install-foundation --install-xctest --install-llbuild \
|
|
|
|
--install-swiftpm
|
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
|
2020-09-07 18:23:03 +02:00
|
|
|
mv $TERMUX_PREFIX/glibc-native.modulemap \
|
2020-09-23 22:16:17 +02:00
|
|
|
$TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH/glibc.modulemap
|
2020-02-17 18:24:10 +01:00
|
|
|
fi
|
|
|
|
}
|