on iko/ghcjs-patch-master help sign in
Move envDeps and exactDeps into lib and ghc (#360)
300fff4Hamish Mackenzie
builder/comp-builder.nix+25−1
@@ -259,7 +259,9 @@ stdenv.mkDerivation ({
259 #
259 #
260 # Note 3: if a package has no libs SETUP will not generate anything. This can
260 # Note 3: if a package has no libs SETUP will not generate anything. This can
261 # happen when building the `all` component of a package.
261 # happen when building the `all` component of a package.
262− installPhase = ''
262+ installPhase = let
263+ target-pkg-and-db = "${ghc.targetPrefix}ghc-pkg -v0 --package-db $out/package.conf.d";
264+ in ''
263 runHook preInstall
265 runHook preInstall
264 $SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
266 $SETUP_HS copy ${lib.concatStringsSep " " component.setupInstallFlags}
265 ${lib.optionalString (haskellLib.isLibrary componentId || haskellLib.isAll componentId) ''
267 ${lib.optionalString (haskellLib.isLibrary componentId || haskellLib.isAll componentId) ''
@@ -272,6 +274,28 @@ stdenv.mkDerivation ({
272 elif [ -e "${name}.conf" ]; then
274 elif [ -e "${name}.conf" ]; then
273 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
275 ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
274 fi
276 fi
277+
278+ mkdir -p $out/exactDep
279+ touch $out/exactDep/configure-flags
280+ touch $out/exactDep/cabal.config
281+
282+ if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
283+ echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
284+ elif id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
285+ name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
286+ # so we are dealing with a sublib. As we build sublibs separately, the above
287+ # query should be safe.
288+ echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
289+ fi
290+ if ver=$(${target-pkg-and-db} field ${package.identifier.name} version --simple-output); then
291+ echo "constraint: ${package.identifier.name} == $ver" >> $out/exactDep/cabal.config
292+ echo "constraint: ${package.identifier.name} installed" >> $out/exactDep/cabal.config
293+ fi
294+
295+ touch $out/envDep
296+ if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
297+ echo "package-id $id" >> $out/envDep
298+ fi
275 ''}
299 ''}
276 ${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) ''
300 ${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) ''
277 mkdir -p $out/bin
301 mkdir -p $out/bin
builder/make-config-files.nix+30−43
@@ -9,12 +9,17 @@ let
9 target-pkg = "${ghc.targetPrefix}ghc-pkg";
9 target-pkg = "${ghc.targetPrefix}ghc-pkg";
10
10
11 # This is a bit of a hack. So we'll have a slightly longer explaination here:
11 # This is a bit of a hack. So we'll have a slightly longer explaination here:
12+
13+ # Every library component built with `comp-builder.nix` includes an `exactDep`
14+ # and `envDep` directory with precomputed values used here.
15+ # GHC derivations include `exactDep` and `envDep` derivations that have
16+ # the same information for each of the built in packages.
17+
12 # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command.
18 # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command.
13 # This requires us to pass --dependency={dep name}={pkg id}. The dependency
19 # This requires us to pass --dependency={dep name}={pkg id}. The dependency
14− # name will usually be the name of the package `p`, which we can locate in the
20+ # name will usually be the name of the package `p`, that will have been located
15− # package-db, passed in via `pdbArg`. Thus querying the package-db for the
21+ # in the suitable package db when the dependency (along with `exactDep` and `envDep`)
16− # id field for package `p`, will unsually provide is with the right value. Sublibs
17− # need a bit of special handling:
22+ # was built. Sublibs need a bit of special handling:
18 #
23 #
19 # - Sublibs: if the dependency is a sublibrary of a package, we need to use
24 # - Sublibs: if the dependency is a sublibrary of a package, we need to use
20 # the sublibrary's name for the dep name, and lookup the sublibraries
25 # the sublibrary's name for the dep name, and lookup the sublibraries
@@ -22,52 +27,33 @@ let
22 # sublib name to exactDep, as we don't have access to it at the call-site,
27 # sublib name to exactDep, as we don't have access to it at the call-site,
23 # we resort to a bit of globbing, which (as pkg db's should contain only
28 # we resort to a bit of globbing, which (as pkg db's should contain only
24 # a single package) work.
29 # a single package) work.
25− exactDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-exactdep" { inherit nativeBuildInputs; } ''
26− mkdir -p $out
27− touch $out/configure-flags
28− touch $out/cabal.config
29−
30− if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
31− echo "--dependency=${p}=$id" >> $out/configure-flags
32− elif id=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" id --simple-output); then
33− name=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" name --simple-output)
34− # so we are dealing with a sublib. As we build sublibs separately, the above
35− # query should be safe.
36− echo "--dependency=''${name#z-${p}-z-}=$id" >> $out/configure-flags
37− fi
38− if ver=$(${target-pkg} ${pdbArg} field ${p} version --simple-output); then
39− echo "constraint: ${p} == $ver" >> $out/cabal.config
40− echo "constraint: ${p} installed" >> $out/cabal.config
41− fi
42− '';
43
30
44− catExactDep = dep: ''
31+ getLibComponent = dep:
32+ dep.components.library # Regular package dependency
33+ or dep; # or a sublib
34+
35+ catPkgExactDep = p: ''
45− cat ${dep}/configure-flags >> $out/configure-flags
36+ cat ${getLibComponent p}/exactDep/configure-flags >> $out/configure-flags
46− cat ${dep}/cabal.config >> $out/cabal.config
37+ cat ${getLibComponent p}/exactDep/cabal.config >> $out/cabal.config
47 '';
38 '';
48
39
49− catPkgExactDep = p:
50− catExactDep (exactDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
51−
52− catGhcPkgExactDep = p: catExactDep (exactDep "" p [ghc]);
40+ catGhcPkgExactDep = p: ''
53−
41+ if [ -e ${ghc.exactDeps}/${p} ]; then
54− envDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-envdep" { inherit nativeBuildInputs; } ''
42+ cat ${ghc.exactDeps}/${p}/configure-flags >> $out/configure-flags
55− touch $out
43+ cat ${ghc.exactDeps}/${p}/cabal.config >> $out/cabal.config
56− if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then
57− echo "package-id $id" >> $out
58 fi
44 fi
59 '';
45 '';
60
46
61− catEnvDep = ghcEnv: ''
47+ catPkgEnvDep = p: ''
62− cat ${ghcEnv} >> $out/ghc-environment
48+ cat ${getLibComponent p}/envDep >> $out/ghc-environment
63 '';
49 '';
64
50
65− catPkgEnvDep = p:
66− catEnvDep (envDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]);
67−
68− catGhcPkgEnvDep = p: catEnvDep (envDep "" p [ghc]);
51+ catGhcPkgEnvDep = p: ''
52+ if [ -e ${ghc.envDeps}/${p} ]; then
53+ cat ${ghc.envDeps}/${p} >> $out/ghc-environment
54+ fi
55+ '';
69
56
70− packageDb = p: "--package-db ${p.components.library or p}/package.conf.d";
71in { identifier, component, fullName, flags ? {} }:
57in { identifier, component, fullName, flags ? {} }:
72 runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
58 runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
73 mkdir -p $out
59 mkdir -p $out
@@ -86,8 +72,9 @@ in { identifier, component, fullName, flags ? {} }:
86 '') nonReinstallablePkgs}
72 '') nonReinstallablePkgs}
87
73
88 ${lib.concatMapStringsSep "\n" (p: ''
74 ${lib.concatMapStringsSep "\n" (p: ''
89− cp -f "${p}/package.conf.d/"*.conf $out/package.conf.d
75+ cp -f "${(getLibComponent p).configFiles}/package.conf.d/"*.conf $out/package.conf.d
90− '') (haskellLib.flatLibDepends component)}
76+ cp -f "${getLibComponent p}/package.conf.d/"*.conf $out/package.conf.d
77+ '') component.depends}
91
78
92 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
79 # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
93 ${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
80 ${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
compiler/ghc/default.nix+10−2
@@ -13,6 +13,8 @@
13
13
14, libiconv ? null, ncurses
14, libiconv ? null, ncurses
15
15
16+, exactDeps, envDeps
17+
16, # GHC can be built with system libffi or a bundled one.
18, # GHC can be built with system libffi or a bundled one.
17 libffi ? null
19 libffi ? null
18
20
@@ -204,7 +206,7 @@ in let configured-src = stdenv.mkDerivation (rec {
204 installPhase = "cp -r . $out";
206 installPhase = "cp -r . $out";
205 });
207 });
206
208
207−in stdenv.mkDerivation (rec {
209+ drv =stdenv.mkDerivation (rec {
208 version = ghc-version;
210 version = ghc-version;
209 name = "${targetPrefix}ghc-${version}";
211 name = "${targetPrefix}ghc-${version}";
210
212
@@ -313,6 +315,10 @@ in stdenv.mkDerivation (rec {
313
315
314 # Used to detect non haskell-nix compilers (accedental use of nixpkgs compilers can lead to unexpected errors)
316 # Used to detect non haskell-nix compilers (accedental use of nixpkgs compilers can lead to unexpected errors)
315 isHaskellNixCompiler = true;
317 isHaskellNixCompiler = true;
318+
319+ # These are used in make-config-files.nix
320+ exactDeps = exactDeps drv;
321+ envDeps = envDeps drv;
316 } // extra-passthru;
322 } // extra-passthru;
317
323
318 meta = {
324 meta = {
@@ -326,4 +332,6 @@ in stdenv.mkDerivation (rec {
326 dontStrip = true;
332 dontStrip = true;
327 dontPatchELF = true;
333 dontPatchELF = true;
328 noAuditTmpdir = true;
334 noAuditTmpdir = true;
329−})
335+});
336+
337+in drv
overlays/bootstrap.nix+46−8
@@ -1,4 +1,36 @@
1−self: super: {
1+self: super:
2+let
3+ exactDeps = ghc: self.runCommand "ghc-exactdep-${ghc.version}" { nativeBuildInputs = [ ghc ]; } ''
4+ for P in $(${ghc.targetPrefix}ghc-pkg list --simple-output | sed 's/-[0-9][0-9.]*//g'); do
5+ mkdir -p $out/$P
6+ touch $out/$P/configure-flags
7+ touch $out/$P/cabal.config
8+
9+ if id=$(${ghc.targetPrefix}ghc-pkg field $P id --simple-output); then
10+ echo "--dependency=$P=$id" >> $out/$P/configure-flags
11+ elif id=$(${ghc.targetPrefix}ghc-pkg field "z-$P-z-*" id --simple-output); then
12+ name=$(${ghc.targetPrefix}ghc-pkg field "z-$P-z-*" name --simple-output)
13+ # so we are dealing with a sublib. As we build sublibs separately, the above
14+ # query should be safe.
15+ echo "--dependency=''${name#z-$P-z-}=$id" >> $out/$P/configure-flags
16+ fi
17+ if ver=$(${ghc.targetPrefix}ghc-pkg field $P version --simple-output); then
18+ echo "constraint: $P == $ver" >> $out/$P/cabal.config
19+ echo "constraint: $P installed" >> $out/$P/cabal.config
20+ fi
21+ done
22+ '';
23+
24+ envDeps = ghc: self.runCommand "ghc-envdep-${ghc.version}" { nativeBuildInputs = [ ghc ]; } ''
25+ mkdir -p $out
26+ for P in $(${ghc.targetPrefix}ghc-pkg list --simple-output | sed 's/-[0-9.]*//g'); do
27+ touch $out/$P
28+ if id=$(${ghc.targetPrefix}ghc-pkg field $P id --simple-output); then
29+ echo "package-id $id" >> $out/$P
30+ fi
31+ done
32+ '';
33+in {
2 haskell-nix = super.haskell-nix // {
34 haskell-nix = super.haskell-nix // {
3 # Use this to disable the existing haskell infra structure for testing purposes
35 # Use this to disable the existing haskell infra structure for testing purposes
4 compiler =
36 compiler =
@@ -73,7 +105,7 @@ self: super: {
73 ghc844 = self.callPackage ../compiler/ghc {
105 ghc844 = self.callPackage ../compiler/ghc {
74 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc844; };
106 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc844; };
75
107
76− inherit bootPkgs sphinx;
108+ inherit bootPkgs sphinx exactDeps envDeps;
77
109
78 buildLlvmPackages = self.buildPackages.llvmPackages_5;
110 buildLlvmPackages = self.buildPackages.llvmPackages_5;
79 llvmPackages = self.llvmPackages_5;
111 llvmPackages = self.llvmPackages_5;
@@ -91,7 +123,7 @@ self: super: {
91 ghc861 = self.callPackage ../compiler/ghc {
123 ghc861 = self.callPackage ../compiler/ghc {
92 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc861; };
124 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc861; };
93
125
94− inherit bootPkgs sphinx;
126+ inherit bootPkgs sphinx exactDeps envDeps;
95
127
96 buildLlvmPackages = self.buildPackages.llvmPackages_5;
128 buildLlvmPackages = self.buildPackages.llvmPackages_5;
97 llvmPackages = self.llvmPackages_5;
129 llvmPackages = self.llvmPackages_5;
@@ -107,7 +139,7 @@ self: super: {
107 ghc862 = self.callPackage ../compiler/ghc {
139 ghc862 = self.callPackage ../compiler/ghc {
108 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc862; };
140 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc862; };
109
141
110− inherit bootPkgs sphinx;
142+ inherit bootPkgs sphinx exactDeps envDeps;
111
143
112 buildLlvmPackages = self.buildPackages.llvmPackages_5;
144 buildLlvmPackages = self.buildPackages.llvmPackages_5;
113 llvmPackages = self.llvmPackages_5;
145 llvmPackages = self.llvmPackages_5;
@@ -124,7 +156,7 @@ self: super: {
124 ghc863 = self.callPackage ../compiler/ghc {
156 ghc863 = self.callPackage ../compiler/ghc {
125 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc863; };
157 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc863; };
126
158
127− inherit bootPkgs sphinx;
159+ inherit bootPkgs sphinx exactDeps envDeps;
128
160
129 buildLlvmPackages = self.buildPackages.llvmPackages_5;
161 buildLlvmPackages = self.buildPackages.llvmPackages_5;
130 llvmPackages = self.llvmPackages_5;
162 llvmPackages = self.llvmPackages_5;
@@ -141,7 +173,7 @@ self: super: {
141 ghc864 = self.callPackage ../compiler/ghc {
173 ghc864 = self.callPackage ../compiler/ghc {
142 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc864; };
174 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc864; };
143
175
144− inherit bootPkgs sphinx;
176+ inherit bootPkgs sphinx exactDeps envDeps;
145
177
146 buildLlvmPackages = self.buildPackages.llvmPackages_5;
178 buildLlvmPackages = self.buildPackages.llvmPackages_5;
147 llvmPackages = self.llvmPackages_5;
179 llvmPackages = self.llvmPackages_5;
@@ -158,7 +190,7 @@ self: super: {
158 ghc865 = self.callPackage ../compiler/ghc {
190 ghc865 = self.callPackage ../compiler/ghc {
159 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc865; };
191 extra-passthru = { buildGHC = self.buildPackages.haskell-nix.compiler.ghc865; };
160
192
161− inherit bootPkgs sphinx;
193+ inherit bootPkgs sphinx exactDeps envDeps;
162
194
163 buildLlvmPackages = self.buildPackages.llvmPackages_5;
195 buildLlvmPackages = self.buildPackages.llvmPackages_5;
164 llvmPackages = self.llvmPackages_5;
196 llvmPackages = self.llvmPackages_5;
@@ -231,7 +263,13 @@ self: super: {
231 # compilers into the same place where nix expects them.
263 # compilers into the same place where nix expects them.
232 # We mark these compilers as boot compilers to make sure they are only used
264 # We mark these compilers as boot compilers to make sure they are only used
233 # where a boot compiler is expected.
265 # where a boot compiler is expected.
266+ compiler = builtins.mapAttrs (_: v:
267+ v // {
234− compiler = builtins.mapAttrs (_: v: v // { isHaskellNixBootCompiler = true; })
268+ isHaskellNixBootCompiler = true;
269+ exactDeps = exactDeps v;
270+ envDeps = envDeps v;
271+ }
272+ )
235 (import ../compiler/old-ghc-nix { pkgs = self; });
273 (import ../compiler/old-ghc-nix { pkgs = self; });
236
274
237 packages = {
275 packages = {