on iko/ghcjs-patch-master help sign in
Add native musl support (#578)
de3f82aAlexander Kudryashov
builder/comp-builder.nix+3−1
@@ -1,4 +1,4 @@
1−{ stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp, nodejs }:
1+{ stdenv, buildPackages, ghc, lib, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp, zlib, ncurses, nodejs }:
2
2
3lib.makeOverridable (
3lib.makeOverridable (
4{ componentId
4{ componentId
@@ -118,6 +118,8 @@ let
118 "--ghc-option=-optl=-pthread"
118 "--ghc-option=-optl=-pthread"
119 "--ghc-option=-optl=-static"
119 "--ghc-option=-optl=-static"
120 "--ghc-option=-optl=-L${gmp.override { withStatic = true; }}/lib"
120 "--ghc-option=-optl=-L${gmp.override { withStatic = true; }}/lib"
121+ "--ghc-option=-optl=-L${zlib.static}/lib"
122+ "--ghc-option=-optl=-L${ncurses.override { enableStatic = true; }}/lib"
121 ] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
123 ] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
122 ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
124 ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
123 ++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
125 ++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
builder/default.nix+1−1
@@ -43,7 +43,7 @@ let
43 in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
43 in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
44 haskellLib.weakCallPackage pkgs nixpkgsHoogle {
44 haskellLib.weakCallPackage pkgs nixpkgsHoogle {
45 # For musl we can use haddock from the buildGHC
45 # For musl we can use haddock from the buildGHC
46− ghc = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl
46+ ghc = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
47 then ghc.buildGHC
47 then ghc.buildGHC
48 else ghc;
48 else ghc;
49 inherit packages hoogle;
49 inherit packages hoogle;
builder/ghc-for-component-wrapper.nix+1−1
@@ -19,7 +19,7 @@ let
19 libDir = "$out/${configFiles.libDir}";
19 libDir = "$out/${configFiles.libDir}";
20 docDir = "$out/share/doc/ghc/html";
20 docDir = "$out/share/doc/ghc/html";
21 # For musl we can use haddock from the buildGHC
21 # For musl we can use haddock from the buildGHC
22− haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl
22+ haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !(stdenv.buildPlatform == stdenv.hostPlatform)
23 then ghc.buildGHC
23 then ghc.buildGHC
24 else ghc;
24 else ghc;
25
25
compiler/ghc/default.nix+10−8
@@ -68,11 +68,15 @@ let
68
68
69 # TODO check if this posible fix for segfaults works or not.
69 # TODO check if this posible fix for segfaults works or not.
70 targetLibffi =
70 targetLibffi =
71+ # on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
72+ # to the non-targetPlatform version in those cases.
73+ let targetLibffi = targetPackages.libffi or libffi; in
74+ # we need to set `dontDisableStatic` for musl for libffi to work.
71 if stdenv.targetPlatform.isMusl
75 if stdenv.targetPlatform.isMusl
72− then targetPackages.libffi.overrideAttrs (old: { dontDisableStatic = true; })
76+ then targetLibffi.overrideAttrs (old: { dontDisableStatic = true; })
73− else if targetPlatform != hostPlatform
77+ else targetLibffi;
78+
74− then targetPackages.libffi
79+ targetGmp = targetPackages.gmp or gmp;
75− else libffi;
76
80
77 # TODO(@Ericson2314) Make unconditional
81 # TODO(@Ericson2314) Make unconditional
78 targetPrefix = stdenv.lib.optionalString
82 targetPrefix = stdenv.lib.optionalString
@@ -195,16 +199,14 @@ in let configured-src = stdenv.mkDerivation (rec {
195 done
199 done
196 '';
200 '';
197
201
198− # TODO(@Ericson2314): Always pass "--target" and always prefix.
199− configurePlatforms = [ "build" "host" ]
202+ configurePlatforms = [ "build" "host" "target" ];
200− ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
201 # `--with` flags for libraries needed for RTS linker
203 # `--with` flags for libraries needed for RTS linker
202 configureFlags = [
204 configureFlags = [
203 "--datadir=$doc/share/doc/ghc"
205 "--datadir=$doc/share/doc/ghc"
204 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
206 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
205 ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
207 ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
206 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
208 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
207− "--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
209+ "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
208 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
210 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
209 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
211 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
210 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
212 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
lib/default.nix+4
@@ -199,6 +199,10 @@ with haskellLib;
199 # This is the same as isCrossHost but for use when building ghc itself
199 # This is the same as isCrossHost but for use when building ghc itself
200 isCrossTarget = stdenv.targetPlatform != stdenv.hostPlatform
200 isCrossTarget = stdenv.targetPlatform != stdenv.hostPlatform
201 && !(stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && stdenv.hostPlatform.isx86 && stdenv.targetPlatform.isx86);
201 && !(stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && stdenv.hostPlatform.isx86 && stdenv.targetPlatform.isx86);
202+ # Native musl build-host-target combo
203+ isNativeMusl = stdenv.hostPlatform.isMusl
204+ && stdenv.buildPlatform == stdenv.hostPlatform
205+ && stdenv.hostPlatform == stdenv.targetPlatform;
202
206
203 # Takes a version number or attr set of arguments (for cabalProject)
207 # Takes a version number or attr set of arguments (for cabalProject)
204 # and conversios it to an attr set of argments. This allows
208 # and conversios it to an attr set of argments. This allows
overlays/bootstrap.nix+1
@@ -100,6 +100,7 @@ in {
100 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/ghc-8.6.4-prim-no-arm-atomics.patch
100 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/ghc-8.6.4-prim-no-arm-atomics.patch
101 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table.patch
101 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table.patch
102 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table-2.patch
102 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table-2.patch
103+ ++ always ./patches/ghc/respect-ar-path.patch
103
104
104 ++ final.lib.optional (version == "8.6.3") ./patches/ghc/T16057--ghci-doa-on-windows.patch
105 ++ final.lib.optional (version == "8.6.3") ./patches/ghc/T16057--ghci-doa-on-windows.patch
105 ++ final.lib.optional (version == "8.6.3") ./patches/ghc/ghc-8.6.3-reinstallable-lib-ghc.patch
106 ++ final.lib.optional (version == "8.6.3") ./patches/ghc/ghc-8.6.3-reinstallable-lib-ghc.patch
overlays/musl.nix+11−2
@@ -1,4 +1,4 @@
1−final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl {
1+final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl ({
2 # On nixpkgs 19.09 openssl is configured as `linux-generic64` instead
2 # On nixpkgs 19.09 openssl is configured as `linux-generic64` instead
3 # of `linux-x86_64` and as a result the `asm` parts of of openssl
3 # of `linux-x86_64` and as a result the `asm` parts of of openssl
4 # are not built. Because the `no_asm` configure flag is also not passed
4 # are not built. Because the `no_asm` configure flag is also not passed
@@ -7,4 +7,13 @@ final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl {
7 prev.lib.optionalAttrs prev.stdenv.hostPlatform.isx86_64 {
7 prev.lib.optionalAttrs prev.stdenv.hostPlatform.isx86_64 {
8 configureScript = "./Configure linux-x86_64";
8 configureScript = "./Configure linux-x86_64";
9 });
9 });
10−}
10+
11+ # Prevent pkgsMusl.pkgsStatic chain
12+ busybox-sandbox-shell = prev.busybox-sandbox-shell.override { inherit (final) busybox; };
13+
14+ # Fails on cross compile
15+ nix = prev.nix.overrideAttrs (_: { doInstallCheck = false; });
16+} // prev.lib.optionalAttrs (prev.lib.versionAtLeast prev.lib.version "20.03") {
17+ # Fix infinite recursion between openssh and fetchcvs
18+ openssh = prev.openssh.override { withFIDO = false; };
19+})
overlays/patches/ghc/respect-ar-path.patchnew file+12
@@ -0,0 +1,12 @@
1+--- a/aclocal.m4 2020-05-06 12:01:51.205674085 +0500
2++++ b/aclocal.m4 2020-05-06 12:02:36.619673673 +0500
3+@@ -1079,7 +1079,8 @@
4+ # thinks that target == host so it never checks the unqualified
5+ # tools for Windows. See #14274.
6+ AC_DEFUN([FP_PROG_AR],
7+-[if test -z "$fp_prog_ar"; then
8++[AC_SUBST(fp_prog_ar,$AR)
9++if test -z "$fp_prog_ar"; then
10+ if test "$HostOS" = "mingw32"
11+ then
12+ AC_PATH_PROG([fp_prog_ar], [ar])
overlays/tools.nix+3−2
@@ -80,7 +80,8 @@ in { haskell-nix = prev.haskell-nix // {
80 sha256 = "0d158xifwvz0y69ah98ckxakzqpz229mq7rpf2bpbmwhnpw3jmm6";
80 sha256 = "0d158xifwvz0y69ah98ckxakzqpz229mq7rpf2bpbmwhnpw3jmm6";
81 };
81 };
82 modules = [({config, ...}: {
82 modules = [({config, ...}: {
83+ packages.ghcide.configureFlags = lib.optional (!final.stdenv.targetPlatform.isMusl)
83− packages.ghcide.configureFlags = [ "--enable-executable-dynamic" ];
84+ "--enable-executable-dynamic";
84 nonReinstallablePkgs = [ "Cabal" "array" "base" "binary" "bytestring" "containers" "deepseq"
85 nonReinstallablePkgs = [ "Cabal" "array" "base" "binary" "bytestring" "containers" "deepseq"
85 "directory" "filepath" "ghc" "ghc-boot" "ghc-boot-th" "ghc-compact"
86 "directory" "filepath" "ghc" "ghc-boot" "ghc-boot-th" "ghc-compact"
86 "ghc-heap" "ghc-prim" "ghci" "haskeline" "hpc" "integer-gmp"
87 "ghc-heap" "ghc-prim" "ghci" "haskeline" "hpc" "integer-gmp"
@@ -99,4 +100,4 @@ in { haskell-nix = prev.haskell-nix // {
99 ];
100 ];
100 })).ghcide.components.exes.ghcide;
101 })).ghcide.components.exes.ghcide;
101 };
102 };
102−}; }
103+}; }