Merge pull request #154046 from hexagonal-sun/ghc-fix-bin-outputs-on-aarch64-darwin

ghc8107: fix seperate bin outputs on aarch64-darwin

authored by Ben Siraphob and committed by GitHub e68cbf0c 8da5ec7c

+108
+9
pkgs/development/compilers/ghc/8.10.7.nix
··· 212 url = "https://gitlab.haskell.org/ghc/ghc/-/commit/97d0b0a367e4c6a52a17c3299439ac7de129da24.patch"; 213 sha256 = "0r4zjj0bv1x1m2dgxp3adsf2xkr94fjnyj1igsivd9ilbs5ja0b5"; 214 }) 215 ]; 216 217 postPatch = "patchShebangs .";
··· 212 url = "https://gitlab.haskell.org/ghc/ghc/-/commit/97d0b0a367e4c6a52a17c3299439ac7de129da24.patch"; 213 sha256 = "0r4zjj0bv1x1m2dgxp3adsf2xkr94fjnyj1igsivd9ilbs5ja0b5"; 214 }) 215 + ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 216 + 217 + # Prevent the paths module from emitting symbols that we don't use 218 + # when building with separate outputs. 219 + # 220 + # These cause problems as they're not eliminated by GHC's dead code 221 + # elimination on aarch64-darwin. (see 222 + # https://github.com/NixOS/nixpkgs/issues/140774 for details). 223 + ./cabal-paths.patch 224 ]; 225 226 postPatch = "patchShebangs .";
+99
pkgs/development/compilers/ghc/cabal-paths.patch
···
··· 1 + diff --git a/Cabal/Distribution/Simple/Build/PathsModule.hs b/Cabal/Distribution/Simple/Build/PathsModule.hs 2 + index 5e660e8d6..1ae603c94 100644 3 + --- a/libraries/Cabal/Cabal/Distribution/Simple/Build/PathsModule.hs 4 + +++ b/libraries/Cabal/Cabal/Distribution/Simple/Build/PathsModule.hs 5 + @@ -37,6 +37,9 @@ import System.FilePath ( pathSeparator ) 6 + -- * Building Paths_<pkg>.hs 7 + -- ------------------------------------------------------------ 8 + 9 + +splitPath :: FilePath -> [ String ] 10 + +splitPath = unintersperse pathSeparator 11 + + 12 + generatePathsModule :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> String 13 + generatePathsModule pkg_descr lbi clbi = 14 + let pragmas = 15 + @@ -78,12 +81,44 @@ generatePathsModule pkg_descr lbi clbi = 16 + "import System.Environment (getExecutablePath)\n" 17 + | otherwise = "" 18 + 19 + + dirs = [ (flat_libdir, "LibDir") 20 + + , (flat_dynlibdir, "DynLibDir") 21 + + , (flat_datadir, "DataDir") 22 + + , (flat_libexecdir, "LibexecDir") 23 + + , (flat_sysconfdir, "SysconfDir") ]; 24 + + 25 + + shouldEmitPath p 26 + + | (splitPath flat_prefix) `isPrefixOf` (splitPath flat_bindir) = True 27 + + | (splitPath flat_prefix) `isPrefixOf` (splitPath p) = False 28 + + | otherwise = True 29 + + 30 + + shouldEmitDataDir = shouldEmitPath flat_datadir 31 + + 32 + + nixEmitPathFn (path, name) = let 33 + + varName = toLower <$> name 34 + + fnName = "get"++name 35 + + in if shouldEmitPath path then 36 + + varName ++ " :: FilePath\n"++ 37 + + varName ++ " = " ++ show path ++ 38 + + "\n" ++ fnName ++ " :: IO FilePath" ++ 39 + + "\n" ++ fnName ++ " = " ++ mkGetEnvOr varName ("return " ++ varName)++"\n" 40 + + else "" 41 + + 42 + + absBody = intercalate "\n" $ nixEmitPathFn <$> dirs 43 + + 44 + + warnPragma = case filter (not . shouldEmitPath . fst) dirs of 45 + + [] -> "" 46 + + omittedDirs -> "{-# WARNING \"The functions: "++omittedFns++" Have been omitted by the Nix build system.\" #-}" 47 + + where omittedFns = intercalate ", " $ map snd omittedDirs 48 + + 49 + + importList = intercalate ", " $ ("get" ++) . snd <$> filter (shouldEmitPath . fst) dirs 50 + + 51 + header = 52 + pragmas++ 53 + - "module " ++ prettyShow paths_modulename ++ " (\n"++ 54 + - " version,\n"++ 55 + - " getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,\n"++ 56 + - " getDataFileName, getSysconfDir\n"++ 57 + + "module " ++ prettyShow paths_modulename ++ " " ++ warnPragma ++ " (\n"++ 58 + + " version, getBinDir,\n"++ 59 + + (if shouldEmitDataDir then " getDataFileName, \n" else "\n")++ 60 + + " " ++ importList ++"\n"++ 61 + " ) where\n"++ 62 + "\n"++ 63 + foreign_imports++ 64 + @@ -136,26 +171,18 @@ generatePathsModule pkg_descr lbi clbi = 65 + "\n"++ 66 + filename_stuff 67 + | absolute = 68 + - "\nbindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath\n"++ 69 + + "\nbindir :: FilePath\n"++ 70 + "\nbindir = " ++ show flat_bindir ++ 71 + - "\nlibdir = " ++ show flat_libdir ++ 72 + - "\ndynlibdir = " ++ show flat_dynlibdir ++ 73 + - "\ndatadir = " ++ show flat_datadir ++ 74 + - "\nlibexecdir = " ++ show flat_libexecdir ++ 75 + - "\nsysconfdir = " ++ show flat_sysconfdir ++ 76 + "\n"++ 77 + - "\ngetBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"++ 78 + + "\ngetBinDir :: IO FilePath\n"++ 79 + "getBinDir = "++mkGetEnvOr "bindir" "return bindir"++"\n"++ 80 + - "getLibDir = "++mkGetEnvOr "libdir" "return libdir"++"\n"++ 81 + - "getDynLibDir = "++mkGetEnvOr "dynlibdir" "return dynlibdir"++"\n"++ 82 + - "getDataDir = "++mkGetEnvOr "datadir" "return datadir"++"\n"++ 83 + - "getLibexecDir = "++mkGetEnvOr "libexecdir" "return libexecdir"++"\n"++ 84 + - "getSysconfDir = "++mkGetEnvOr "sysconfdir" "return sysconfdir"++"\n"++ 85 + - "\n"++ 86 + - "getDataFileName :: FilePath -> IO FilePath\n"++ 87 + - "getDataFileName name = do\n"++ 88 + - " dir <- getDataDir\n"++ 89 + - " return (dir ++ "++path_sep++" ++ name)\n" 90 + + absBody ++ "\n"++ 91 + + (if shouldEmitDataDir then 92 + + "getDataFileName :: FilePath -> IO FilePath\n"++ 93 + + "getDataFileName name = do\n"++ 94 + + " dir <- getDataDir\n"++ 95 + + " return (dir ++ "++path_sep++" ++ name)\n" 96 + + else "\n") 97 + | otherwise = 98 + "\nprefix, bindirrel :: FilePath" ++ 99 + "\nprefix = " ++ show flat_prefix ++