summaryrefslogtreecommitdiffstats
path: root/pkgs/test/haskell/ghcWithPackages/default.nix
blob: aedcac0d2c917232dfda89d2797f221193ddfbf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
  lib,
  runCommand,
  runCommandCC,
  haskellPackages,
}:

lib.recurseIntoAttrs {
  # This is special-cased to return just `ghc`.
  trivial = haskellPackages.ghcWithPackages (hsPkgs: [ ]);

  # Here we actually build a trivial package.
  hello = haskellPackages.ghcWithPackages (hsPkgs: [
    hsPkgs.hello
  ]);

  # Here we build a database with multiple packages.
  multiple = haskellPackages.ghcWithPackages (hsPkgs: [
    hsPkgs.hspec
    hsPkgs.unordered-containers
  ]);

  # See: https://github.com/NixOS/nixpkgs/pull/224542
  regression-224542 =
    let
      ghc = haskellPackages.ghcWithPackages (hsPkgs: [
        hsPkgs.hspec
      ]);
    in
    runCommand "regression-224542"
      {
        nativeBuildInputs = [
          ghc
        ];
      }
      ''
        ${ghc.targetPrefix}ghc --interactive \
          -Werror=unrecognised-warning-flags \
          -Werror=missed-extra-shared-lib \
          2>&1 \
        | tee ghc-output.txt

        # If GHC failed to find a shared library, linking dylibs in
        # `ghcWithPackages` didn't work correctly.
        if grep --quiet "error: .*-Wmissed-extra-shared-lib" ghc-output.txt \
          && grep --quiet "no such file" ghc-output.txt; then
          exit 1
        fi

        touch $out
      '';

  use-llvm =
    let
      ghc = (haskellPackages.ghcWithPackages.override { useLLVM = true; }) (_: [ ]);
    in
    runCommandCC "ghc-with-packages-use-llvm"
      {
        nativeBuildInputs = [ ghc ];
      }
      ''
        echo 'main = pure ()' > test.hs
        # -ddump-llvm is unnecessary, but nice for visual feedback in the build log
        ${ghc.targetPrefix}ghc --make -fllvm -keep-llvm-files -ddump-llvm test.hs
        # Did we actually use the LLVM backend?
        test -f test.ll
        touch $out
      '';
}