Merge pull request #26799 from obsidiansystems/cross-haskell

haskell infra: Fix cross compilation to work with new system
This commit is contained in:
John Ericson
2018-01-22 15:31:19 -05:00
committed by GitHub
20 changed files with 776 additions and 312 deletions

View File

@@ -1,4 +1,5 @@
{ pkgs, stdenv, lib, haskellLib, ghc, all-cabal-hashes
, buildHaskellPackages
, compilerConfig ? (self: super: {})
, packageSetConfig ? (self: super: {})
, overrides ? (self: super: {})
@@ -14,7 +15,7 @@ let
haskellPackages = pkgs.callPackage makePackageSet {
package-set = initialPackages;
inherit stdenv haskellLib ghc extensible-self;
inherit stdenv haskellLib ghc buildHaskellPackages extensible-self;
};
commonConfiguration = configurationCommon { inherit pkgs haskellLib; };

View File

@@ -1,4 +1,4 @@
{ stdenv, buildPackages, ghc
{ stdenv, buildPackages, buildHaskellPackages, ghc
, jailbreak-cabal, hscolour, cpphs, nodejs
, buildPlatform, hostPlatform
}:
@@ -81,7 +81,11 @@ let
then "package-db"
else "package-conf";
nativeGhc = if isCross || isGhcjs then ghc.bootPkgs.ghc else ghc;
# GHC used for building Setup.hs
#
# Same as our GHC, unless we're cross, in which case it is native GHC with the
# same version, or ghcjs, in which case its the ghc used to build ghcjs.
nativeGhc = buildHaskellPackages.ghc;
nativePackageDbFlag = if versionOlder "7.6" nativeGhc.version
then "package-db"
else "package-conf";
@@ -147,8 +151,7 @@ let
] ++ crossCabalFlags);
setupCompileFlags = [
(optionalString (!coreSetup) "-${packageDbFlag}=$packageConfDir")
(optionalString isGhcjs "-build-runner")
(optionalString (!coreSetup) "-${nativePackageDbFlag}=$packageConfDir")
(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")
@@ -160,14 +163,12 @@ let
allPkgconfigDepends = pkgconfigDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++
optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends;
nativeBuildInputs = optional (allPkgconfigDepends != []) pkgconfig ++
buildTools ++ libraryToolDepends ++ executableToolDepends ++ [ removeReferencesTo ];
nativeBuildInputs = [ ghc nativeGhc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) pkgconfig ++
buildTools ++ libraryToolDepends ++ executableToolDepends;
propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends;
otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++
optionals (allPkgconfigDepends != []) allPkgconfigDepends ++
optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testToolDepends) ++
# ghcjs's hsc2hs calls out to the native hsc2hs
optional isGhcjs nativeGhc ++
optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkToolDepends);
allBuildInputs = propagatedBuildInputs ++ otherBuildInputs;
@@ -176,12 +177,14 @@ let
ghcEnv = ghc.withPackages (p: haskellBuildInputs);
setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand;
setupCommand = "./Setup";
ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
ghcCommand = "${ghc.targetPrefix}${ghcCommand'}";
ghcCommandCaps= toUpper ghcCommand';
nativeGhcCommand = "${nativeGhc.targetPrefix}ghc";
in
assert allPkgconfigDepends != [] -> pkgconfig != null;
@@ -220,7 +223,6 @@ stdenv.mkDerivation ({
runHook preSetupCompilerEnvironment
echo "Build with ${ghc}."
export PATH="${ghc}/bin:$PATH"
${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"}
packageConfDir="$TMPDIR/package.conf.d"
@@ -271,11 +273,13 @@ stdenv.mkDerivation ({
done
echo setupCompileFlags: $setupCompileFlags
${setupBuilder} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
runHook postCompileBuildDriver
'';
# Cabal takes flags like `--configure-option=--host=...` instead
configurePlatforms = [];
inherit configureFlags;
configurePhase = ''

View File

@@ -4,6 +4,10 @@
{ # package-set used for build tools (all of nixpkgs)
buildPackages
, # A haskell package set for Setup.hs, compiler plugins, and similar
# build-time uses.
buildHaskellPackages
, # package-set used for non-haskell dependencies (all of nixpkgs)
pkgs
@@ -18,8 +22,8 @@
, # compiler to use
ghc
, # A function that takes `{ pkgs, stdenv, callPackage }` as the first arg and `self`
# as second, and returns a set of haskell packages
, # A function that takes `{ pkgs, stdenv, callPackage }` as the first arg and
# `self` as second, and returns a set of haskell packages
package-set
, # The final, fully overriden package set usable with the nixpkgs fixpoint
@@ -36,15 +40,12 @@ let
inherit (stdenv.lib) fix' extends makeOverridable;
inherit (haskellLib) overrideCabal;
buildHaskellPackages = if hostPlatform != buildPlatform
then self.ghc.bootPkgs
else self;
mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
inherit stdenv;
nodejs = buildPackages.nodejs-slim;
inherit (buildHaskellPackages) jailbreak-cabal;
inherit buildHaskellPackages;
inherit (self) ghc;
inherit (buildHaskellPackages) jailbreak-cabal;
hscolour = overrideCabal buildHaskellPackages.hscolour (drv: {
isLibrary = false;
doHaddock = false;
@@ -119,7 +120,7 @@ let
installPhase = ''
export HOME="$TMP"
mkdir -p "$out"
cabal2nix --compiler=${self.ghc.name} --system=${stdenv.system} ${sha256Arg} "${src}" > "$out/default.nix"
cabal2nix --compiler=${ghc.haskellCompilerName} --system=${stdenv.system} ${sha256Arg} "${src}" > "$out/default.nix"
'';
};