feat(setup ghc cross): handle package registration

feat(termux_setup_ghc_cross_compiler): handle haskell packages registration

chore(termux_setup_ghc_cross_compiler): update checksum

Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
This commit is contained in:
Aditya Alok 2022-03-12 11:10:20 +05:30 committed by Henrik Grimler
parent 3c9ed52daf
commit a9b411f577
No known key found for this signature in database
GPG Key ID: B0076E490B71616B
1 changed files with 58 additions and 25 deletions

View File

@ -1,3 +1,30 @@
__termux_haskell_register_packages() {
# Register dependency haskell packages with termux-ghc-pkg.
IFS=',' read -r -a DEP <<<"${TERMUX_PKG_DEPENDS},${TERMUX_PKG_BUILD_DEPENDS}"
for dep in "${DEP[@]}"; do
if [[ "${dep}" == haskell-* ]]; then
echo "Dependency '${pkg}' is a haskell package, registering it with ghc-pkg..."
sed "s|${TERMUX_PREFIX}/bin/ghc-pkg|$(command -v termux-ghc-pkg)|g" \
"${TERMUX_PREFIX}/share/haskell/register/${pkg}.sh" | sh
termux-ghc-pkg recache
# NOTE: Above command rewrites a cache file at
# "${TERMUX_PREFIX}/lib/ghc-${TERMUX_GHC_VERSION}/package.conf.d". Since it is done after
# timestamp creation, we need to remove it in massage step.
fi
done
}
__termux_haskell_eval_custom_build() {
local bin="$1"
if ! $(cat "${TERMUX_PKG_SRCDIR}"/*.cabal | grep -wq "^[bB]uild-type:") ||
$(cat "${TERMUX_PKG_SRCDIR}"/*.cabal | grep -wq '^[bB]uild-type:\s*[Ss]imple$'); then
return
fi
# Now, it must be a custom build.
# Compile custom Setup script with GHC and make it available in PATH.
ghc --make "${TERMUX_PKG_SRCDIR}"/Setup -o "${bin}/termux-ghc-setup"
}
# Utility function to setup a GHC cross-compiler toolchain targeting Android.
termux_setup_ghc_cross_compiler() {
local TERMUX_GHC_VERSION="8.10.7"
@ -13,33 +40,25 @@ termux_setup_ghc_cross_compiler() {
local TERMUX_GHC_TAR="${TERMUX_COMMON_CACHEDIR}/${GHC_PREFIX}.tar.xz"
export PATH="${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}:${TERMUX_GHC_RUNTIME_FOLDER}/bin:${PATH}"
export PATH="${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}:${PATH}"
test -d "${TERMUX_PREFIX}/lib/ghc-${TERMUX_GHC_VERSION}" ||
termux_error_exit "Package 'ghc-libs' is not installed. It is required by GHC cross-compiler." \
"You should specify it in 'TERMUX_PKG_BUILD_DEPENDS'."
# Register dependency haskell packages with termux-ghc-pkg.
IFS=',' read -r -a DEP <<<"${TERMUX_PKG_DEPENDS},${TERMUX_PKG_BUILD_DEPENDS}"
for dep in "${DEP[@]}"; do
if [[ "${dep}" == haskell-* ]]; then
echo "Dependency '${pkg}' is a haskell package, registering it with ghc-pkg..."
sed "s|${TERMUX_PREFIX}/bin/ghc-pkg|$(command -v termux-ghc-pkg)|g" \
"${TERMUX_PREFIX}/share/haskell/register/${pkg}.sh" | sh
termux-ghc-pkg recache
# NOTE: Above command rewrites a cache file at "${TERMUX_PREFIX}/lib/ghc-${TERMUX_GHC_VERSION}/package.conf.d".
# Since it is done after timestamp creation, we need to remove it in massage step.
fi
done
__termux_haskell_register_packages
[ -d "${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}" ] && return
if [ -d "${TERMUX_GHC_RUNTIME_FOLDER}" ]; then
__termux_haskell_eval_custom_build "${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}"
return
fi
local CHECKSUMS="$(
cat <<-EOF
aarch64:1f0fb1579f0afa53a67bb2f20a8c270e971a955a1e508377628d6fe22e2254e1
arm:e79b1819537b49592cae9009d18baf610217bbc6c553c2f02d1bc8fe3de63704
i686:5ffd15446e1540fb2a75c10b97d5b426037540c024720337a7f9e297e599a749
x86_64:f78049742d0169054f289168833d35b06b464330b9236b13f3b8f38ddc87505b
aarch64:abcb8c4e9d9c1ef3ce1e95049fe220c1947059c965a10baaa97a864666c17f4c
arm:2bc44818f312bf7110deefbd23da0177f9e299519c22fe28b21ac24a2ea689a4
i686:8e05cd5ffaeb1dc6dec824bf9ac42572f418ab95f86606e1dff91bcdca9e78b6
x86_64:1976ec89e16294c8866ae7e2d564ce5bae8ebc62ac3dab1c2b8845f775b85feb
EOF
)"
@ -51,9 +70,6 @@ termux_setup_ghc_cross_compiler() {
tar -xf "${TERMUX_GHC_TAR}" -C "${TERMUX_GHC_RUNTIME_FOLDER}"
local _HOST="${TERMUX_HOST_PLATFORM}"
[ "${TERMUX_ARCH}" = "arm" ] && _HOST="armv7a-linux-androideabi"
# Replace ghc settings with settings of the cross compiler.
sed "s|\$topdir/bin/unlit|${TERMUX_GHC_RUNTIME_FOLDER}/lib/ghc-${TERMUX_GHC_VERSION}/bin/unlit|g" \
"${TERMUX_GHC_RUNTIME_FOLDER}/lib/ghc-${TERMUX_GHC_VERSION}/settings" > \
@ -62,14 +78,19 @@ termux_setup_ghc_cross_compiler() {
# so we need to remove it in massage step.
for tool in ghc ghc-pkg hsc2hs hp2ps ghci; do
sed -i "s|\$executablename|${TERMUX_GHC_RUNTIME_FOLDER}/lib/ghc-${TERMUX_GHC_VERSION}/bin/${tool}|g" \
_tool="${tool}"
[ "${tool}" = "ghci" ] && _tool="ghc"
sed -i "s|\$executablename|${TERMUX_GHC_RUNTIME_FOLDER}/lib/ghc-${TERMUX_GHC_VERSION}/bin/${_tool}|g" \
"${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}/termux-${tool}"
done
# GHC ships with old version, we use our own.
termux-ghc-pkg unregister Cabal
# NOTE: Above command rewrites a cache file at "${TERMUX_PREFIX}/lib/ghc-${TERMUX_GHC_VERSION}/package.conf.d".
# Since it is done after timestamp creation, we need to remove it in massage step.
# NOTE: Above command rewrites a cache file at
# "${TERMUX_PREFIX}/lib/ghc-${TERMUX_GHC_VERSION}/package.conf.d". Since it is done after
# timestamp creation, we need to remove it in massage step.
__termux_haskell_eval_custom_build "${TERMUX_GHC_RUNTIME_FOLDER}/bin/${TERMUX_ARCH}"
rm "${TERMUX_GHC_TAR}"
else
@ -81,12 +102,24 @@ termux_setup_ghc_cross_compiler() {
else
local ON_DEVICE_GHC_BIN="${TERMUX_COMMON_CACHEDIR}/${GHC_PREFIX}-runtime"
export PATH="${ON_DEVICE_GHC_BIN}:${PATH}"
[ -d "${ON_DEVICE_GHC_BIN}" ] && return
__termux_haskell_register_packages
if [ -d "${ON_DEVICE_GHC_BIN}" ]; then
__termux_haskell_eval_custom_build "${ON_DEVICE_GHC_BIN}"
return
fi
mkdir -p "${ON_DEVICE_GHC_BIN}"
for tool in ghc ghc-pkg hsc2hs hp2ps ghci; do
ln -sf "${TERMUX_PREFIX}/bin/${tool}" "${ON_DEVICE_GHC_BIN}/termux-${tool}"
done
__termux_haskell_eval_custom_build "${ON_DEVICE_GHC_BIN}"
if ! command -v termux-ghc-setup &>/dev/null; then
# Provide `termux-ghc-setup` on device.
ghc --make "${TERMUX_SCRIPTDIR}"/scripts/build/haskell-build/default-setup.hs \
-o "${ON_DEVICE_GHC_BIN}"/termux-ghc-setup
fi
fi
fi
}