From 74268e0f168da7a5da570449216b11e59c5ae322 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Fri, 8 Oct 2021 17:44:38 +0300 Subject: [PATCH] disabled packages: add ghc - needs update and fix for current ndk version --- ...lways-use-pic-on-android-for-dynexec.patch | 17 ++ disabled-packages/ghc/always_link_m.patch | 30 ++++ disabled-packages/ghc/build.sh | 154 ++++++++++++++++++ disabled-packages/ghc/undefined_symbols.patch | 24 +++ .../ghc/use-stage1-binaries-for-install.patch | 28 ++++ 5 files changed, 253 insertions(+) create mode 100644 disabled-packages/ghc/always-use-pic-on-android-for-dynexec.patch create mode 100644 disabled-packages/ghc/always_link_m.patch create mode 100644 disabled-packages/ghc/build.sh create mode 100644 disabled-packages/ghc/undefined_symbols.patch create mode 100644 disabled-packages/ghc/use-stage1-binaries-for-install.patch diff --git a/disabled-packages/ghc/always-use-pic-on-android-for-dynexec.patch b/disabled-packages/ghc/always-use-pic-on-android-for-dynexec.patch new file mode 100644 index 000000000..d4957dc64 --- /dev/null +++ b/disabled-packages/ghc/always-use-pic-on-android-for-dynexec.patch @@ -0,0 +1,17 @@ +--- ghc-8.10.1/compiler/main/DynFlags.hs.orig 2020-06-13 08:56:50.595808526 +0100 ++++ ghc-8.10.1/compiler/main/DynFlags.hs 2020-06-13 08:57:24.770000253 +0100 +@@ -4624,6 +4624,14 @@ + default_PIC platform = + case (platformOS platform, platformArch platform) of + (OSDarwin, ArchX86_64) -> [Opt_PIC] ++ (OSLinux, ArchARM{}) -> [Opt_PIC] ++ (OSLinux, ArchARM64) -> [Opt_PIC] ++ (OSLinux, ArchX86) -> [Opt_PIC] ++ (OSLinux, ArchX86_64) -> [Opt_PIC] ++ (OSUnknown, ArchARM{}) -> [Opt_PIC] ++ (OSUnknown, ArchARM64) -> [Opt_PIC] ++ (OSUnknown, ArchX86) -> [Opt_PIC] ++ (OSUnknown, ArchX86_64) -> [Opt_PIC] + (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in + -- OpenBSD since 5.3 release + -- (1 May 2013) we need to diff --git a/disabled-packages/ghc/always_link_m.patch b/disabled-packages/ghc/always_link_m.patch new file mode 100644 index 000000000..d10158ddb --- /dev/null +++ b/disabled-packages/ghc/always_link_m.patch @@ -0,0 +1,30 @@ +diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs +index b3312b0..b0e3d90 100644 +--- a/compiler/main/SysTools.hs ++++ b/compiler/main/SysTools.hs +@@ -414,11 +414,7 @@ linkDynLib dflags0 o_files dep_packages + -- math-y things are used (which we assume to include all programs). See #14022. + libmLinkOpts :: [Option] + libmLinkOpts = +-#if defined(HAVE_LIBM) + [Option "-lm"] +-#else +- [] +-#endif + + getPkgFrameworkOpts :: DynFlags -> Platform -> [InstalledUnitId] -> IO [String] + getPkgFrameworkOpts dflags platform dep_packages +diff --git a/rts/package.conf.in b/rts/package.conf.in +index e4cb159..7a234cd 100644 +--- a/rts/package.conf.in ++++ b/rts/package.conf.in +@@ -26,9 +26,7 @@ library-dirs: TOP"/rts/dist/build" FFI_LIB_DIR LIBDW_LIB_DIR + hs-libraries: "HSrts" FFI_LIB + + extra-libraries: +-#if defined(HAVE_LIBM) + "m" /* for ldexp() */ +-#endif + #if defined(HAVE_LIBRT) + , "rt" + #endif diff --git a/disabled-packages/ghc/build.sh b/disabled-packages/ghc/build.sh new file mode 100644 index 000000000..4710d1a41 --- /dev/null +++ b/disabled-packages/ghc/build.sh @@ -0,0 +1,154 @@ +# Build failure with recent NDK. + +TERMUX_PKG_HOMEPAGE=https://www.haskell.org/ghc/ +TERMUX_PKG_DESCRIPTION="The Glasgow Haskell Compilation system" +TERMUX_PKG_LICENSE="BSD 2-Clause, BSD 3-Clause, LGPL-2.1" +TERMUX_PKG_VERSION=8.10.1 +TERMUX_PKG_REVISION=5 +TERMUX_PKG_SRCURL=http://downloads.haskell.org/~ghc/${TERMUX_PKG_VERSION}/ghc-${TERMUX_PKG_VERSION}-src.tar.xz +TERMUX_PKG_SHA256=4e3b07f83a266b3198310f19f71e371ebce97c769b14f0d688f4cbf2a2a1edf5 +TERMUX_PKG_DEPENDS="binutils, clang, iconv, libffi, llvm, ncurses" +TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_NO_STATICSPLIT=true +TERMUX_PKG_EXTRA_CONFIGURE_ARGS=" --disable-ld-override --build=x86_64-unknown-linux --host=x86_64-unknown-linux" +TERMUX_PKG_BLACKLISTED_ARCHES="arm" + +DYNAMIC_GHC_PROGRAMS=NO + +termux_step_pre_configure() { + termux_setup_ghc + + TERMUX_PKG_EXTRA_CONFIGURE_ARGS+=" --target=${TERMUX_HOST_PLATFORM}" + + # After stage 0, cabal passes a host string to the libraries' configure scripts that isn't valid. + # We set one ourselves anyway, so this simply isn't needed. + sed -i 's/maybeHostFlag = i/maybeHostFlag = [] -- i/' libraries/Cabal/Cabal/Distribution/Simple.hs + + # Android will only run PIE executables, so --no-pie, like GHC suggests, is out. GHC relies on relocations. + # Combine PIE and -Wl,-r together, and the linker will tell you those flags are mutually exclusive. + # This poses a problem as we need both. If you let the compiler handle it, then apparently all's well. + sed -i 's/"-Wl,-r"/"-r"/' compiler/main/DriverPipeline.hs + + cp mk/build.mk.sample mk/build.mk + cat >> mk/build.mk <<-EOF + SRC_HC_OPTS += -optc-Wno-unused-label -optc-Wno-unused-but-set-variable + SRC_HC_OPTS += -optc-Wno-unused-variable -optc-Wno-unused-function + SRC_HC_OPTS += -optc-Wno-unused-command-line-argument -optc-Wno-unknown-warning-option + GhcStage2HcOpts += -optl-Wl,--enable-new-dtags + INTEGER_LIBRARY = integer-simple + SplitSections = YES + BuildFlavour = quick-cross + HADDOCK_DOCS = NO + BUILD_SPHINX_HTML = NO + BUILD_SPHINX_PS = NO + BUILD_SPHINX_PDF = NO + DYNAMIC_GHC_PROGRAMS = $DYNAMIC_GHC_PROGRAMS + GhcLibWays = v + BUILD_MAN = NO + #STRIP_CMD = $STRIP + EOF + # If choosing to build a GHC dynamically linked to its libs, then + # $TERMUX_PREFIX/lib automatically gets added to the rpath that's generated + if [ "$DYNAMIC_GHC_PROGRAMS" != "YES" ]; then + echo "GhcStage2HcOpts += -optl-Wl,-rpath=$TERMUX_PREFIX/lib" >> mk/build.mk + fi + +# So... this is fun. If these options are initially passed to the configure script, +# then building stage 0 breaks, because it's meant to run on the host with the +# host's libs. But of course, we need to link to Termux's libffi etc. and use the +# cross-compiler when building something to run on Android in the later stages +patch -Np1 </dev/null)" + if [ -n "$curr_rpath" ]; then + local paths_to_prepend=() + local new_rpath=() + + IFS=':' read -ra paths <<< "$curr_rpath" + for i in "${!paths[@]}"; do + # Prioritise non-Haskell library paths + if [[ ${paths[$i]} != *ghc-$TERMUX_PKG_VERSION* ]]; then + paths_to_prepend+=("${paths[$i]}") + continue + fi + local fixed_path="${paths[$i]/\/dist-install\/build}" + if [ "$fixed_path" != "${paths[$i]}" ]; then + # Naïvely correct the path to a Haskell library + fixed_path="${fixed_path##*/}" + fixed_path=$(echo "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/$fixed_path-"[[:digit:]]*) + new_rpath+=("$fixed_path") + else + # This may be the path to RTS, which does not have a version number in the folder name + # and nor is it apparently expected to be found in dist-install + fixed_path="${paths[$i]/\/dist\/build}" + if [ "$fixed_path" != "${paths[$i]}" ]; then + new_rpath+=("$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/${fixed_path##*/}") + else + new_rpath+=("$fixed_path") + fi + fi + done + # Make sure the standard Termux library path is the first entry + [[ ! " ${paths_to_prepend[@]} " =~ " $TERMUX_PREFIX/lib " ]] && paths_to_prepend=("$TERMUX_PREFIX/lib" "${paths_to_prepend[@]}") + # This isn't in the original rpath at all, but is needed + paths_to_prepend+=("$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/ghc-$TERMUX_PKG_VERSION") + local OIFS="$IFS" + local IFS=':' + printf -v new_rpath "%s:%s" "${paths_to_prepend[*]}" "${new_rpath[*]}" + IFS="$OIFS" + patchelf --set-rpath "$new_rpath" "$bin" + fi + done < <(find "$TERMUX_PREFIX/lib/ghc-$TERMUX_PKG_VERSION/bin/" -type f -print0) + fi +} + +termux_step_install_license() { + install -Dm600 -t "$TERMUX_PREFIX/share/doc/ghc" "$TERMUX_PKG_SRCDIR/LICENSE" +} diff --git a/disabled-packages/ghc/undefined_symbols.patch b/disabled-packages/ghc/undefined_symbols.patch new file mode 100644 index 000000000..36a12bc75 --- /dev/null +++ b/disabled-packages/ghc/undefined_symbols.patch @@ -0,0 +1,24 @@ +--- ghc-8.10.1/rts/Trace.c 2020-03-24 04:53:17.000000000 +0000 ++++ ghc-8.10.1.new/rts/Trace.c 2020-06-12 13:33:14.775373605 +0100 +@@ -12,6 +12,10 @@ + // internal headers + #include "Trace.h" + ++int TRACE_sched; ++int TRACE_gc; ++int TRACE_spark_sampled; ++ + #if defined(TRACING) + + #include "GetTime.h" +@@ -28,10 +32,7 @@ + #endif + + // events +-int TRACE_sched; +-int TRACE_gc; + int TRACE_nonmoving_gc; +-int TRACE_spark_sampled; + int TRACE_spark_full; + int TRACE_user; + int TRACE_cap; diff --git a/disabled-packages/ghc/use-stage1-binaries-for-install.patch b/disabled-packages/ghc/use-stage1-binaries-for-install.patch new file mode 100644 index 000000000..e4532c3ea --- /dev/null +++ b/disabled-packages/ghc/use-stage1-binaries-for-install.patch @@ -0,0 +1,28 @@ +Description: Use the stage1 binaries for install + In order to be able to perform a cross-build, we need to use + the stage1 binaries during installation. Both ghc and ghc-pkg + are run during the install target and therefore must be able + to run on the build machine. + . +Author: John Paul Adrian Glaubitz +Last-Update: 2017-01-29 + +Index: ghc-8.8.1+dfsg1/ghc.mk +=================================================================== +--- ghc-8.8.1+dfsg1.orig/ghc.mk ++++ ghc-8.8.1+dfsg1/ghc.mk +@@ -963,8 +963,12 @@ + # Install packages in the right order, so that ghc-pkg doesn't complain. + # Also, install ghc-pkg first. + ifeq "$(Windows_Host)" "NO" +-INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc +-INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg ++# Use the inplace/stage1 versions for installation, ++# since the installed versions are built for the target ++#INSTALLED_GHC_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc ++#INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(ghclibexecdir)/bin/ghc-pkg ++INSTALLED_GHC_REAL=$(CURDIR)/inplace/bin/ghc-stage1 ++INSTALLED_GHC_PKG_REAL=$(CURDIR)/utils/ghc-pkg/dist/build/tmp/ghc-pkg + else + INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe + INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe