on iko/ghcjs-patch-master help sign in
Add patches speeding up cabal build-tool-depends (#1200)

* Add patches speeding up cabal build-tool-depends * Add missing brackets and fix paths * Fix up patches for 3.4 * Fix missing file from patch * Add comments

commitf8a0b92bc3bfb86de00e87647db0f32c17206ab4 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateSat 14 Aug 2021, 12:05 (5 years ago) parented6d223
5 files changed+233−14
modules/configuration-nix.nix+23−1 overlays/ghcjs.nix−5 overlays/hackage-quirks.nix−8 overlays/patches/Cabal/Cabal-3.4-defer-build-tool-depends-7532.patch+63 overlays/patches/Cabal/Cabal-3.4-speedup-solver-when-tests-enabled-7490.patch+147
modules/configuration-nix.nix+23−1
@@ -3,7 +3,14 @@
33# package sets out of this repo. Ideally, this file is only used for
44# fixing things that are broken due to the Nix infrastructure.
55
6−{ pkgs, ... }: {
6+{ pkgs, ... }:
7+let
8+ fromUntil = from: until: patch: { version, revision }:
9+ if builtins.compareVersions version from >= 0
10+ && builtins.compareVersions version until < 0
11+ then patch
12+ else null;
13+in {
714 # terminfo doesn't list libtinfo in its cabal file. We could ignore
815 # this if we used the terminfo shipped with GHC, but this package is
916 # reinstallable so we'd rather have it defined in the plan.
@@ -26,4 +33,19 @@
2633 packages.hscolour.package.license = pkgs.lib.mkForce "LGPL-2.1-only";
2734 packages.cpphs.package.license = pkgs.lib.mkForce "LGPL-2.1-only";
2835 packages.polyparse.package.license = pkgs.lib.mkForce "LGPL-2.1-only";
36+
37+ # These two patches are needed by GHCJS
38+ packages.Cabal.patches = [
39+ (fromUntil "3.2.0.0" "3.5" ../overlays/patches/Cabal/Cabal-3.0.0.0-drop-pkg-db-check.diff)
40+ (fromUntil "3.2.0.0" "3.5" ../overlays/patches/Cabal/Cabal-3.0.0.0-no-final-checks.diff)
41+ ];
42+
43+ # These two patches are:
44+ # https://github.com/haskell/cabal/pull/7490
45+ # https://github.com/haskell/cabal/pull/7532
46+ # back poerted to cabal 3.4
47+ packages.cabal-install.patches = [
48+ (fromUntil "3.4.0.0" "3.5" ../overlays/patches/Cabal/Cabal-3.4-defer-build-tool-depends-7532.patch)
49+ (fromUntil "3.4.0.0" "3.5" ../overlays/patches/Cabal/Cabal-3.4-speedup-solver-when-tests-enabled-7490.patch)
50+ ];
2951}
overlays/ghcjs.nix−5
@@ -18,11 +18,6 @@ final: prev:
1818 "mtl" "parsec" "process" "text" "time" "transformers"
1919 "unix" "xhtml" "terminfo"
2020 ];
21− # Include patches for custom setups
22− packages.Cabal.patches = [
23− ./patches/Cabal/Cabal-3.0.0.0-drop-pkg-db-check.diff
24− ./patches/Cabal/Cabal-3.0.0.0-no-final-checks.diff
25− ];
2621 testWrapper = [((final.writeScriptBin "node-wrapper" ''
2722 set -euo pipefail
2823 exe=$1
overlays/hackage-quirks.nix−8
@@ -23,14 +23,6 @@ in { haskell-nix = prev.haskell-nix // {
2323 (lib.optionalAttrs (version == "3.2.0.0") {
2424 packages.cabal-install.src = final.haskell-nix.sources.cabal-32 + "/cabal-install";
2525 })
26− (lib.optionalAttrs (builtins.compareVersions version "3.0.0.0" >= 0
27− && builtins.compareVersions version "3.5" < 0) {
28− # Include patches needed for ghcjs
29− packages.Cabal.patches = [
30− ./patches/Cabal/Cabal-3.0.0.0-drop-pkg-db-check.diff
31− ./patches/Cabal/Cabal-3.0.0.0-no-final-checks.diff
32− ];
33− })
3426 ];
3527 };
3628
overlays/patches/Cabal/Cabal-3.4-defer-build-tool-depends-7532.patchnew file+63
@@ -0,0 +1,63 @@
1+From 3ac512e46f7b744597aaea12c7dfed95723b3665 Mon Sep 17 00:00:00 2001
2+From: Gershom Bazerman <gershom@arista.com>
3+Date: Wed, 11 Aug 2021 16:07:07 -0400
4+Subject: [PATCH] defer build-tools-depends choices as well as setup choices
5+
6+---
7+ .../Distribution/Solver/Modular/Preference.hs | 19 ++++++++++---------
8+ .../Distribution/Solver/Modular/Solver.hs | 2 +-
9+ 2 files changed, 11 insertions(+), 10 deletions(-)
10+
11+diff --git a/Distribution/Solver/Modular/Preference.hs b/Distribution/Solver/Modular/Preference.hs
12+index ed5adfbf8b2..35a43d4cf3b 100644
13+--- a/Distribution/Solver/Modular/Preference.hs
14++++ b/Distribution/Solver/Modular/Preference.hs
15+@@ -2,7 +2,7 @@
16+ -- | Reordering or pruning the tree in order to prefer or make certain choices.
17+ module Distribution.Solver.Modular.Preference
18+ ( avoidReinstalls
19+- , deferSetupChoices
20++ , deferSetupExeChoices
21+ , deferWeakFlagChoices
22+ , enforceManualFlags
23+ , enforcePackageConstraints
24+@@ -407,17 +407,18 @@ preferBaseGoalChoice = trav go
25+ isBase (Goal (P (Q _pp pn)) _) = unPN pn == "base"
26+ isBase _ = False
27+
28+--- | Deal with setup dependencies after regular dependencies, so that we can
29+--- will link setup dependencies against package dependencies when possible
30+-deferSetupChoices :: Tree d c -> Tree d c
31+-deferSetupChoices = trav go
32++-- | Deal with setup and build-tool-depends dependencies after regular dependencies,
33++-- so we will link setup/exe dependencies against package dependencies when possible
34++deferSetupExeChoices :: Tree d c -> Tree d c
35++deferSetupExeChoices = trav go
36+ where
37+- go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P.preferByKeys noSetup xs)
38++ go (GoalChoiceF rdm xs) = GoalChoiceF rdm (P.preferByKeys noSetupOrExe xs)
39+ go x = x
40+
41+- noSetup :: Goal QPN -> Bool
42+- noSetup (Goal (P (Q (PackagePath _ns (QualSetup _)) _)) _) = False
43+- noSetup _ = True
44++ noSetupOrExe :: Goal QPN -> Bool
45++ noSetupOrExe (Goal (P (Q (PackagePath _ns (QualSetup _)) _)) _) = False
46++ noSetupOrExe (Goal (P (Q (PackagePath _ns (QualExe _ _)) _)) _) = False
47++ noSetupOrExe _ = True
48+
49+ -- | Transformation that tries to avoid making weak flag choices early.
50+ -- Weak flags are trivial flags (not influencing dependencies) or such
51+diff --git a/Distribution/Solver/Modular/Solver.hs b/Distribution/Solver/Modular/Solver.hs
52+index 83c597cd9e6..fe4b6160e39 100644
53+--- a/Distribution/Solver/Modular/Solver.hs
54++++ b/Distribution/Solver/Modular/Solver.hs
55+@@ -117,7 +117,7 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
56+ sortGoals = case goalOrder sc of
57+ Nothing -> goalChoiceHeuristics .
58+ heuristicsTree .
59+- P.deferSetupChoices .
60++ P.deferSetupExeChoices .
61+ P.deferWeakFlagChoices .
62+ P.preferBaseGoalChoice
63+ Just order -> P.firstGoal .
overlays/patches/Cabal/Cabal-3.4-speedup-solver-when-tests-enabled-7490.patchnew file+147
@@ -0,0 +1,147 @@
1+From fa47bff82b0f0f0bda7ca7e01b15e5740b63f775 Mon Sep 17 00:00:00 2001
2+From: Gershom Bazerman <gershom@arista.com>
3+Date: Fri, 23 Jul 2021 11:24:42 -0400
4+Subject: [PATCH 1/4] attempt to speed solving when test is enable projectwide
5+
6+---
7+ .../Distribution/Solver/Modular/Preference.hs | 6 ++++--
8+ .../Distribution/Client/ProjectPlanning.hs | 13 ++++---------
9+ 2 files changed, 8 insertions(+), 11 deletions(-)
10+
11+diff --git a/Distribution/Solver/Modular/Preference.hs b/Distribution/Solver/Modular/Preference.hs
12+index d25ef846356..4275563006e 100644
13+--- a/Distribution/Solver/Modular/Preference.hs
14++++ b/Distribution/Solver/Modular/Preference.hs
15+@@ -127,11 +127,13 @@ preferPackagePreferences pcs =
16+
17+ -- | Traversal that tries to establish package stanza enable\/disable
18+ -- preferences. Works by reordering the branches of stanza choices.
19++-- Note that this works on packages lower in the path as well as at the top level,
20++-- as lower choices need to remain compatible with top level choices.
21+ preferPackageStanzaPreferences :: (PN -> PackagePreferences) -> Tree d c -> Tree d c
22+ preferPackageStanzaPreferences pcs = trav go
23+ where
24+- go (SChoiceF qsn@(SN (Q pp pn) s) rdm gr _tr ts)
25+- | primaryPP pp && enableStanzaPref pn s =
26++ go (SChoiceF qsn@(SN (Q _pp pn) s) rdm gr _tr ts)
27++ | enableStanzaPref pn s =
28+ -- move True case first to try enabling the stanza
29+ let ts' = W.mapWeightsWithKey (\k w -> weight k : w) ts
30+ weight k = if k then 0 else 1
31+diff --git a/Distribution/Client/ProjectPlanning.hs b/Distribution/Client/ProjectPlanning.hs
32+index 077c6422be4..18a4bf43a0d 100644
33+--- a/Distribution/Client/ProjectPlanning.hs
34++++ b/Distribution/Client/ProjectPlanning.hs
35+@@ -1024,14 +1024,9 @@ planPackages verbosity comp platform solver SolverSettings{..}
36+ | (pc, src) <- solverSettingConstraints ]
37+
38+ . addPreferences
39+- -- enable stanza preference where the user did not specify
40+- [ PackageStanzasPreference pkgname stanzas
41+- | pkg <- localPackages
42+- , let pkgname = pkgSpecifierTarget pkg
43+- stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable
44+- stanzas = [ stanza | stanza <- [minBound..maxBound]
45+- , Map.lookup stanza stanzaM == Nothing ]
46+- , not (null stanzas)
47++ -- enable stanza preference unilaterally, even when the user asked to enable as well, to help hint the solver.
48++ [ PackageStanzasPreference pkgname [minBound..maxBound]
49++ | pkgname <- map pkgSpecifierTarget localPackages
50+ ]
51+
52+ . addConstraints
53+From 624b8dc2069964de7c99cb7c9fa8c8674db797de Mon Sep 17 00:00:00 2001
54+From: Gershom Bazerman <gershom@arista.com>
55+Date: Tue, 3 Aug 2021 17:35:12 -0400
56+Subject: [PATCH 2/4] fix bug in preferences
57+
58+---
59+ cabal-install/Distribution/Client/ProjectPlanning.hs | 7 ++++++-
60+ 1 file changed, 6 insertions(+), 1 deletion(-)
61+
62+diff --git a/Distribution/Client/ProjectPlanning.hs b/Distribution/Client/ProjectPlanning.hs
63+index 18a4bf43a0d..42fe5be8f3d 100644
64+--- a/Distribution/Client/ProjectPlanning.hs
65++++ b/Distribution/Client/ProjectPlanning.hs
66+@@ -1026,7 +1026,12 @@ planPackages verbosity comp platform solver SolverSettings{..}
67+ . addPreferences
68+ -- enable stanza preference unilaterally, even when the user asked to enable as well, to help hint the solver.
69+ [ PackageStanzasPreference pkgname [minBound..maxBound]
70+- | pkgname <- map pkgSpecifierTarget localPackages
71++ | pkg <- localPackages
72++ , let pkgname = pkgSpecifierTarget pkg
73++ stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable
74++ stanzas = [ stanza | stanza <- [minBound..maxBound]
75++ , Map.lookup stanza stanzaM /= Just False ]
76++ , not (null stanzas)
77+ ]
78+
79+ . addConstraints
80+
81+From a5d04451d3d45bcfc8f679340f1dfd1e0e2993ed Mon Sep 17 00:00:00 2001
82+From: Gershom Bazerman <gershom@arista.com>
83+Date: Mon, 9 Aug 2021 18:17:49 -0400
84+Subject: [PATCH 3/4] fix bug
85+
86+---
87+ cabal-install/Distribution/Client/ProjectPlanning.hs | 2 +-
88+ 1 file changed, 1 insertion(+), 1 deletion(-)
89+
90+diff --git a/Distribution/Client/ProjectPlanning.hs b/Distribution/Client/ProjectPlanning.hs
91+index 42fe5be8f3d..3aefe9242f8 100644
92+--- a/Distribution/Client/ProjectPlanning.hs
93++++ b/Distribution/Client/ProjectPlanning.hs
94+@@ -1025,7 +1025,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
95+
96+ . addPreferences
97+ -- enable stanza preference unilaterally, even when the user asked to enable as well, to help hint the solver.
98+- [ PackageStanzasPreference pkgname [minBound..maxBound]
99++ [ PackageStanzasPreference pkgname stanzas
100+ | pkg <- localPackages
101+ , let pkgname = pkgSpecifierTarget pkg
102+ stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable
103+
104+From fdf3f7f0a633de79b4c8f1298eaf433cdf558250 Mon Sep 17 00:00:00 2001
105+From: Gershom Bazerman <gershom@arista.com>
106+Date: Wed, 11 Aug 2021 13:57:57 -0400
107+Subject: [PATCH 4/4] touchup comments
108+
109+---
110+ .../Distribution/Solver/Modular/Preference.hs | 9 +++++++--
111+ cabal-install/Distribution/Client/ProjectPlanning.hs | 3 ++-
112+ 2 files changed, 9 insertions(+), 3 deletions(-)
113+
114+diff --git a/Distribution/Solver/Modular/Preference.hs b/Distribution/Solver/Modular/Preference.hs
115+index 4275563006e..ed5adfbf8b2 100644
116+--- a/Distribution/Solver/Modular/Preference.hs
117++++ b/Distribution/Solver/Modular/Preference.hs
118+@@ -127,8 +127,13 @@ preferPackagePreferences pcs =
119+
120+ -- | Traversal that tries to establish package stanza enable\/disable
121+ -- preferences. Works by reordering the branches of stanza choices.
122+--- Note that this works on packages lower in the path as well as at the top level,
123+--- as lower choices need to remain compatible with top level choices.
124++-- Note that this works on packages lower in the path as well as at the top level.
125++-- This is because stanza preferences apply to local packages only
126++-- and for local packages, a single version is fixed, which means
127++-- (for now) that all stanza preferences must be uniform at all levels.
128++-- Further, even when we can have multiple versions of the same package,
129++-- the build plan will be more efficient if we can attempt to keep
130++-- stanza preferences aligned at all levels.
131+ preferPackageStanzaPreferences :: (PN -> PackagePreferences) -> Tree d c -> Tree d c
132+ preferPackageStanzaPreferences pcs = trav go
133+ where
134+diff --git a/Distribution/Client/ProjectPlanning.hs b/Distribution/Client/ProjectPlanning.hs
135+index 3aefe9242f8..fc6d9a17383 100644
136+--- a/Distribution/Client/ProjectPlanning.hs
137++++ b/Distribution/Client/ProjectPlanning.hs
138+@@ -1024,7 +1024,8 @@ planPackages verbosity comp platform solver SolverSettings{..}
139+ | (pc, src) <- solverSettingConstraints ]
140+
141+ . addPreferences
142+- -- enable stanza preference unilaterally, even when the user asked to enable as well, to help hint the solver.
143++ -- enable stanza preference unilaterally, regardless if the user asked
144++ -- accordingly or expressed no preference, to help hint the solver
145+ [ PackageStanzasPreference pkgname stanzas
146+ | pkg <- localPackages
147+ , let pkgname = pkgSpecifierTarget pkg