on iko/ghcjs-patch-master help sign in
Musl changes (#700)
a500f39Moritz Angermann
builder/comp-builder.nix+5−13
@@ -1,13 +1,6 @@
1{ stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp, zlib, ncurses, numactl, nodejs }:
1{ stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp, zlib, ncurses, numactl, nodejs }:
2−let
3− # These are here to avoid multiple calls to override
4− gmpStatic = gmp.override { withStatic = true; };
5− zlibStatic = zlib.static;
6− ncursesStatic = ncurses.override { enableStatic = true; };
7− numactlStatic = numactl.overrideAttrs (_: { configureFlags = "--enable-static"; });
8−in
9lib.makeOverridable (
2lib.makeOverridable (
10−let self =
3+let self =
11{ componentId
4{ componentId
12, component
5, component
13, package
6, package
@@ -40,7 +33,10 @@ let self =
40, dontStrip ? component.dontStrip
33, dontStrip ? component.dontStrip
41
34
42, enableStatic ? component.enableStatic
35, enableStatic ? component.enableStatic
43−, enableShared ? component.enableShared && !haskellLib.isCrossHost
36+, enableShared ? ghc.enableShared && component.enableShared && !haskellLib.isCrossHost
37+ # on x86 we'll use shared libraries, even with musl m(
38+ # ghc's internal linker seems to be broken on x86.
39+ && !(stdenv.hostPlatform.isMusl && !stdenv.hostPlatform.isx86)
44, enableDeadCodeElimination ? component.enableDeadCodeElimination
40, enableDeadCodeElimination ? component.enableDeadCodeElimination
45
41
46# Options for Haddock generation
42# Options for Haddock generation
@@ -126,10 +122,6 @@ let
126 "--disable-executable-dynamic"
122 "--disable-executable-dynamic"
127 "--ghc-option=-optl=-pthread"
123 "--ghc-option=-optl=-pthread"
128 "--ghc-option=-optl=-static"
124 "--ghc-option=-optl=-static"
129− "--ghc-option=-optl=-L${gmpStatic}/lib"
130− "--ghc-option=-optl=-L${zlibStatic}/lib"
131− "--ghc-option=-optl=-L${ncursesStatic}/lib"
132− "--ghc-option=-optl=-L${numactlStatic}/lib"
133 ] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
125 ] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
134 ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
126 ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
135 ++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
127 ++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
compiler/ghc/default.nix+8−3
@@ -107,6 +107,11 @@ let
107 '' + stdenv.lib.optionalString (!enableTerminfo) ''
107 '' + stdenv.lib.optionalString (!enableTerminfo) ''
108 WITH_TERMINFO=NO
108 WITH_TERMINFO=NO
109 ''
109 ''
110+ # musl doesn't have a system-linker. Only on x86, and on x86 we need it, as
111+ # our elf linker for x86_64 is broken.
112+ + stdenv.lib.optionalString (targetPlatform.isMusl && !targetPlatform.isx86) ''
113+ compiler_CONFIGURE_OPTS += --flags=-dynamic-system-linker
114+ ''
110 # While split sections are now enabled by default in ghc 8.8 for windows,
115 # While split sections are now enabled by default in ghc 8.8 for windows,
111 # the seem to lead to `too many sections` errors when building base for
116 # the seem to lead to `too many sections` errors when building base for
112 # profiling.
117 # profiling.
@@ -284,15 +289,15 @@ stdenv.mkDerivation (rec {
284 if [[ ! -f "$out/bin/${targetPrefix}ghc-pkg" ]]; then
289 if [[ ! -f "$out/bin/${targetPrefix}ghc-pkg" ]]; then
285 echo "ERROR: Missing file $out/bin/${targetPrefix}ghc-pkg"
290 echo "ERROR: Missing file $out/bin/${targetPrefix}ghc-pkg"
286 exit 0
291 exit 0
287− fi
292+ fi
288 if [[ ! -d "$out/lib/${targetPrefix}ghc-${version}" ]]; then
293 if [[ ! -d "$out/lib/${targetPrefix}ghc-${version}" ]]; then
289 echo "ERROR: Missing directory $out/lib/${targetPrefix}ghc-${version}"
294 echo "ERROR: Missing directory $out/lib/${targetPrefix}ghc-${version}"
290 exit 0
295 exit 0
291− fi
296+ fi
292 if (( $(ls -1 "$out/lib/${targetPrefix}ghc-${version}" | wc -l) < 30 )); then
297 if (( $(ls -1 "$out/lib/${targetPrefix}ghc-${version}" | wc -l) < 30 )); then
293 echo "ERROR: Expected more files in $out/lib/${targetPrefix}ghc-${version}"
298 echo "ERROR: Expected more files in $out/lib/${targetPrefix}ghc-${version}"
294 exit 0
299 exit 0
295− fi
300+ fi
296 '';
301 '';
297
302
298 passthru = {
303 passthru = {
overlays/bootstrap.nix+1
@@ -141,6 +141,7 @@ in {
141 # hadrian one.
141 # hadrian one.
142 ++ fromUntil "8.8" "8.12" ./patches/ghc/bec76733b818b0489ffea0834ab6b1560207577c.patch
142 ++ fromUntil "8.8" "8.12" ./patches/ghc/bec76733b818b0489ffea0834ab6b1560207577c.patch
143 ++ fromUntil "8.8" "8.12" ./patches/ghc/67738db10010fd28a8e997b5c8f83ea591b88a0e.patch
143 ++ fromUntil "8.8" "8.12" ./patches/ghc/67738db10010fd28a8e997b5c8f83ea591b88a0e.patch
144+ ++ final.lib.optional (versionAtLeast "8.6.4" && versionLessThan "8.8") ./patches/ghc/ghc-no-system-linker.patch
144 ;
145 ;
145 in ({
146 in ({
146 ghc844 = final.callPackage ../compiler/ghc {
147 ghc844 = final.callPackage ../compiler/ghc {
overlays/hackage-quirks.nix−6
@@ -44,12 +44,6 @@ in { haskell-nix = prev.haskell-nix // {
44 sha256 = "0jcpja4s4cylmg9rddyakb1p1fb4l41ffwmy0njpb1dxc5z3v618";
44 sha256 = "0jcpja4s4cylmg9rddyakb1p1fb4l41ffwmy0njpb1dxc5z3v618";
45 };
45 };
46 })
46 })
47− # Musl needs static zlib
48− (lib.optionalAttrs final.stdenv.hostPlatform.isMusl {
49− packages.pandoc.components.exes.pandoc.configureFlags = [
50− "--ghc-option=-optl=-L${final.zlib.static}/lib"
51− ];
52− })
53 ];
47 ];
54 };
48 };
55
49
overlays/musl.nix+13
@@ -11,6 +11,19 @@ final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl ({
11 # Prevent pkgsMusl.pkgsStatic chain
11 # Prevent pkgsMusl.pkgsStatic chain
12 busybox-sandbox-shell = prev.busybox-sandbox-shell.override { inherit (final) busybox; };
12 busybox-sandbox-shell = prev.busybox-sandbox-shell.override { inherit (final) busybox; };
13
13
14+ # we don't want the static output to be split. That just
15+ # messes with the z -> libz mapping. We can't have a conditonal
16+ # z -> libz / z -> libz.static mapping without threading the
17+ # package configuration in. That seems a bit overkill.
18+ zlib = prev.zlib.override { splitStaticOutput = false; };
19+
20+ # and a few more packages that need their static libs explicitly enabled
21+ gmp = prev.gmp.override { withStatic = true; };
22+ ncurses = prev.ncurses.override { enableStatic = true; };
23+ libsodium = prev.libsodium.overrideAttrs (_: { dontDisableStatic = true; });
24+
25+ numactl = prev.numactl.overrideAttrs (_: { configureFlags = "--enable-static"; });
26+
14 # Fails on cross compile
27 # Fails on cross compile
15 nix = prev.nix.overrideAttrs (_: { doInstallCheck = false; });
28 nix = prev.nix.overrideAttrs (_: { doInstallCheck = false; });
16} // prev.lib.optionalAttrs (prev.lib.versionAtLeast prev.lib.trivial.release "20.03") {
29} // prev.lib.optionalAttrs (prev.lib.versionAtLeast prev.lib.trivial.release "20.03") {
overlays/patches/ghc/ghc-no-system-linker.patchnew file+78
@@ -0,0 +1,78 @@
1+diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
2+index 01628dcad1..209704d034 100644
3+--- a/compiler/ghc.cabal.in
4++++ b/compiler/ghc.cabal.in
5+@@ -45,6 +45,11 @@ Flag terminfo
6+ Default: True
7+ Manual: True
8+
9++Flag dynamic-system-linker
10++ Description: The system can load dynamic code. This is not the case for musl.
11++ Default: True
12++ Manual: False
13++
14+ Library
15+ Default-Language: Haskell2010
16+ Exposed: False
17+@@ -84,6 +89,9 @@ Library
18+ CPP-Options: -DGHCI
19+ Include-Dirs: ../rts/dist/build @FFIIncludeDir@
20+
21++ if flag(dynamic-system-linker)
22++ CPP-Options: -DCAN_LOAD_DLL
23++
24+ Other-Extensions:
25+ BangPatterns
26+ CPP
27+diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
28+index 3b030be2d3..879c5c19ee 100644
29+--- a/compiler/ghci/Linker.hs
30++++ b/compiler/ghci/Linker.hs
31+@@ -1295,13 +1295,13 @@ linkPackage hsc_env pkg
32+
33+ maybePutStr dflags
34+ ("Loading package " ++ sourcePackageIdString pkg ++ " ... ")
35+-
36+ -- See comments with partOfGHCi
37++#if defined(CAN_LOAD_DLL)
38+ when (packageName pkg `notElem` partOfGHCi) $ do
39+ loadFrameworks hsc_env platform pkg
40+ mapM_ (load_dyn hsc_env)
41+ (known_dlls ++ map (mkSOName platform) dlls)
42+-
43++#endif
44+ -- After loading all the DLLs, we can load the static objects.
45+ -- Ordering isn't important here, because we do one final link
46+ -- step to resolve everything.
47+@@ -1382,10 +1382,15 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
48+ -- O(n). Loading an import library is also O(n) so in general we prefer
49+ -- shared libraries because they are simpler and faster.
50+ --
51+- = findDll user `orElse`
52++ =
53++#if defined(CAN_LOAD_DLL)
54++ findDll user `orElse`
55++#endif
56+ tryImpLib user `orElse`
57++#if defined(CAN_LOAD_DLL)
58+ findDll gcc `orElse`
59+ findSysDll `orElse`
60++#endif
61+ tryImpLib gcc `orElse`
62+ findArchive `orElse`
63+ tryGcc `orElse`
64+@@ -1452,7 +1457,13 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
65+ full = dllpath $ search lib_so_name lib_dirs
66+ gcc name = liftM (fmap Archive) $ search name lib_dirs
67+ files = import_libs ++ arch_files
68+- in apply $ short : full : map gcc files
69++ dlls = [short, full]
70++ archives = map gcc files
71++ in apply $
72++#if defined(CAN_LOAD_DLL)
73++ dlls ++
74++#endif
75++ archives
76+ tryImpLib re = case os of
77+ OSMinGW32 ->
78+ let dirs' = if re == user then lib_dirs else gcc_dirs
test/fully-static/default.nix+2−23
@@ -17,32 +17,11 @@ let
17 src = testSrc "fully-static";
17 src = testSrc "fully-static";
18 pkg-def-extras = [];
18 pkg-def-extras = [];
19 modules = [
19 modules = [
20− # Musl libc fully static build
21− (let
22− staticLibs = [
23− zlib.static
24− (openssl.override { static = true; }).out
25− (libffi.overrideAttrs (oldAttrs: {
26− dontDisableStatic = true;
27− configureFlags = (oldAttrs.configureFlags or []) ++ [
28− "--enable-static"
29− "--disable-shared"
30− ];
31− }))
32− ] ++ optional gpl (gmp6.override { withStatic = true; });
33−
34− withFullyStatic = {
35− configureFlags =
36− optionals stdenv.hostPlatform.isMusl (map (drv: "--ghc-option=-optl=-L${drv}/lib") staticLibs);
37− };
38− in {
20+ {
39 # Select a non-GMP compiler, usually for software licensing reasons.
21 # Select a non-GMP compiler, usually for software licensing reasons.
40 ghc.package = mkIf (stdenv.hostPlatform.isMusl && !gpl)
22 ghc.package = mkIf (stdenv.hostPlatform.isMusl && !gpl)
41 buildPackages.haskell-nix.compiler.integer-simple.${compiler};
23 buildPackages.haskell-nix.compiler.integer-simple.${compiler};
42−
43− # Add GHC flags and libraries for fully static build
44− packages.pandoc.components.exes.pandoc = withFullyStatic;
45− })
24+ }
46 ];
25 ];
47 };
26 };
48 packagesGmp = (project { gpl = true; }).hsPkgs;
27 packagesGmp = (project { gpl = true; }).hsPkgs;