Skip to content

Commit 9392cb0

Browse files
authored
Cabal fix for ghc-options -fplugin in ghc >=9.6.3 (#2101)
* Cabal fix for ghc-options -fplugin in ghc >=9.6.3 Include haskell/cabal#9384 to fix #2096 * Add test * Patch does not work for GHC head and should not be needed soon * Disable broken test * ifdLevel 1 * ifdLevel 2 * ifdLevel 3 * ifdLevel 1 * ifdLevel 2 * ifdLevel 3 * Disable test for ghc that polysemy does not support * More cases where plugin test is broken * More cases where plugin test is broken * Add missing haskellLib arg
1 parent 52a99ff commit 9392cb0

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed

overlays/bootstrap.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ in {
241241
++ final.lib.optionals (final.stdenv.targetPlatform.isGhcjs) (fromUntil "9.6.1" "9.6.3" ./patches/ghc/ghc-9.6-JS-implement-TH-support.patch)
242242
++ final.lib.optionals (final.stdenv.targetPlatform.isGhcjs) (fromUntil "9.6.3" "9.8" ./patches/ghc/ghc-9.6.3-JS-implement-TH-support.patch)
243243
++ fromUntil "9.8.1" "9.8.2" ./patches/ghc/ghc-9.8-cabal-c-soures-fix.patch
244+
++ fromUntil "9.6.3" "9.9" ./patches/ghc/ghc-9.6.3-Cabal-9384.patch
244245

245246
# the following is a partial reversal of https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4391, to address haskell.nix#1227
246247
++ final.lib.optional (versionAtLeast "8.10.6" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/mmap-next.patch
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
2+
index 9d653f858..1fbd15318 100644
3+
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
4+
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
5+
@@ -1861,18 +1861,12 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
6+
libBi = libBuildInfo lib
7+
comp = compiler lbi
8+
platform = hostPlatform lbi
9+
- vanillaArgs0 =
10+
+ vanillaArgs =
11+
(componentGhcOptions verbosity lbi libBi clbi (componentBuildDir lbi clbi))
12+
`mappend` mempty {
13+
ghcOptMode = toFlag GhcModeAbiHash,
14+
ghcOptInputModules = toNubListR $ exposedModules lib
15+
}
16+
- vanillaArgs =
17+
- -- Package DBs unnecessary, and break ghc-cabal. See #3633
18+
- -- BUT, put at least the global database so that 7.4 doesn't
19+
- -- break.
20+
- vanillaArgs0 { ghcOptPackageDBs = [GlobalPackageDB]
21+
- , ghcOptPackages = mempty }
22+
sharedArgs = vanillaArgs `mappend` mempty {
23+
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
24+
ghcOptFPic = toFlag True,
25+
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
26+
index c8721746a..dcd5b3230 100644
27+
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
28+
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
29+
@@ -1573,18 +1573,12 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
30+
libBi = libBuildInfo lib
31+
comp = compiler lbi
32+
platform = hostPlatform lbi
33+
- vanillaArgs0 =
34+
+ vanillaArgs =
35+
(componentGhcOptions verbosity lbi libBi clbi (componentBuildDir lbi clbi))
36+
`mappend` mempty {
37+
ghcOptMode = toFlag GhcModeAbiHash,
38+
ghcOptInputModules = toNubListR $ exposedModules lib
39+
}
40+
- vanillaArgs =
41+
- -- Package DBs unnecessary, and break ghc-cabal. See #3633
42+
- -- BUT, put at least the global database so that 7.4 doesn't
43+
- -- break.
44+
- vanillaArgs0 { ghcOptPackageDBs = [GlobalPackageDB]
45+
- , ghcOptPackages = mempty }
46+
sharedArgs = vanillaArgs `mappend` mempty {
47+
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
48+
ghcOptFPic = toFlag True,

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ let
218218
ca-derivations-include = callTest ./ca-derivations-include { inherit CADerivationsEnabled; };
219219
test-only = callTest ./test-only { inherit util; };
220220
cabal-project-nix-path = callTest ./cabal-project-nix-path {};
221+
plugin = callTest ./plugin {};
221222
unit = unitTests;
222223
};
223224

test/plugin/default.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{ stdenv, lib, haskellLib, project', recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages, buildPackages }:
2+
3+
with lib;
4+
5+
let
6+
project = project' {
7+
inherit compiler-nix-name evalPackages;
8+
src = testSrc "plugin";
9+
};
10+
11+
packages = project.hsPkgs;
12+
13+
in recurseIntoAttrs {
14+
ifdInputs = {
15+
inherit (project) plan-nix;
16+
};
17+
18+
# Not sure why this breaks for ghc 8.10.7
19+
meta.disabled = compiler-nix-name == "ghc8107"
20+
# TODO remove once polysemy works with ghc 9.8.1
21+
|| __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.8.1" >= 0
22+
|| stdenv.hostPlatform.isMusl
23+
|| stdenv.hostPlatform.isGhcjs
24+
|| stdenv.hostPlatform.isWindows
25+
|| (haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64);
26+
build = packages.test.components.library;
27+
}

test/plugin/src/MyLib.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLib (someFunc) where
2+
3+
someFunc :: IO ()
4+
someFunc = putStrLn "someFunc"

test/plugin/test.cabal

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cabal-version: 3.4
2+
name: test
3+
version: 0.1.0.0
4+
build-type: Simple
5+
6+
library
7+
exposed-modules: MyLib
8+
build-depends: base, polysemy, polysemy-plugin
9+
ghc-options: -Wall -fplugin=Polysemy.Plugin
10+
hs-source-dirs: src
11+
default-language: Haskell2010

0 commit comments

Comments
 (0)