Skip to content

Commit b8b825d

Browse files
committed
Put the old default setup back for ghcjs
1 parent 02ce8ab commit b8b825d

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

builder/hspkg-builder.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ let
3535

3636
setup = if package.buildType == "Simple"
3737
then
38-
buildPackages.haskell-nix.nix-tools-unchecked.exes.cabal // { isCabal = true; }
38+
if stdenv.targetPlatform.isGhcjs
39+
# Don't try to build default setup with DWARF enabled
40+
let defaultSetup = ghc.defaultSetupFor package.identifier.name // {
41+
dwarf = defaultSetup;
42+
}; in defaultSetup
43+
else
44+
buildPackages.haskell-nix.nix-tools-unchecked.exes.cabal // { isCabal = true; }
3945
else setup-builder ({
4046
component = components.setup // {
4147
depends = config.setup-depends ++ components.setup.depends ++ package.setup-depends;

overlays/default-setup.nix

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# This overlay adds the two versions of the default setup
2+
# exe to the ghc derivations (one using the latest Cabal and
3+
# one using the GHC provided Cabal). These are then used
4+
# when a package has the `Simple` build type. Storing them
5+
# on the GHC derivation means that nix eval does not have
6+
# to compute the same derivation multiple times.
7+
final: prev:
8+
let
9+
nonReinstallablePkgs =
10+
if final.stdenv.targetPlatform.isGhcjs
11+
then ["base" "Cabal" "filepath" "directory"]
12+
else ["base" "Cabal"];
13+
haskellLib = final.haskell-nix.haskellLib;
14+
defaultSetupSrc =
15+
if final.stdenv.targetPlatform.isGhcjs
16+
then ../builder/Setup.ghcjs.hs
17+
else ../builder/Setup.hs;
18+
addDefaultSetup = compiler-nix-name: ghc:
19+
let
20+
# When building setup depends we need to use the build systems GHC and Packages
21+
makeSetupConfigFiles = haskellLib.weakCallPackage final.buildPackages ../builder/make-config-files.nix {
22+
inherit haskellLib nonReinstallablePkgs;
23+
ghc = (ghc.passthru.buildGHC or ghc);
24+
};
25+
setup-builder = haskellLib.weakCallPackage final ../builder/setup-builder.nix {
26+
ghc = (ghc.passthru.buildGHC or ghc);
27+
hsPkgs = {};
28+
# We need to use the buildPackages stdenv to build the setup-builder.
29+
# in the native case, it would be the same in the cross case however
30+
# we *really* want to build the Setup.hs on the build machine and not
31+
# have the stdenv confuse it with the target/host env.
32+
inherit (final.buildPackages) stdenv;
33+
inherit (final) buildPackages;
34+
inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
35+
};
36+
37+
# This is the `Cabal` library that was built for `cabal-install` to use.
38+
# It makes sense to use this version (when possible) because it will match the behavior of
39+
# building with `cabal-install` (including fixes that may not be in the
40+
# version of Cabal bundled with GHC).
41+
cabalFromCabalInstall = final.buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
42+
43+
in ghc // rec {
44+
defaultSetup = final.lib.mapAttrs (_: useCabalFromCabalInstall: setup-builder ({
45+
name = "${ghc.targetPrefix}default-Setup";
46+
component = {
47+
depends = final.lib.optional useCabalFromCabalInstall cabalFromCabalInstall;
48+
libs = [];
49+
frameworks = [];
50+
doExactConfig = false;
51+
includeDirs = [];
52+
asmSources = [];
53+
cSources = [];
54+
cmmSources = [];
55+
cxxSources = [];
56+
jsSources = [];
57+
extraSrcFiles = [ "Setup.hs" "Setup.lhs" ];
58+
pkgconfig = [];
59+
build-tools = [];
60+
61+
platforms = null;
62+
preUnpack = null; postUnpack = null;
63+
prePatch = null; postPatch = null;
64+
preBuild = null; postBuild = null;
65+
preInstall = null; postInstall = null;
66+
};
67+
package = {
68+
identifier = {
69+
name = "default-Setup";
70+
version = "1.0";
71+
};
72+
homepage = null;
73+
synopsis = null;
74+
license = "MIT";
75+
};
76+
src = null;
77+
cleanSrc = final.buildPackages.runCommand "default-Setup-src" {} ''
78+
mkdir $out
79+
cat ${defaultSetupSrc} > $out/Setup.hs
80+
'';
81+
inherit defaultSetupSrc;
82+
} // final.lib.optionalAttrs useCabalFromCabalInstall {
83+
# This is needed so that we don't get duplicate packages when we
84+
# add a custom Cabal package to the dependencies. That way custom
85+
# setups won't complain about e.g. binary from the Cabal dependencies
86+
# and binary from the global package-db.
87+
nonReinstallablePkgs = ["base"];
88+
})) {
89+
useCabalFromCabalInstall = true;
90+
useCabalFromGHC = false;
91+
};
92+
93+
# Check there is no chance we are building `cabalFromCabalInstall`. Using `cabalFromCabalInstall`
94+
# to build itself would cause infinite recursion.
95+
defaultSetupFor = packageName:
96+
if
97+
# Cabal that comes with GHC 9.6.3 is newer than cabal-install
98+
__compareVersions ghc.version "9.6.3" < 0
99+
&& (
100+
# `cabalFromCabalInstall` is not cross compiled
101+
final.stdenv.buildPlatform != final.stdenv.hostPlatform
102+
||
103+
# These are the dependencies of `Cabal`
104+
!builtins.elem packageName
105+
["alex" "happy" "hscolour" "Cabal" "Cabal-syntax" "bytestring" "time"
106+
"filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
107+
"containers" "binary" "mtl" "text" "process" "parsec" "stm" "exceptions"]
108+
)
109+
then defaultSetup.useCabalFromCabalInstall
110+
else defaultSetup.useCabalFromGHC;
111+
};
112+
in {
113+
haskell-nix = prev.haskell-nix // {
114+
compiler = final.lib.mapAttrs addDefaultSetup prev.haskell-nix.compiler;
115+
bootstrap = prev.haskell-nix.bootstrap // {
116+
compiler = final.lib.mapAttrs addDefaultSetup prev.haskell-nix.bootstrap.compiler;
117+
};
118+
};
119+
haskell = prev.haskell // {
120+
compiler = final.lib.mapAttrs addDefaultSetup prev.haskell.compiler;
121+
};
122+
}

overlays/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ let
8585
ghcjs = import ./ghcjs.nix;
8686
cabalPkgConfig = import ./cabal-pkg-config.nix;
8787
cacheCompilerDeps = import ./cache-compiler-deps.nix;
88+
default-setup = import ./default-setup.nix;
8889
dummy-ghc-data = import ./dummy-ghc-data.nix;
8990
fetch-source = import ./fetch-source.nix;
9091
};

0 commit comments

Comments
 (0)