termux-packages/packages/swift/build.sh

152 lines
7.0 KiB
Bash

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_MAINTAINER="@buttaface"
TERMUX_PKG_VERSION=5.3.1
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=73cec0b4967562cdcd14d724cfcc25ad6d1aaf3e0d42f25bfaf23a38f22c63be
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="i686"
TERMUX_PKG_NO_STATICSPLIT=true
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" = "false" ]; then
SWIFT_BIN="swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE-ubuntu20.04"
SWIFT_BINDIR="$TERMUX_PKG_HOSTBUILD_DIR/$SWIFT_BIN/usr/bin"
fi
termux_step_post_get_source() {
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
library_checksums[swift-cmark]=bed59602c5d19acb8c689b296633586250e38a6cb09f28cdafa660a116a9369d
library_checksums[llvm-project]=60bf2616689d18a494bb55b655d44878a307fc536abe45ead4bc89740167abb2
library_checksums[swift-corelibs-libdispatch]=cb493475a8d295a47f59e7e6673fd9ce0ca137e278bb17cf2d0da8a73ecaf134
library_checksums[swift-corelibs-foundation]=66dc9d33a71462b9127e9bd111abed859d7f303a467665f6055670fa0b00bd9d
library_checksums[swift-corelibs-xctest]=0a98cb3dcfa197f0b4d997b5bc9b00cb928c00d97b8a7207c9cdec901c2acad5
library_checksums[swift-llbuild]=bce0c17de2180757e090541fcb879e631b4a345bb96380ff70ffb77207674abb
library_checksums[swift-package-manager]=633680d00c000c986a00b12afbe5c3317ba8c7dc0f80c247390adaea58595bdd
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
mv $library-swift-${TERMUX_PKG_VERSION}-$SWIFT_RELEASE $library
done
mv swift-cmark cmark
mv swift-llbuild llbuild
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 \
4040b9b75eaeee8d111c88d99deedb0b686f94cab4c2857e5fcae3f5b6c3c240
fi
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=)
}
termux_step_host_build() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
termux_setup_cmake
termux_setup_ninja
termux_setup_standalone_toolchain
# 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_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++
tar xf $TERMUX_PKG_CACHEDIR/$SWIFT_BIN.tar.gz -C $TERMUX_PKG_HOSTBUILD_DIR
fi
}
termux_step_pre_configure() {
export SWIFT_ARCH=$TERMUX_ARCH
test $SWIFT_ARCH == 'arm' && SWIFT_ARCH='armv7'
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
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
cd ../..
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%\@SWIFT_ARCH\@%${SWIFT_ARCH}%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
fi
}
termux_step_make() {
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
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-$SWIFT_ARCH/lib/swift"
export HOST_SWIFTC="$SWIFT_BINDIR/swiftc"
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android
--android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_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
--cross-compile-hosts=android-$SWIFT_ARCH --cross-compile-deps-path=$TERMUX_PREFIX
--native-swift-tools-path=$SWIFT_BINDIR
--native-clang-tools-path=$TERMUX_STANDALONE_TOOLCHAIN/bin"
fi
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
$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() {
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
mv $TERMUX_PREFIX/glibc-native.modulemap \
$TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH/glibc.modulemap
fi
}