termux-packages/packages/swift/build.sh

166 lines
7.4 KiB
Bash
Raw Normal View History

TERMUX_PKG_HOMEPAGE=https://swift.org/
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-09-10 11:50:16 +02:00
TERMUX_PKG_VERSION=5.4.3
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
2021-09-10 11:50:16 +02:00
TERMUX_PKG_SHA256=b5eed91bff7667e469b13803a57d60f87c7ec136f4ebb01ae433b3ebc2b6c28b
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"
TERMUX_PKG_BLACKLISTED_ARCHES="i686"
TERMUX_PKG_NO_STATICSPLIT=true
# Build of swift uses cmake, but the standard
# termux_step_configure_cmake function is not used. Instead we set
# TERMUX_PKG_FORCE_CMAKE to make the build system aware that cmake is
# needed.
TERMUX_PKG_FORCE_CMAKE=true
TERMUX_CMAKE_BUILD=Ninja
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"
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-09-07 18:23:03 +02:00
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"
fi
SWIFT_ARCH=$TERMUX_ARCH
test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7'
termux_step_post_get_source() {
# 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
2021-09-10 11:50:16 +02:00
library_checksums[swift-cmark]=5cac6b095878105fc871fb268f22d6f3b4a3d3d5ed44c018c817c77d3d1ea724
library_checksums[llvm-project]=efa12cb20f894ef34aaab9eb3cdc7fa6b94633ebb65db0fcf2a1f26f3bccab0d
library_checksums[swift-corelibs-libdispatch]=4e78210507236a523038f489d660ca66e168bfd6d005d4df0a79f466a19206aa
library_checksums[swift-corelibs-foundation]=75b4a9098867cb85c54430cd9645f42ef4cb6946de8cd84ebdde6e70a451d8bb
library_checksums[swift-corelibs-xctest]=94154379381274e483caeb32f7b33b88906be7f78ac0413929dbeb4464bef02c
library_checksums[swift-llbuild]=69ab1466d79b0f95a04adf7c9c299aeedffde1d517b64a4c64e6c76b1f530556
library_checksums[swift-argument-parser]=6743338612be50a5a32127df0a3dd1c34e695f5071b1213f128e6e2b27c4364a
library_checksums[Yams]=8bbb28ef994f60afe54668093d652e4d40831c79885fa92b1c2cd0e17e26735a
2021-09-10 11:50:16 +02:00
library_checksums[swift-driver]=16a1161ca78c184f40937d07a997b2045abdd7cc8cf62102e3cda6249e329fd6
library_checksums[swift-tools-support-core]=7f8271fd9f9af2e1f889d918d7cd53bf7fad34ca04e0ab2a9a7a6cc1d3ad2cbe
library_checksums[swift-package-manager]=298ec9390941d50b2a71833ce1224bd8c4c1b5c68cc19fd83da4331f07f0e5c6
for library in "${!library_checksums[@]}"; do \
if [ "$library" = "swift-argument-parser" ]; then
GH_ORG="apple"
SRC_VERSION="0.4.1"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "Yams" ]; then
GH_ORG="jpsim"
SRC_VERSION="4.0.2"
TAR_NAME=$SRC_VERSION
else
GH_ORG="apple"
SRC_VERSION=$SWIFT_RELEASE
TAR_NAME=swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE
2020-04-30 13:56:12 +02:00
fi
termux_download \
https://github.com/$GH_ORG/$library/archive/$TAR_NAME.tar.gz \
$TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz \
${library_checksums[$library]}
tar xf $TERMUX_PKG_CACHEDIR/$library-$SRC_VERSION.tar.gz
mv $library-$TAR_NAME $library
done
mv swift-cmark cmark
mv swift-llbuild llbuild
mv Yams yams
mv swift-package-manager swiftpm
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
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 \
2021-09-10 11:50:16 +02:00
e5bf05aeb639999ae2134a86837dcaa7b80e2d9308849c79892e0144f906d56b
fi
}
termux_step_host_build() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
termux_setup_cmake
termux_setup_ninja
termux_setup_standalone_toolchain
2020-09-07 18:23:03 +02:00
# Natively compile llvm-tblgen and some other files needed later.
SWIFT_BUILD_ROOT=$TERMUX_PKG_HOSTBUILD_DIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
2021-06-29 10:14:04 +02:00
-R --no-assertions -j $TERMUX_MAKE_PROCESSES $SWIFT_PATH_FLAGS \
--skip-build-cmark --skip-build-llvm --skip-build-swift --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
fi
}
termux_step_pre_configure() {
cd llbuild
# A single patch needed from the existing llbuild package
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../llbuild/lib-llvm-Support-CmakeLists.txt.patch
cd ../llvm-project
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
cd ..
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-Utilities-bootstrap | \
sed "s%\@TERMUX_PKG_BUILDDIR\@%${TERMUX_PKG_BUILDDIR}%g" | patch -p1
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%\@SWIFT_ARCH\@%${SWIFT_ARCH}%g" > $TERMUX_PKG_BUILDDIR/swiftpm-android-flags.json
fi
}
termux_step_make() {
# 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=)
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
ln -sf $TERMUX_PKG_HOSTBUILD_DIR/llvm-linux-x86_64 $TERMUX_PKG_BUILDDIR/llvm-linux-x86_64
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
--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
--cross-compile-hosts=android-$SWIFT_ARCH --cross-compile-deps-path=$TERMUX_PREFIX
2021-06-29 10:14:04 +02:00
--native-swift-tools-path=$SWIFT_BINDIR
--native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin"
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
}
termux_step_make_install() {
rm $TERMUX_PREFIX/lib/swift/pm/llbuild/libllbuild.so
rm $TERMUX_PREFIX/lib/swift/android/lib{dispatch,BlocksRuntime}.so
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
2020-09-07 18:23:03 +02:00
mv $TERMUX_PREFIX/glibc-native.modulemap \
$TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH/glibc.modulemap
fi
}