termux-packages/packages/swift/build.sh
Yaksh Bariya 60ee021c04
Revert "swift: Bump revision"
This reverts commit 48b67cba81.
2021-10-25 17:25:45 +05:30

172 lines
7.6 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.5
TERMUX_PKG_REVISION=3
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=0f76c429e65f24d48a2a18b18e7b380a5c97be0d4370271ac3623e436332fd35
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_DEPENDS="lld, 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, 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
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
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
library_checksums[swift-cmark]=689865cafeb0bd7eb1297cdd8ba06c43d072af921d36bdbdf6dbe3817b3bb27f
library_checksums[llvm-project]=87955764fb6cd83cb24e0421f249ce3fc817400edd3c0015eb840fe7fd7cf5e3
library_checksums[swift-corelibs-libdispatch]=5efdfa1d2897c598acea42fc00776477bb3713645686774f5ff0818b26649e62
library_checksums[swift-corelibs-foundation]=4d58bd3ed05f8b2bf836e4868034f01272dddbd3c0385ddc6f2afc93da033464
library_checksums[swift-corelibs-xctest]=4dd3a3096c51b52817b0876ce18ea921cb0f71adf1992019e984d0d45e49b840
library_checksums[swift-llbuild]=09e774c4a97bbb7473ab2b69ef2a547036660ce7d5d2c67802974de3e23381f8
library_checksums[swift-argument-parser]=9dfcb236f599e309e49af145610957648f8a59d9527b4202bc5bdda0068556d7
library_checksums[Yams]=8bbb28ef994f60afe54668093d652e4d40831c79885fa92b1c2cd0e17e26735a
library_checksums[swift-crypto]=86d6c22c9f89394fd579e967b0d5d0b6ce33cdbf52ba70f82fa313baf70c759f
library_checksums[swift-driver]=e6c8ec5fc41f05ffd4c04b409278d0b4ec098402304b20d2997f06ea2ed2e4ed
library_checksums[swift-tools-support-core]=4ae77edeb30a311d6d4bd5a4ed5ce7286d8fb3305d962a702a985297c82053d0
library_checksums[swift-package-manager]=89b240810b1c2adb86ba83a70ec384b75608a737f9af09f469c8ca968a85a30e
library_checksums[indexstore-db]=191711ad5d7638091b8c813335a7831c7e549a82b3fd480e368ed8ad7801d62d
library_checksums[sourcekit-lsp]=21bca4b8a84a4b687dc9ab1090fd3433915d7555445687ad82f1eaf3ec23c738
for library in "${!library_checksums[@]}"; do \
if [ "$library" = "swift-argument-parser" ]; then
GH_ORG="apple"
SRC_VERSION="0.4.3"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-crypto" ]; then
GH_ORG="apple"
SRC_VERSION="1.1.5"
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
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 \
aaf7eaefdc3f90f77b21b8829546fc2648e02928af476437d6a58556cb858ec6
fi
}
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_HOSTBUILD_DIR $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 --build-toolchain-only \
--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/clang-lib-Driver-ToolChains-Linux.cpp.diff
cd ../swift-corelibs-libdispatch
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libdispatch/src-shims-atomic.h.patch
cd ..
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
$TERMUX_PKG_BUILDER_DIR/swiftpm-driver-lsp-termux-flags | \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | patch -p1
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
--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=$(dirname $TERMUX_PREFIX)
--native-swift-tools-path=$SWIFT_BINDIR
--native-clang-tools-path=$SWIFT_BINDIR"
fi
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
$SWIFT_BUILD_FLAGS --xctest -b -p --swift-driver --sourcekit-lsp \
--android-api-level $TERMUX_PKG_API_LEVEL \
--build-swift-static-stdlib --swift-install-components=$SWIFT_COMPONENTS \
--llvm-install-components=IndexStore --install-llvm --install-swift \
--install-libdispatch --install-foundation --install-xctest --install-llbuild \
--install-swiftpm --install-swift-driver --install-sourcekit-lsp
}
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
rm $TERMUX_PREFIX/swiftpm-android-$SWIFT_ARCH.json
mv $TERMUX_PREFIX/glibc-native.modulemap \
$TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH/glibc.modulemap
fi
}