Better error message when building missing ghcjs (#1140)

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
```
This commit is contained in:
Hamish Mackenzie 2021-06-17 11:57:21 +12:00 committed by GitHub
parent f899936d1f
commit 90184a79f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 42 deletions

View File

@ -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
@ -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;
@ -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;

View File

@ -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 {