Skip to content

Commit

Permalink
Cabal fix for ghc-options -fplugin in ghc >=9.6.3 (#2101)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hamishmack authored Nov 28, 2023
1 parent 52a99ff commit 9392cb0
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ in {
++ final.lib.optionals (final.stdenv.targetPlatform.isGhcjs) (fromUntil "9.6.1" "9.6.3" ./patches/ghc/ghc-9.6-JS-implement-TH-support.patch)
++ final.lib.optionals (final.stdenv.targetPlatform.isGhcjs) (fromUntil "9.6.3" "9.8" ./patches/ghc/ghc-9.6.3-JS-implement-TH-support.patch)
++ fromUntil "9.8.1" "9.8.2" ./patches/ghc/ghc-9.8-cabal-c-soures-fix.patch
++ fromUntil "9.6.3" "9.9" ./patches/ghc/ghc-9.6.3-Cabal-9384.patch

# the following is a partial reversal of https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4391, to address haskell.nix#1227
++ final.lib.optional (versionAtLeast "8.10.6" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/mmap-next.patch
Expand Down
48 changes: 48 additions & 0 deletions overlays/patches/ghc/ghc-9.6.3-Cabal-9384.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
index 9d653f858..1fbd15318 100644
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/GHC.hs
@@ -1861,18 +1861,12 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
libBi = libBuildInfo lib
comp = compiler lbi
platform = hostPlatform lbi
- vanillaArgs0 =
+ vanillaArgs =
(componentGhcOptions verbosity lbi libBi clbi (componentBuildDir lbi clbi))
`mappend` mempty {
ghcOptMode = toFlag GhcModeAbiHash,
ghcOptInputModules = toNubListR $ exposedModules lib
}
- vanillaArgs =
- -- Package DBs unnecessary, and break ghc-cabal. See #3633
- -- BUT, put at least the global database so that 7.4 doesn't
- -- break.
- vanillaArgs0 { ghcOptPackageDBs = [GlobalPackageDB]
- , ghcOptPackages = mempty }
sharedArgs = vanillaArgs `mappend` mempty {
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptFPic = toFlag True,
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
index c8721746a..dcd5b3230 100644
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/GHCJS.hs
@@ -1573,18 +1573,12 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
libBi = libBuildInfo lib
comp = compiler lbi
platform = hostPlatform lbi
- vanillaArgs0 =
+ vanillaArgs =
(componentGhcOptions verbosity lbi libBi clbi (componentBuildDir lbi clbi))
`mappend` mempty {
ghcOptMode = toFlag GhcModeAbiHash,
ghcOptInputModules = toNubListR $ exposedModules lib
}
- vanillaArgs =
- -- Package DBs unnecessary, and break ghc-cabal. See #3633
- -- BUT, put at least the global database so that 7.4 doesn't
- -- break.
- vanillaArgs0 { ghcOptPackageDBs = [GlobalPackageDB]
- , ghcOptPackages = mempty }
sharedArgs = vanillaArgs `mappend` mempty {
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptFPic = toFlag True,
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ let
ca-derivations-include = callTest ./ca-derivations-include { inherit CADerivationsEnabled; };
test-only = callTest ./test-only { inherit util; };
cabal-project-nix-path = callTest ./cabal-project-nix-path {};
plugin = callTest ./plugin {};
unit = unitTests;
};

Expand Down
27 changes: 27 additions & 0 deletions test/plugin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{ stdenv, lib, haskellLib, project', recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages, buildPackages }:

with lib;

let
project = project' {
inherit compiler-nix-name evalPackages;
src = testSrc "plugin";
};

packages = project.hsPkgs;

in recurseIntoAttrs {
ifdInputs = {
inherit (project) plan-nix;
};

# Not sure why this breaks for ghc 8.10.7
meta.disabled = compiler-nix-name == "ghc8107"
# TODO remove once polysemy works with ghc 9.8.1
|| __compareVersions buildPackages.haskell-nix.compiler.${compiler-nix-name}.version "9.8.1" >= 0
|| stdenv.hostPlatform.isMusl
|| stdenv.hostPlatform.isGhcjs
|| stdenv.hostPlatform.isWindows
|| (haskellLib.isCrossHost && stdenv.hostPlatform.isAarch64);
build = packages.test.components.library;
}
4 changes: 4 additions & 0 deletions test/plugin/src/MyLib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
11 changes: 11 additions & 0 deletions test/plugin/test.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cabal-version: 3.4
name: test
version: 0.1.0.0
build-type: Simple

library
exposed-modules: MyLib
build-depends: base, polysemy, polysemy-plugin
ghc-options: -Wall -fplugin=Polysemy.Plugin
hs-source-dirs: src
default-language: Haskell2010

0 comments on commit 9392cb0

Please sign in to comment.