haskell: use GHCJS to build Setup.hs for GHCJS packages

Closes https://github.com/NixOS/nixpkgs/pull/23614.
This commit is contained in:
Leon Isenberg 2017-03-25 05:23:01 +01:00 committed by Peter Simons
parent 80a52e22b3
commit 2553ceb982
5 changed files with 24 additions and 2 deletions

View file

@ -327,6 +327,7 @@
version = "1.22.8.0";
src = "${ghcjsBoot}/boot/cabal/Cabal";
doCheck = false;
hyperlinkSource = false;
libraryHaskellDepends = [
array base binary bytestring containers deepseq directory filepath
pretty process time unix

View file

@ -53,6 +53,14 @@ self: super:
terminfo = self.terminfo_0_4_0_2;
xhtml = self.xhtml_3000_2_1;
# Cabal isn't part of the stage1 packages which form the default package-db
# that GHCJS provides.
# Almost all packages require Cabal to build their Setup.hs,
# but usually they don't declare it explicitly as they don't need to for normal GHC.
# To account for that we add Cabal by default.
mkDerivation = args:
if args.pname == "Cabal" then super.mkDerivation args else super.mkDerivation (args //
{ setupHaskellDepends = (args.setupHaskellDepends or []) ++ [ self.Cabal ]; });
## OTHER PACKAGES

View file

@ -15,6 +15,7 @@ let
mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
inherit stdenv;
inherit (pkgs) fetchurl pkgconfig glibcLocales coreutils gnugrep gnused;
nodejs = pkgs.nodejs-slim;
jailbreak-cabal = if (self.ghc.cross or null) != null
then self.ghc.bootPkgs.jailbreak-cabal
else self.jailbreak-cabal;

View file

@ -1,5 +1,5 @@
{ stdenv, fetchurl, ghc, pkgconfig, glibcLocales, coreutils, gnugrep, gnused
, jailbreak-cabal, hscolour, cpphs
, jailbreak-cabal, hscolour, cpphs, nodejs
}: let isCross = (ghc.cross or null) != null; in
{ pname
@ -133,6 +133,7 @@ let
setupCompileFlags = [
(optionalString (!coreSetup) "-${packageDbFlag}=$packageConfDir")
(optionalString isGhcjs "-build-runner")
(optionalString (isGhcjs || isHaLVM || versionOlder "7.8" ghc.version) "-j$NIX_BUILD_CORES")
# https://github.com/haskell/cabal/issues/2398
(optionalString (versionOlder "7.10" ghc.version && !isHaLVM) "-threaded")
@ -157,7 +158,7 @@ let
ghcEnv = ghc.withPackages (p: haskellBuildInputs);
setupBuilder = if isCross || isGhcjs then "${nativeGhc}/bin/ghc" else ghcCommand;
setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand;
setupCommand = "./Setup";
ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else "";
@ -294,6 +295,14 @@ stdenv.mkDerivation ({
local pkgId=$( ${gnused}/bin/sed -n -e 's|^id: ||p' $packageConfFile )
mv $packageConfFile $packageConfDir/$pkgId.conf
''}
${optionalString isGhcjs ''
for exeDir in "$out/bin/"*.jsexe; do
exe="''${exeDir%.jsexe}"
printf '%s\n' '#!${nodejs}/bin/node' > "$exe"
cat "$exeDir/all.js" >> "$exe"
chmod +x "$exe"
done
''}
${optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share"}
${optionalString (enableSharedExecutables && isExecutable && !isGhcjs && stdenv.isDarwin && stdenv.lib.versionOlder ghc.version "7.10") ''
for exe in "$out/bin/"* ; do

View file

@ -38,6 +38,9 @@ rec {
addPkgconfigDepend = drv: x: addPkgconfigDepends drv [x];
addPkgconfigDepends = drv: xs: overrideCabal drv (drv: { pkgconfigDepends = (drv.pkgconfigDepends or []) ++ xs; });
addSetupDepend = drv: x: addSetupDepends drv [x];
addSetupDepends = drv: xs: overrideCabal drv (drv: { setupHaskellDepends = (drv.setupHaskellDepends or []) ++ xs; });
enableCabalFlag = drv: x: appendConfigureFlag (removeConfigureFlag drv "-f-${x}") "-f${x}";
disableCabalFlag = drv: x: appendConfigureFlag (removeConfigureFlag drv "-f${x}") "-f-${x}";