on iko/ghcjs-patch-master help sign in
Add native musl support (#578)

* Add native musl support - adds haskellLibl.isNaviveMusl and related fixes (previously it was assumed that for musl we always use cross-compilation) - fixed some issues for musl intoduced in nixpkgs 20.03 (ssh/fetchcvs infinite recursion, busybox pkgsMusl.pkgsStatic chain, etc.) - cross-compilation fixes for ghc (absolute path for ar, always pass target to configure, libffi and gmp packages for target platform) - this needs more testing * Better explanation for targetPlatform.{libffi, gmp} * Ghc configure script now respect AR env variable Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>

commitde3f82a419976c5a5f95a149553673b72fbe94ea authorAlexander Kudryashov <tuxmaniacster@gmail.com> dateFri 8 May 2020, 12:32 (6 years ago) parent794f796
9 files changed+46−15
builder/comp-builder.nix+3−1 builder/default.nix+1−1 builder/ghc-for-component-wrapper.nix+1−1 compiler/ghc/default.nix+10−8 lib/default.nix+4 overlays/bootstrap.nix+1 overlays/musl.nix+11−2 overlays/patches/ghc/respect-ar-path.patch+12 overlays/tools.nix+3−2
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 }:
22
33lib.makeOverridable (
44{ componentId
@@ -118,6 +118,8 @@ let
118118 "--ghc-option=-optl=-pthread"
119119 "--ghc-option=-optl=-static"
120120 "--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"
121123 ] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
122124 ++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
123125 ++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
builder/default.nix+1−1
@@ -43,7 +43,7 @@ let
4343 in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
4444 haskellLib.weakCallPackage pkgs nixpkgsHoogle {
4545 # 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
4747 then ghc.buildGHC
4848 else ghc;
4949 inherit packages hoogle;
builder/ghc-for-component-wrapper.nix+1−1
@@ -19,7 +19,7 @@ let
1919 libDir = "$out/${configFiles.libDir}";
2020 docDir = "$out/share/doc/ghc/html";
2121 # 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)
2323 then ghc.buildGHC
2424 else ghc;
2525
compiler/ghc/default.nix+10−8
@@ -68,11 +68,15 @@ let
6868
6969 # TODO check if this posible fix for segfaults works or not.
7070 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.
7175 if stdenv.targetPlatform.isMusl
72− then targetPackages.libffi.overrideAttrs (old: { dontDisableStatic = true; })
73− else if targetPlatform != hostPlatform
74− then targetPackages.libffi
75− else libffi;
76+ then targetLibffi.overrideAttrs (old: { dontDisableStatic = true; })
77+ else targetLibffi;
78+
79+ targetGmp = targetPackages.gmp or gmp;
7680
7781 # TODO(@Ericson2314) Make unconditional
7882 targetPrefix = stdenv.lib.optionalString
@@ -195,16 +199,14 @@ in let configured-src = stdenv.mkDerivation (rec {
195199 done
196200 '';
197201
198− # TODO(@Ericson2314): Always pass "--target" and always prefix.
199− configurePlatforms = [ "build" "host" ]
200− ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
202+ configurePlatforms = [ "build" "host" "target" ];
201203 # `--with` flags for libraries needed for RTS linker
202204 configureFlags = [
203205 "--datadir=$doc/share/doc/ghc"
204206 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
205207 ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
206208 ] ++ 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"
208210 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
209211 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
210212 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
lib/default.nix+4
@@ -199,6 +199,10 @@ with haskellLib;
199199 # This is the same as isCrossHost but for use when building ghc itself
200200 isCrossTarget = stdenv.targetPlatform != stdenv.hostPlatform
201201 && !(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;
202206
203207 # Takes a version number or attr set of arguments (for cabalProject)
204208 # and conversios it to an attr set of argments. This allows
overlays/bootstrap.nix+1
@@ -100,6 +100,7 @@ in {
100100 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/ghc-8.6.4-prim-no-arm-atomics.patch
101101 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table.patch
102102 ++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table-2.patch
103+ ++ always ./patches/ghc/respect-ar-path.patch
103104
104105 ++ final.lib.optional (version == "8.6.3") ./patches/ghc/T16057--ghci-doa-on-windows.patch
105106 ++ 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 ({
22 # On nixpkgs 19.09 openssl is configured as `linux-generic64` instead
33 # of `linux-x86_64` and as a result the `asm` parts of of openssl
44 # 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 {
77 prev.lib.optionalAttrs prev.stdenv.hostPlatform.isx86_64 {
88 configureScript = "./Configure linux-x86_64";
99 });
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 // {
8080 sha256 = "0d158xifwvz0y69ah98ckxakzqpz229mq7rpf2bpbmwhnpw3jmm6";
8181 };
8282 modules = [({config, ...}: {
83− packages.ghcide.configureFlags = [ "--enable-executable-dynamic" ];
83+ packages.ghcide.configureFlags = lib.optional (!final.stdenv.targetPlatform.isMusl)
84+ "--enable-executable-dynamic";
8485 nonReinstallablePkgs = [ "Cabal" "array" "base" "binary" "bytestring" "containers" "deepseq"
8586 "directory" "filepath" "ghc" "ghc-boot" "ghc-boot-th" "ghc-compact"
8687 "ghc-heap" "ghc-prim" "ghci" "haskeline" "hpc" "integer-gmp"
@@ -99,4 +100,4 @@ in { haskell-nix = prev.haskell-nix // {
99100 ];
100101 })).ghcide.components.exes.ghcide;
101102 };
102−}; }
103+}; }