Skip to content

Commit

Permalink
Better error message when building missing ghcjs (#1140)
Browse files Browse the repository at this point in the history
Currently if you try to build a ghcjs version that does not exist
haskell.nix falls back on the GHC version.  Once ghcjs is in the
ghc tree this will work, but for now we should have an error
message that is more descriptive than attempting and failing to
build ghc for a js target.

New error looks like this:

```
$ nix-build -A pkgs-unstable.pkgsCross.ghcjs.buildPackages.haskell-nix.compiler.ghc861
error: ghcjs 8.6.1 is no longer supported by haskell.nix. Consider using 8.6.5
```
  • Loading branch information
hamishmack committed Jun 16, 2021
1 parent f899936 commit 90184a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
50 changes: 16 additions & 34 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ let
};
traceWarnOld = v: x: __trace
"WARNING: ${x.src-spec.version} is out of date, consider using ${latestVer.${v}}." x;
errorOldGhcjs = v: up: throw "ghcjs ${v} is no longer supported by haskell.nix. Consider using ${latestVer.${up}}";
in {
haskell-nix = prev.haskell-nix // {
# Use this to disable the existing haskell infra structure for testing purposes
Expand Down Expand Up @@ -515,6 +516,21 @@ in {
isHaskellNixBootCompiler = true;
})
({
# Better error messages when an unsupported version of ghcjs is used
ghc844 = errorOldGhcjs "8.4.4" "8.6";
ghc861 = errorOldGhcjs "8.6.1" "8.6";
ghc862 = errorOldGhcjs "8.6.2" "8.6";
ghc863 = errorOldGhcjs "8.6.3" "8.6";
ghc864 = errorOldGhcjs "8.6.4" "8.6";
ghc881 = errorOldGhcjs "8.8.1" "8.8";
ghc882 = errorOldGhcjs "8.8.2" "8.8";
ghc883 = errorOldGhcjs "8.8.3" "8.8";
ghc8101 = errorOldGhcjs "8.10.1" "8.10";
ghc8102 = errorOldGhcjs "8.10.2" "8.10";
ghc8103 = errorOldGhcjs "8.10.3" "8.10";
ghc8104 = errorOldGhcjs "8.10.4" "8.10";
ghc810420210212 = throw "ghcjs for ghc810420210212 is not supported by haskell.nix";
ghc901 = throw "ghcjs 9.0.1 is not yet supported by haskell.nix";
ghc865 = let buildGHC = final.buildPackages.haskell-nix.compiler.ghc865;
in let booted-ghcjs = final.callPackage ../compiler/ghcjs/ghcjs.nix {
ghcjsSrcJson = ../compiler/ghcjs/ghcjs-src.json;
Expand Down Expand Up @@ -547,40 +563,6 @@ in {
cd lib
lndir ${booted-ghcjs}/lib ${targetPrefix}ghc-8.6.5
'' + installDeps targetPrefix);
ghc883 = let buildGHC = final.buildPackages.haskell-nix.compiler.ghc883;
in let booted-ghcjs = final.callPackage ../compiler/ghcjs/ghcjs.nix {
ghcjsSrcJson = ../compiler/ghcjs/ghcjs88-src.json;
ghcjsVersion = "8.8.0.0.1";
ghc = buildGHC;
ghcVersion = "8.8.3";
compiler-nix-name = "ghc883";
}; in let targetPrefix = "js-unknown-ghcjs-"; in final.runCommand "${targetPrefix}ghc-8.8.3" {
nativeBuildInputs = [ final.xorg.lndir ];
passthru = {
inherit targetPrefix;
version = "8.8.3";
isHaskellNixCompiler = true;
enableShared = false;
inherit (booted-ghcjs) configured-src bundled-ghcjs project;
inherit booted-ghcjs buildGHC;
extraConfigureFlags = [
"--ghcjs"
"--with-ghcjs=${targetPrefix}ghc" "--with-ghcjs-pkg=${targetPrefix}ghc-pkg"
"--with-gcc=${final.buildPackages.emscripten}/bin/emcc"
];
};
# note: we'll use the buildGHCs `hsc2hs`, ghcjss wrapper just horribly breaks in this nix setup.
} (''
mkdir -p $out/bin
cd $out/bin
ln -s ${booted-ghcjs}/bin/ghcjs ${targetPrefix}ghc
ln -s ${booted-ghcjs}/bin/ghcjs-pkg ${targetPrefix}ghc-pkg
ln -s ${buildGHC}/bin/hsc2hs ${targetPrefix}hsc2hs
cd ..
mkdir -p lib/${targetPrefix}ghc-8.8.3
cd lib
lndir ${booted-ghcjs}/lib ${targetPrefix}ghc-8.8.3
'' + installDeps targetPrefix);
ghc884 = let buildGHC = final.buildPackages.haskell-nix.compiler.ghc884;
in let booted-ghcjs = final.callPackage ../compiler/ghcjs/ghcjs.nix {
ghcjsSrcJson = ../compiler/ghcjs/ghcjs88-src.json;
Expand Down
13 changes: 5 additions & 8 deletions test/haskell-language-server/stack.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{ lib, testSrc, haskell-nix, evalPackages, buildPackages, compiler-nix-name, recurseIntoAttrs }:
{ stdenv, lib, testSrc, haskell-nix, evalPackages, buildPackages, compiler-nix-name, recurseIntoAttrs }:
let
project = buildPackages.haskell-nix.project' {
inherit compiler-nix-name;
src = evalPackages.fetchgit {
url = "https://github.com/haskell/haskell-language-server.git";
fetchSubmodules = true;
rev = "1.1.0";
sha256 = "sha256-5bIr7Zsvn1B8bjjiHPLQQS8+qW3ZiEwqBnFUG+fAcU8=";
rev = "1.2.0";
sha256 = "sha256-vNpb/Fjb9sKkt/1r29c82P/NeAXpxQbVKnM/EDWY6z4=";
};
projectFileName = "stack-${buildPackages.haskell-nix.compiler.${
if compiler-nix-name == "ghc8105"
then "ghc8104"
else compiler-nix-name
}.version}.yaml";
projectFileName = "stack-${buildPackages.haskell-nix.compiler.${compiler-nix-name}.version}.yaml";
sha256map = {
"https://github.com/alanz/ghc-exactprint.git"."6748e24da18a6cea985d20cc3e1e7920cb743795" = "18r41290xnlizgdwkvz16s7v8k2znc7h215sb1snw6ga8lbv60rb";
"https://github.com/bubba/brittany.git"."c59655f10d5ad295c2481537fc8abf0a297d9d1c" = "1rkk09f8750qykrmkqfqbh44dbx1p8aq1caznxxlw8zqfvx39cxl";
"https://github.com/hsyl20/ghc-api-compat.git"."8fee87eac97a538dbe81ff1ab18cff10f2f9fa15" = "sha256-byehvdxQxhNk5ZQUXeFHjAZpAze4Ct9261ro4c5acZk=";
};
};
in recurseIntoAttrs {
Expand Down

0 comments on commit 90184a7

Please sign in to comment.