Skip to content

Commit c7ba0f9

Browse files
committed
Merge branch 'master' into support-cabal-doctest
2 parents a1f6eaf + fbeb1e0 commit c7ba0f9

File tree

31 files changed

+234
-119
lines changed

31 files changed

+234
-119
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cabal new-repl your-package-name:library:your-package-name
7777
CI pushes to [[https://cachix.org][cachix]] so you can benefit from the cache
7878
if you pin a combination of =haskell.nix= and =nixpkgs= built by CI.
7979

80-
You'll need to configure the [[https://nix-tools.cachix.org][nix-tools cachix]]
80+
You'll need to configure the [[https://iohk.cachix.org][iohk cachix]]
8181
as a =substituter= for =nix= and add the public key found at the url to
8282
=trusted-public-keys=.
8383

builder/comp-builder.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
, dontStrip ? component.dontStrip
2727

2828
, enableStatic ? component.enableStatic
29-
, enableShared ? component.enableShared && !stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.useiOSPrebuilt
29+
, enableShared ? component.enableShared && !haskellLib.isCrossHost
3030
, enableDeadCodeElimination ? component.enableDeadCodeElimination
3131

3232
# Options for Haddock generation
@@ -106,11 +106,20 @@ let
106106
(enableFeature enableExecutableProfiling "executable-profiling")
107107
(enableFeature enableStatic "static")
108108
(enableFeature enableShared "shared")
109+
] ++ lib.optionals (stdenv.hostPlatform.isMusl && (haskellLib.isExecutableType componentId)) [
110+
# These flags will make sure the resulting executable is statically linked.
111+
# If it uses other libraries it may be necessary for to add more
112+
# `--ghc-option=-optl=-L` options to the `configurationFlags` of the
113+
# component.
114+
"--disable-executable-dynamic"
115+
"--ghc-option=-optl=-pthread"
116+
"--ghc-option=-optl=-static"
117+
"--ghc-option=-optl=-L${gmp.override { withStatic = true; }}/lib"
109118
] ++ lib.optional enableSeparateDataOutput "--datadir=$data/share/${ghc.name}"
110119
++ lib.optional doHaddock' "--docdir=${docdir "$doc"}"
111120
++ lib.optional (enableLibraryProfiling || enableExecutableProfiling) "--profiling-detail=${profilingDetail}"
112121
++ lib.optional stdenv.hostPlatform.isLinux (enableFeature enableDeadCodeElimination "split-sections")
113-
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
122+
++ lib.optionals haskellLib.isCrossHost (
114123
map (arg: "--hsc2hs-option=" + arg) (["--cross-compile"] ++ lib.optionals (stdenv.hostPlatform.isWindows) ["--via-asm"])
115124
++ lib.optional (package.buildType == "Configure") "--configure-option=--host=${stdenv.hostPlatform.config}" )
116125
++ component.configureFlags
@@ -142,7 +151,7 @@ let
142151

143152
doHaddock' = doHaddock
144153
&& (haskellLib.isLibrary componentId)
145-
&& stdenv.hostPlatform == stdenv.buildPlatform;
154+
&& !haskellLib.isCrossHost;
146155

147156
exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe";
148157
exeName = componentId.cname + exeExt;

builder/default.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ let
3939

4040

4141
hoogleLocal = let
42-
nixpkgsHoogleLocal = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
43-
in { packages ? [], hoogle ? pkgs.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
42+
# Use the latest default nixpkgs hoogle.nix, as the 19.03 one does not work with cross compilers
43+
nixpkgsHoogleLocal = import ((import ../nixpkgs {}).path + /pkgs/development/haskell-modules/hoogle.nix);
44+
in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.haskellPackages.hoogle.components.exes.hoogle }:
4445
haskellLib.weakCallPackage pkgs nixpkgsHoogleLocal {
45-
ghc = pkgs.haskell-nix.ghc;
46+
# For musl we can use haddock from the buildGHC
47+
ghc = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl
48+
then ghc.buildGHC
49+
else ghc;
4650
inherit packages hoogle;
4751
};
4852

builder/ghc-for-component-wrapper.nix

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515
}:
1616

1717
let
18-
inherit (configFiles) ghcCommand ghcCommandCaps packageCfgDir;
18+
inherit (configFiles) targetPrefix ghcCommand ghcCommandCaps packageCfgDir;
1919
libDir = "$out/${configFiles.libDir}";
2020
docDir = "$out/share/doc/ghc/html";
21+
# For musl we can use haddock from the buildGHC
22+
haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl
23+
then ghc.buildGHC
24+
else ghc;
2125

2226
in runCommand "${componentName}-${ghc.name}-env" {
2327
preferLocalBuild = true;
2428
passthru = {
2529
inherit (ghc) version meta;
30+
inherit targetPrefix;
2631
baseGhc = ghc;
2732
};
2833
} (
@@ -62,7 +67,7 @@ in runCommand "${componentName}-${ghc.name}-env" {
6267
fi
6368
done
6469
65-
for prg in runghc runhaskell; do
70+
for prg in "${targetPrefix}runghc" "${targetPrefix}runhaskell"; do
6671
if [[ -x "${ghc}/bin/$prg" ]]; then
6772
rm -f $out/bin/$prg
6873
makeWrapper ${ghc}/bin/$prg $out/bin/$prg \
@@ -75,9 +80,9 @@ in runCommand "${componentName}-${ghc.name}-env" {
7580
done
7681
7782
# Wrap haddock, if the base GHC provides it.
78-
if [[ -x "${ghc}/bin/haddock" ]]; then
83+
if [[ -x "${haddock}/bin/haddock" ]]; then
7984
rm -f $out/bin/haddock
80-
makeWrapper ${ghc}/bin/haddock $out/bin/haddock \
85+
makeWrapper ${haddock}/bin/haddock $out/bin/haddock \
8186
--add-flags '"-B$NIX_${ghcCommandCaps}_LIBDIR"' \
8287
--set "NIX_${ghcCommandCaps}_LIBDIR" "${libDir}"
8388
fi

builder/make-config-files.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ let
6666
in { identifier, component, fullName, flags ? {} }:
6767
# Filters out only library packages that for this GHC target
6868
# TODO investigate why this is needed
69-
let libDeps = lib.filter (p: p.configFiles.targetPrefix == ghc.targetPrefix)
69+
# TODO find out why p ? configFiles helps (for instance for `R1909.aarch64-unknown-linux-gnu.tests.cabal-22.run.x86_64-linux`)
70+
let libDeps = lib.filter (p: (p ? configFiles) && p.configFiles.targetPrefix == ghc.targetPrefix)
7071
(map getLibComponent component.depends);
7172
cfgFiles =
7273
let xs = map

builder/shell-for.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
, ... } @ args:
1313

1414
let
15+
# TODO find out why hoogle index creation can be made to work for cross compilers
16+
withHoogle' = withHoogle && !haskellLib.isCrossHost;
1517
selected = packages hsPkgs;
1618
additionalSelected = additional hsPkgs;
1719
selectedConfigs = map (p: p.components.all.config) selected;
@@ -53,7 +55,7 @@ let
5355
ghcEnv = ghcForComponent {
5456
inherit configFiles;
5557
componentName = name;
56-
postInstall = lib.optionalString withHoogle ''
58+
postInstall = lib.optionalString withHoogle' ''
5759
ln -s ${hoogleIndex}/bin/hoogle $out/bin
5860
'';
5961
};
@@ -79,7 +81,7 @@ in
7981

8082
buildInputs = systemInputs
8183
++ mkDrvArgs.buildInputs or []
82-
++ lib.optional withHoogle hoogleIndex;
84+
++ lib.optional withHoogle' hoogleIndex;
8385
nativeBuildInputs = [ ghcEnv ]
8486
++ nativeBuildInputs
8587
++ mkDrvArgs.nativeBuildInputs or [];

compiler/ghc/default.nix

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# haskell.nix ships its own version of the ghc expression as it needs more
44
# control over the expression to isolate it against varying <nixpkgs> and
55
# allow us to customize it to the way haskell.nix works.
6-
{ stdenv, targetPackages
6+
{ stdenv, haskell-nix, targetPackages
77

88
# build-tools
99
, bootPkgs
@@ -33,15 +33,24 @@
3333

3434
, # Whether to build dynamic libs for the standard library (on the target
3535
# platform). Static libs are always built.
36-
enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt
36+
enableShared ? !haskell-nix.haskellLib.isCrossTarget
3737

38-
, # Whetherto build terminfo.
39-
enableTerminfo ? !stdenv.targetPlatform.isWindows
38+
, # Whetherto build terminfo. Musl fails to build terminfo as ncurses seems to be linked to glibc
39+
enableTerminfo ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.isMusl
4040

4141
, # What flavour to build. An empty string indicates no
4242
# specific flavour and falls back to ghc default values.
43-
ghcFlavour ? stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
44-
(if useLLVM then "quick-cross" else "perf-cross-ncg")
43+
ghcFlavour ? stdenv.lib.optionalString haskell-nix.haskellLib.isCrossTarget (
44+
if useLLVM
45+
then (
46+
# TODO check if the issues with qemu and Aarch32 persist. See
47+
# https://github.com/input-output-hk/haskell.nix/pull/411/commits/1986264683067198e7fdc1d665351622b664712e
48+
if stdenv.targetPlatform.isAarch32
49+
then "quick-cross"
50+
else "perf-cross"
51+
)
52+
else "perf-cross-ncg"
53+
)
4554

4655
, # Whether to disable the large address space allocator
4756
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
@@ -59,9 +68,15 @@ assert !enableIntegerSimple -> gmp != null;
5968

6069
let
6170
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
71+
inherit (haskell-nix.haskellLib) isCrossTarget;
6272

6373
inherit (bootPkgs) ghc;
6474

75+
# TODO check if this posible fix for segfaults works or not.
76+
libffiStaticEnabled = if libffi == null || !stdenv.targetPlatform.isMusl
77+
then libffi
78+
else targetPackages.libffi.overrideAttrs (old: { dontDisableStatic = true; });
79+
6580
# TODO(@Ericson2314) Make unconditional
6681
targetPrefix = stdenv.lib.optionalString
6782
(targetPlatform != hostPlatform)
@@ -75,8 +90,9 @@ let
7590
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
7691
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
7792
'' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
78-
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
7993
CrossCompilePrefix = ${targetPrefix}
94+
'' + stdenv.lib.optionalString isCrossTarget ''
95+
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
8096
HADDOCK_DOCS = NO
8197
BUILD_SPHINX_HTML = NO
8298
BUILD_SPHINX_PDF = NO
@@ -88,11 +104,19 @@ let
88104
'' + stdenv.lib.optionalString useLLVM ''
89105
GhcStage2HcOpts += -fast-llvm
90106
GhcLibHcOpts += -fast-llvm
107+
'' + stdenv.lib.optionalString (!enableTerminfo) ''
108+
WITH_TERMINFO=NO
109+
''
110+
# 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
112+
# profiling.
113+
+ stdenv.lib.optionalString targetPlatform.isWindows ''
114+
SplitSections = NO
91115
'';
92116

93117
# Splicer will pull out correct variations
94118
libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
95-
++ [libffi]
119+
++ [libffiStaticEnabled]
96120
++ stdenv.lib.optional (!enableIntegerSimple) gmp
97121
++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
98122

@@ -184,7 +208,7 @@ in let configured-src = stdenv.mkDerivation (rec {
184208
configureFlags = [
185209
"--datadir=$doc/share/doc/ghc"
186210
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
187-
] ++ stdenv.lib.optionals (libffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetPackages.libffi.dev}/include" "--with-ffi-libraries=${targetPackages.libffi.out}/lib"
211+
] ++ stdenv.lib.optionals (libffiStaticEnabled != null) ["--with-system-libffi" "--with-ffi-includes=${libffiStaticEnabled.dev}/include" "--with-ffi-libraries=${libffiStaticEnabled.out}/lib"
188212
] ++ stdenv.lib.optional (!enableIntegerSimple) [
189213
"--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
190214
] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
@@ -298,7 +322,12 @@ in let configured-src = stdenv.mkDerivation (rec {
298322
for i in "$out/bin/"*; do
299323
test ! -h $i || continue
300324
egrep --quiet '^#!' <(head -n 1 $i) || continue
301-
sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
325+
# The ghcprog fixup is for musl (where runhaskell script just needs to point to the correct
326+
# ghc program to work).
327+
sed -i \
328+
-e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' \
329+
-e 's/ghcprog="ghc-/ghcprog="${targetPrefix}ghc-/' \
330+
$i
302331
done
303332
'' + installDeps targetPrefix;
304333

docs/dev/pkg-map.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ nixpkgs.overlays = [
2828
];
2929
```
3030

31-
### Haskell component/package configuration
32-
33-
This is not implemented yet, tracked by issue
34-
[#198](https://github.com/input-output-hk/haskell.nix/issues/198).
35-
3631
### Mapping in Haskell.nix
3732

3833
Alternatively, if the name is commonly used, an alias can be added to

hackage-src.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "https://github.com/input-output-hk/hackage.nix",
3-
"rev": "d589a07318584bf4d8ff4b46711a9ef4dbade3c1",
4-
"date": "2020-02-18T01:11:02+00:00",
5-
"sha256": "1c5np00nm8rdh8yvl643fly5mk1a26g7f722z2jkny91kbwb98l7",
3+
"rev": "18646b3296a596d712c4af6dd2b04de0e947cbbe",
4+
"date": "2020-03-04T01:10:41+00:00",
5+
"sha256": "11wlnjb4lcrnf4zkswincdbw41lry2gr3hmzb93pqdnv335vyfzx",
66
"fetchSubmodules": false
77
}

lib/default.nix

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,18 @@ with haskellLib;
151151
# to: tests.mypackage.unit-tests
152152
#
153153
collectComponents = group: packageSel: haskellPackages:
154-
(lib.mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; })
155-
(lib.filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages))
156-
// { recurseForDerivations = true; };
154+
let packageToComponents = name: package:
155+
# look for the components with this group if there are any
156+
let components = package.components.${group} or {};
157+
# set recurseForDerivations unless it's a derivation itself (e.g. the "library" component) or an empty set
158+
in if lib.isDerivation components || components == {}
159+
then components
160+
else pkgs.recurseIntoAttrs components;
161+
packageFilter = name: package: (package.isHaskell or false) && packageSel package;
162+
filteredPkgs = lib.filterAttrs packageFilter haskellPackages;
163+
# at this point we can filter out packages that don't have any of the given kind of component
164+
packagesByComponent = lib.filterAttrs (_: components: components != {}) (lib.mapAttrs packageToComponents filteredPkgs);
165+
in pkgs.recurseIntoAttrs packagesByComponent;
157166

158167
# Equivalent to collectComponents with (_: true) as selection function.
159168
# Useful for pre-filtered package-set.
@@ -180,4 +189,15 @@ with haskellLib;
180189
check = import ./check.nix {
181190
inherit stdenv lib haskellLib srcOnly;
182191
};
192+
193+
# Use `isCrossHost` to identify when we are cross compiling and
194+
# the code we are producing will not run on the build system
195+
# without an emulator.
196+
# In most cases we do not want to treat musl as a cross compiler.
197+
# For instance when building ghc we want to include ghci.
198+
isCrossHost = stdenv.hostPlatform != stdenv.buildPlatform
199+
&& !(stdenv.buildPlatform.isLinux && stdenv.hostPlatform.isMusl);
200+
# This is the same as isCrossHost but for use when building ghc itself
201+
isCrossTarget = stdenv.targetPlatform != stdenv.hostPlatform
202+
&& !(stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl);
183203
}

0 commit comments

Comments
 (0)