Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-lang/ghc-9.0.2-r2 does not compile on Musl (no lib64) #1368

Open
Thymelizabeth opened this issue Dec 4, 2022 · 10 comments
Open

dev-lang/ghc-9.0.2-r2 does not compile on Musl (no lib64) #1368

Thymelizabeth opened this issue Dec 4, 2022 · 10 comments

Comments

@Thymelizabeth
Copy link

build.log
emerge-info.txt

Fails in the prepare phase trying to relocate folders.

@hololeap
Copy link
Member

hololeap commented Dec 9, 2022

Here's are some relevant blocks of code:

if use binary; then
if use prefix; then
relocate_ghc "${EPREFIX}"
fi
# Move unpacked files to the expected place
mv "${WORKDIR}/usr" "${S}"
eapply_user
else

relocate_ghc() {
local to=$1 ghc_v=${BIN_PV}
# libdir for prebuilt binary and for current system may mismatch
# It does for prefix installation for example: bug #476998
local bin_ghc_prefix=${WORKDIR}/usr
local bin_libpath=$(echo "${bin_ghc_prefix}"/lib*)
local bin_libdir=${bin_libpath#${bin_ghc_prefix}/}

if [[ ${bin_libdir} != $(get_libdir) ]]; then
einfo "Relocating '${bin_libdir}' to '$(get_libdir)' (bug #476998)"
# moving the dir itself is not strictly needed
# but then USE=binary would result in installing
# in '${bin_libdir}'
mv "${bin_ghc_prefix}/${bin_libdir}" "${bin_ghc_prefix}/$(get_libdir)" || die
relocate_path "/usr/${bin_libdir}" "/usr/$(get_libdir)" \
"${WORKDIR}/usr/bin/ghc-${ghc_v}" \
"${WORKDIR}/usr/bin/ghci-${ghc_v}" \
"${WORKDIR}/usr/bin/ghc-pkg-${ghc_v}" \
"${WORKDIR}/usr/bin/hsc2hs" \
"${WORKDIR}/usr/bin/runghc-${ghc_v}" \
"$gp_back" \
"${WORKDIR}/usr/$(get_libdir)/${PN}-${ghc_v}/package.conf.d/"*
fi


I take it you are using the binary USE flag?

@hololeap
Copy link
Member

hololeap commented Dec 9, 2022

I'm not sure if amd64 and amd64-musl need to be treated as separate build hosts, e.g. musl needs its own binary.

@thesamesam might have some insight here.

@hololeap
Copy link
Member

hololeap commented Dec 9, 2022

dev-lang/ghc-9.0.2-r2 does not compile on Musl (no lib64)

@Thymelizabeth are you aware that using the binary USE flag skips compilation, and instead just installs directly from the binary we provide?

<flag name="binary">Install the binary version directly, rather than using it to build the source version.</flag>

@Thymelizabeth
Copy link
Author

The way I see it, there are several problems with trying to install GHC on a system using musl:

  1. The only binaries downloaded are compiled for glibc. These cannot be used to build GHC and cannot be installed directly to the system. Despite this, Portage sees no problem trying to install GHC on a musl based system. There is a build for Alpine Linux available from the main Haskell website which could be added. I recently changed the dev-dotnet/dotnet-sdk-bin package to change the binary download depending on the libc the system uses. This ebuild could use something similar.

  2. When not using the binary USE flag, Portage tries to rename a non-existent folder, i.e. the /usr/lib folder to /usr/lib64. This folder is not provided in the binary. It is, however, provided in the source. /usr/lib64 already exists in the binary. musl does not recommend using a lib64 or lib32 directory

  3. When trying to install with the binary USE flag, Portage tries to backup the /usr/lib/ghc-9.0.2/package.conf.d directory. This folder is also not provided in the binary package, and is not produced as the ebuild is processed. Bear in mind, this binary package is not compiled for musl, but Portage sees nothing wrong with trying to install it.

@hololeap
Copy link
Member

hololeap commented Dec 9, 2022

Thanks for your thoughts on this. I did not see that relocate_ghc is also called here, which is called when the binary USE flag is disabled, which disproves my assumption that you must have it enabled to hit this bug:

# it is autoconf, but we really don't want to give it too
# many arguments, in fact we do the make in-place anyway
./configure --prefix="${WORKDIR}"/usr || die
make install || die
popd > /dev/null
;;
*)
relocate_ghc "${WORKDIR}"
;;

I don't have a lot of familiarity with the ghc ebuild or musl, unfortunately, but I can get a musl sandbox set up at some point to help with development.

@hololeap
Copy link
Member

hololeap commented Dec 9, 2022

@Thymelizabeth Do you think that something like this would be a good first step, just to ensure people on musl don't try to download our glibc binary?

diff --git a/dev-lang/ghc/ghc-9.0.2-r2.ebuild b/dev-lang/ghc/ghc-9.0.2-r2.ebuild
index 1bbe52e971..9e6149913c 100644
--- a/dev-lang/ghc/ghc-9.0.2-r2.ebuild
+++ b/dev-lang/ghc/ghc-9.0.2-r2.ebuild
@@ -29,7 +29,8 @@ BIN_PV=${PV}
 #arch_binaries="$arch_binaries alpha? ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-alpha.tbz2 )"
 #arch_binaries="$arch_binaries arm? ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-armv7a-hardfloat-linux-gnueabi.tbz2 )"
 #arch_binaries="$arch_binaries arm64? ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-aarch64-unknown-linux-gnu.tbz2 )"
-arch_binaries="$arch_binaries amd64? ( https://eidetic.codes/ghc-bin-${PV}-x86_64-pc-linux-gnu-r1.tbz2 )"
+arch_binaries="$arch_binaries amd64? ( elibc_glibc? ( https://eidetic.codes/ghc-bin-${PV}-x86_64-pc-linux-gnu-r1.tbz2 ) )"
+#arch_binaries="$arch_binaries amd64? ( elibc_musl? ( https://eidetic.codes/ghc-bin-${PV}-x86_64-pc-linux-musl-r1.tbz2 ) )"
 #arch_binaries="$arch_binaries ia64?  ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-ia64-fixed-fiw.tbz2 )"
 #arch_binaries="$arch_binaries ppc? ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-ppc.tbz2 )"
 #arch_binaries="$arch_binaries ppc64? ( https://slyfox.uni.cx/~slyfox/distfiles/ghc-bin-${PV}-ppc64.tbz2 )"
@@ -46,7 +47,15 @@ yet_binary() {
                #alpha) return 0 ;;
                #arm64) return 0 ;;
                #arm) return 0 ;;
-               amd64) return 0 ;;
+               amd64)
+                       if use elibc_glibc; then
+                               return 0
+                       elif use elibc_musl; then
+                               return 1
+                       else
+                               return 1
+                       fi
+                       ;;
                #ia64) return 0 ;;
                #ppc) return 0 ;;
                ppc64)

Also, have you been able to build successfully with the ghcbootstrap USE flag using an instance of GHC installed through e.g. ghcup (or the alpine linux tarball)?

@Thymelizabeth
Copy link
Author

Thymelizabeth commented Dec 9, 2022

The patch looks good.

I tried installing with ghcbootstrap enabled, (using Another binary installed to /usr/local), but got a segmentation fault when make tried to use a non-existent file.
ghcbootstrap-enabled-build.log

Trying with the Alpine binary (9.0.2) from haskell.org gives the same result.

GHCup also segfaults.
ghcup-make.log
Unrelated issue: gold (binutils) has a bug where dynamically linked executables with musl segfault on startup, so I used lld with ghcup.

hololeap added a commit that referenced this issue Dec 9, 2022
GHC binaries built for glibc do not seem to play nice on musl systems.
This separates the two so musl binaries can later be built/uploaded.

Bug: #1368
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
@thesamesam
Copy link
Member

I'm not sure if amd64 and amd64-musl need to be treated as separate build hosts, e.g. musl needs its own binary.

@thesamesam might have some insight here.

Yeah, musl will always need its own set as it's a different ABI (treat it like a different architecture for the purposes of reusing binaries).

@thesamesam
Copy link
Member

thesamesam commented Dec 9, 2022

GHCup also segfaults. ghcup-make.log Unrelated issue: gold (binutils) has a bug where dynamically linked executables with musl segfault on startup, so I used lld with ghcup.

I would not use gold for anything, it's considered deprecated. The normal linker from GNU binutils (bfd) is fine, but gold is not.

@formula-spectre
Copy link

I suggest taking a look here:
https://github.com/clang-musl-overlay/clang-musl-overlay/tree/master/dev-lang/ghc
I use this ebuild on musl and it works fine

gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Feb 21, 2023
GHC binaries built for glibc do not seem to play nice on musl systems.
This separates the two so musl binaries can later be built/uploaded.

Bug: gentoo-haskell/gentoo-haskell#1368
Signed-off-by: hololeap <hololeap@users.noreply.github.com>
Signed-off-by: Sam James <sam@gentoo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants