on iko/ghcjs-patch-master help sign in
Add ghcOptions on packages (#257)
147cf21Hamish Mackenzie
builder/comp-builder.nix+4−2
@@ -88,6 +88,8 @@ let
88 ++ component.configureFlags
88 ++ component.configureFlags
89 );
89 );
90
90
91+ setupGhcOptions = lib.optional (package.ghcOptions != null) '' --ghc-options="${package.ghcOptions}"'';
92+
91 executableToolDepends =
93 executableToolDepends =
92 (lib.concatMap (c: if c.isHaskell or false
94 (lib.concatMap (c: if c.isHaskell or false
93 then builtins.attrValues (c.components.exes or {})
95 then builtins.attrValues (c.components.exes or {})
@@ -190,7 +192,7 @@ stdenv.mkDerivation ({
190 buildPhase = ''
192 buildPhase = ''
191 runHook preBuild
193 runHook preBuild
192 # https://gitlab.haskell.org/ghc/ghc/issues/9221
194 # https://gitlab.haskell.org/ghc/ghc/issues/9221
193− $SETUP_HS build -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " component.setupBuildFlags}
195+ $SETUP_HS build -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (component.setupBuildFlags ++ setupGhcOptions)}
194 runHook postBuild
196 runHook postBuild
195 '';
197 '';
196
198
@@ -211,7 +213,7 @@ stdenv.mkDerivation ({
211 "--html" \
213 "--html" \
212 ${lib.optionalString doHoogle "--hoogle"} \
214 ${lib.optionalString doHoogle "--hoogle"} \
213 ${lib.optionalString hyperlinkSource "--hyperlink-source"} \
215 ${lib.optionalString hyperlinkSource "--hyperlink-source"} \
214− ${lib.concatStringsSep " " component.setupHaddockFlags}
216+ ${lib.concatStringsSep " " (component.setupHaddockFlags ++ setupGhcOptions)}
215
217
216 html="dist/doc/html/${componentId.cname}"
218 html="dist/doc/html/${componentId.cname}"
217
219
docs/user-guide/projects.md+2
@@ -27,6 +27,7 @@ let
27 modules = [
27 modules = [
28 # specific package overrides would go here
28 # specific package overrides would go here
29 # example:
29 # example:
30+ # packages.cbors.package.ghcOptions = "-Werror";
30 # packages.cbors.patches = [ ./one.patch ];
31 # packages.cbors.patches = [ ./one.patch ];
31 # packages.cbors.flags.optimize-gmp = false;
32 # packages.cbors.flags.optimize-gmp = false;
32 # It may be better to set flags in stack.yaml instead (overrides will
33 # It may be better to set flags in stack.yaml instead (overrides will
@@ -41,6 +42,7 @@ let
41 modules = [
42 modules = [
42 # specific package overrides would go here
43 # specific package overrides would go here
43 # example:
44 # example:
45+ # packages.cbors.package.ghcOptions = "-Werror";
44 # packages.cbors.patches = [ ./one.patch ];
46 # packages.cbors.patches = [ ./one.patch ];
45 # To override a flag you will need to use mkOverride to make
47 # To override a flag you will need to use mkOverride to make
46 # it clear that you wish to replace the value found in the
48 # it clear that you wish to replace the value found in the
modules/package.nix+5
@@ -131,6 +131,11 @@ in {
131 type = bool;
131 type = bool;
132 default = false;
132 default = false;
133 };
133 };
134+
135+ ghcOptions = mkOption {
136+ type = nullOr str;
137+ default = null;
138+ };
134 };
139 };
135
140
136 components = let
141 components = let
nix-tools/nix-tools-src.json+3−3
@@ -1,7 +1,7 @@
1{
1{
2 "url": "https://github.com/input-output-hk/nix-tools",
2 "url": "https://github.com/input-output-hk/nix-tools",
3− "rev": "5d4649a833cb8b963266cea016d5a12a30022266",
3+ "rev": "87d97c50a53e421ed016d4c9a1dc41f9e6edda53",
4− "date": "2019-10-11T14:24:33+13:00",
4+ "date": "2019-10-12T14:56:33+08:00",
5− "sha256": "1xf3llli08axrhhda80hx95nmbwmdcz0y4r2vmgfhi3lqbcww8vk",
5+ "sha256": "1zvk13haiiyb6mcmypjn20i6vcx98y8zp5ipj0vpbflpg7f6rldm",
6 "fetchSubmodules": false
6 "fetchSubmodules": false
7}
7}
test/default.nix+2
@@ -24,6 +24,8 @@ in pkgs.recurseIntoAttrs {
24 buildable = haskell.callPackage ./buildable {};
24 buildable = haskell.callPackage ./buildable {};
25 project-flags-cabal = haskell.callPackage ./project-flags/cabal.nix {};
25 project-flags-cabal = haskell.callPackage ./project-flags/cabal.nix {};
26 project-flags-stack = haskell.callPackage ./project-flags/stack.nix {};
26 project-flags-stack = haskell.callPackage ./project-flags/stack.nix {};
27+ ghc-options-cabal = haskell.callPackage ./ghc-options/cabal.nix {};
28+ ghc-options-stack = haskell.callPackage ./ghc-options/stack.nix {};
27
29
28 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
30 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
29 # An empty list means success.
31 # An empty list means success.
test/ghc-options/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+.stack-work/
2+*~
test/ghc-options/Setup.hsnew file+2
@@ -0,0 +1,2 @@
1+import Distribution.Simple
2+main = defaultMain
test/ghc-options/app/Main.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE CPP #-}
2+module Main where
3+
4+import Lib
5+
6+#ifdef TEST_GHC_OPTION
7+main :: IO ()
8+main = someFunc
9+#endif
test/ghc-options/cabal.nixnew file+36
@@ -0,0 +1,36 @@
1+{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix, importAndFilterProject }:
2+
3+with stdenv.lib;
4+
5+let
6+ plan = (importAndFilterProject (callCabalProjectToNix {
7+ index-state = "2019-04-30T00:00:00Z";
8+ src = ./.;
9+ }));
10+ pkgSet = mkCabalProjectPkgSet {
11+ plan-pkgs = plan.pkgs;
12+ # TODO find a way to get the ghc-options into plan.json so we can use it in plan-to-nix
13+ modules = [ { packages.test-ghc-options.package.ghcOptions = "-DTEST_GHC_OPTION"; } ];
14+ };
15+ packages = pkgSet.config.hsPkgs;
16+in
17+ stdenv.mkDerivation {
18+ name = "call-cabal-project-to-nix-test";
19+
20+ buildCommand = ''
21+ exe="${packages.test-ghc-options.components.exes.test-ghc-options-exe}/bin/test-ghc-options-exe"
22+
23+ printf "checking whether executable runs... " >& 2
24+ $exe
25+
26+ touch $out
27+ '';
28+
29+ meta.platforms = platforms.all;
30+
31+ passthru = {
32+ # Attributes used for debugging with nix repl
33+ inherit pkgSet packages;
34+ plan-nix = plan.nix;
35+ };
36+ }
test/ghc-options/cabal.projectnew file+4
@@ -0,0 +1,4 @@
1+packages: .
2+
3+package test-ghc-options
4+ ghc-options: -DTEST_GHC_OPTION
test/ghc-options/src/Lib.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE CPP #-}
2+module Lib
3+ ( someFunc
4+ ) where
5+
6+#ifdef TEST_GHC_OPTION
7+someFunc :: IO ()
8+someFunc = putStrLn "someFunc"
9+#endif
test/ghc-options/stack.nixnew file+33
@@ -0,0 +1,33 @@
1+{ stdenv, mkStackPkgSet, callStackToNix, importAndFilterProject }:
2+
3+with stdenv.lib;
4+
5+let
6+ stack = (importAndFilterProject (callStackToNix {
7+ src = ./.;
8+ }));
9+ pkgSet = mkStackPkgSet {
10+ stack-pkgs = stack.pkgs;
11+ };
12+ packages = pkgSet.config.hsPkgs;
13+in
14+ stdenv.mkDerivation {
15+ name = "callStackToNix-test";
16+
17+ buildCommand = ''
18+ exe="${packages.test-ghc-options.components.exes.test-ghc-options-exe}/bin/test-ghc-options-exe"
19+
20+ printf "checking whether executable runs... " >& 2
21+ $exe
22+
23+ touch $out
24+ '';
25+
26+ meta.platforms = platforms.all;
27+
28+ passthru = {
29+ # Attributes used for debugging with nix repl
30+ inherit pkgSet packages;
31+ stack-nix = stack.nix;
32+ };
33+ }
test/ghc-options/stack.yamlnew file+7
@@ -0,0 +1,7 @@
1+resolver: lts-13.19
2+
3+packages:
4+- .
5+
6+ghc-options:
7+ test-ghc-options: -DTEST_GHC_OPTION
test/ghc-options/test-ghc-options.cabalnew file+20
@@ -0,0 +1,20 @@
1+cabal-version: >=1.10
2+name: test-ghc-options
3+version: 0.1.0.0
4+license: PublicDomain
5+author: Hamish Mackenzie
6+maintainer: Hamish.Mackenzie@iohk.io
7+build-type: Simple
8+
9+library
10+ build-depends: base >=4.7 && <5
11+ exposed-modules: Lib
12+ hs-source-dirs: src
13+ default-language: Haskell2010
14+
15+executable test-ghc-options-exe
16+ main-is: Main.hs
17+ build-depends: base >=4.7 && <5, test-ghc-options
18+ hs-source-dirs: app
19+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
20+ default-language: Haskell2010