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

Build failure: pkgs.pkgsMusl.ghc for static linking #316850

Closed
NorfairKing opened this issue Jun 3, 2024 · 5 comments
Closed

Build failure: pkgs.pkgsMusl.ghc for static linking #316850

NorfairKing opened this issue Jun 3, 2024 · 5 comments

Comments

@NorfairKing
Copy link
Contributor

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run this on nixos-24.05:
nix build --expr 'let pkgs = import ./. {}; in pkgs.pkgsMusl.ghc.override { enableRelocatedStaticLibs = true; enableShared = false; }' --impure

Build log

ghc-musl> # cabal-copy (for _build/stage1/lib/package.conf.d/rts-1.0.2.conf)
ghc-musl> # cabal-configure (for _build/stage1/utils/hp2ps/setup-config)
ghc-musl> | Run GhcPkg Recache Stage1: none => none
ghc-musl> | Copy package 'ghc-prim'
ghc-musl> # cabal-copy (for _build/stage1/lib/package.conf.d/ghc-prim-0.10.0.conf)
ghc-musl> 0;Finished in 30m34sError, rule finished running but did not produce file:
ghc-musl>   _build/stage1/lib/x86_64-linux-ghc-9.6.5/libHSrts-1.0.2-ghc9.6.5.so
ghc-musl> Build failed.

Additional context

Add any other context about the problem here.

Notify maintainers

@maralorn

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.90, NixOS, 23.11 (Tapir), 23.11.20240512.44072e2`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/5aisrjwl924wyzkv6w79y6j6h51syqbc-source`

Add a 👍 reaction to issues you find important.

@maralorn
Copy link
Member

maralorn commented Jun 3, 2024

cc @sternenseemann @nh2 @ncfavier

@sternenseemann
Copy link
Member

Duplicate of #208959. Seems like a hadrian bug that got fixed in GHC 9.8. I'll not actively pursue a fix for this. May be there's a patch that could be backported, but I'd recommend using GHC 9.4 or 9.8 if you have to.

@sternenseemann sternenseemann closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2024
@NorfairKing
Copy link
Contributor Author

@sternenseemann this is the default ghc for nixos-24.05 though. Can we backport a fix please?

@NorfairKing
Copy link
Contributor Author

NorfairKing commented Jun 3, 2024

https://gitlab.haskell.org/ghc/ghc/-/issues/21567

This looks relevant.

In which case this would be the fix:

https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8244/diffs

Will try with this patch:
https://gitlab.haskell.org/ghc/ghc/-/commit/02d1633466733f154753753c8d9e94062d334b1a.diff

EDIT:
Nope that patch is already in that ghc version, that mustn't have been it.

@NorfairKing
Copy link
Contributor Author

NorfairKing commented Jun 4, 2024

I managed to build GHC like this, with this patch from the future:

From 1bb24432ff77e11a0340a7d8586e151e15bba2a1 Mon Sep 17 00:00:00 2001
From: Cheng Shao <[email protected]>
Date: Tue, 9 May 2023 00:25:25 +0000
Subject: [PATCH] hadrian: fix no_dynamic_libs flavour transformer

This patch fixes the no_dynamic_libs flavour transformer and make
fully_static reuse it. Previously building with no_dynamic_libs fails
since ghc program is still dynamic and transitively brings in dyn ways
of rts which are produced by no rules.
---
 hadrian/src/Flavour.hs | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs
index 47211d0971..27159bc042 100644
--- a/hadrian/src/Flavour.hs
+++ b/hadrian/src/Flavour.hs
@@ -243,10 +243,12 @@ enableProfiledGhc flavour =
 disableDynamicGhcPrograms :: Flavour -> Flavour
 disableDynamicGhcPrograms flavour = flavour { dynamicGhcPrograms = pure False }
 
--- | Don't build libraries in profiled 'Way's.
+-- | Don't build libraries in dynamic 'Way's.
 disableDynamicLibs :: Flavour -> Flavour
 disableDynamicLibs flavour =
-  flavour { libraryWays = prune $ libraryWays flavour
+  flavour { libraryWays = prune $ libraryWays flavour,
+            rtsWays = prune $ rtsWays flavour,
+            dynamicGhcPrograms = pure False
           }
   where
     prune :: Ways -> Ways
@@ -306,18 +308,8 @@ enableBootNonmovingGc = addArgs $ mconcat
 -- for static linking.
 fullyStatic :: Flavour -> Flavour
 fullyStatic flavour =
-    addArgs staticExec
-    $ flavour { dynamicGhcPrograms = return False
-              , libraryWays = prune $ libraryWays flavour
-              , rtsWays     = prune $ rtsWays flavour }
+    addArgs staticExec $ disableDynamicLibs flavour
   where
-    -- Remove any Way that contains a WayUnit of Dynamic
-    prune :: Ways -> Ways
-    prune = fmap $ Set.filter staticCompatible
-
-    staticCompatible :: Way -> Bool
-    staticCompatible = not . wayUnit Dynamic
-
     staticExec :: Args
     {- Some packages, especially iserv, seem to force a set of build ways,
      - including some that are dynamic (in Rules.BinaryDist).  Trying to
@@ -326,7 +318,7 @@ fullyStatic flavour =
      - the Ways will need to include a Way that's not explicitly dynamic
      - (like "vanilla").
      -}
-    staticExec = staticCompatible <$> getWay ? mconcat
+    staticExec = mconcat
         {-
          - Disable dynamic linking by the built ghc executable because the
          - statically-linked musl doesn't support dynamic linking, but will
-- 
2.42.0

Now I'm checking if that lets me build template-haskell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants