haskell infra: Fix cross as much as possible without changing hashes

This commit is contained in:
John Ericson 2017-09-10 15:36:48 -04:00
parent 63bf7d002c
commit e92cda161a
4 changed files with 41 additions and 30 deletions

View file

@ -1,7 +1,14 @@
{ stdenv, fetchurl, ghc, pkgconfig, glibcLocales, coreutils, gnugrep, gnused { stdenv, buildPackages, ghc
, jailbreak-cabal, hscolour, cpphs, nodejs, lib, removeReferencesTo , jailbreak-cabal, hscolour, cpphs, nodejs
, buildPlatform, hostPlatform
}: }:
let isCross = (ghc.cross or null) != null; in
let
isCross = buildPlatform != hostPlatform;
inherit (buildPackages)
fetchurl removeReferencesTo
pkgconfig binutils coreutils gnugrep gnused glibcLocales;
in
{ pname { pname
, dontStrip ? (ghc.isGhcjs or false) , dontStrip ? (ghc.isGhcjs or false)
@ -20,8 +27,8 @@ let isCross = (ghc.cross or null) != null; in
, enableLibraryProfiling ? false , enableLibraryProfiling ? false
, enableExecutableProfiling ? false , enableExecutableProfiling ? false
# TODO enable shared libs for cross-compiling # TODO enable shared libs for cross-compiling
, enableSharedExecutables ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)) , enableSharedExecutables ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)
, enableSharedLibraries ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)) , enableSharedLibraries ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)
, enableSplitObjs ? null # OBSOLETE, use enableDeadCodeElimination , enableSplitObjs ? null # OBSOLETE, use enableDeadCodeElimination
, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin , enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin
, enableStaticLibraries ? true , enableStaticLibraries ? true
@ -53,7 +60,7 @@ let isCross = (ghc.cross or null) != null; in
, shellHook ? "" , shellHook ? ""
, coreSetup ? false # Use only core packages to build Setup.hs. , coreSetup ? false # Use only core packages to build Setup.hs.
, useCpphs ? false , useCpphs ? false
, hardeningDisable ? lib.optional (ghc.isHaLVM or false) "all" , hardeningDisable ? stdenv.lib.optional (ghc.isHaLVM or false) "all"
, enableSeparateDataOutput ? false , enableSeparateDataOutput ? false
, enableSeparateDocOutput ? doHaddock , enableSeparateDocOutput ? doHaddock
} @ args: } @ args:
@ -102,11 +109,12 @@ let
enableParallelBuilding = (versionOlder "7.8" ghc.version && !hasActiveLibrary) || versionOlder "8.0.1" ghc.version; enableParallelBuilding = (versionOlder "7.8" ghc.version && !hasActiveLibrary) || versionOlder "8.0.1" ghc.version;
crossCabalFlags = [ crossCabalFlags = [
"--with-ghc=${ghc.cross.config}-ghc" "--with-ghc=${ghc.prefix}ghc"
"--with-ghc-pkg=${ghc.cross.config}-ghc-pkg" "--with-ghc-pkg=${ghc.prefix}ghc-pkg"
"--with-gcc=${ghc.cc}" "--with-gcc=${ghc.prefix}cc"
"--with-ld=${ghc.ld}" "--with-ld=${ghc.prefix}ld"
"--with-hsc2hs=${nativeGhc}/bin/hsc2hs" "--with-hsc2hs=${nativeGhc}/bin/hsc2hs"
"--with-strip=${binutils}/bin/${ghc.prefix}strip"
] ++ (if isHaLVM then [] else ["--hsc2hs-options=--cross-compile"]); ] ++ (if isHaLVM then [] else ["--hsc2hs-options=--cross-compile"]);
crossCabalFlagsString = crossCabalFlagsString =
@ -135,7 +143,7 @@ let
] ++ optionals isGhcjs [ ] ++ optionals isGhcjs [
"--ghcjs" "--ghcjs"
] ++ optionals isCross ([ ] ++ optionals isCross ([
"--configure-option=--host=${ghc.cross.config}" "--configure-option=--host=${hostPlatform.config}"
] ++ crossCabalFlags); ] ++ crossCabalFlags);
setupCompileFlags = [ setupCompileFlags = [
@ -170,8 +178,7 @@ let
setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand; setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand;
setupCommand = "./Setup"; setupCommand = "./Setup";
ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else ""; ghcCommand = "${ghc.prefix}${ghcCommand'}";
ghcCommand = "${crossPrefix}${ghcCommand'}";
ghcCommandCaps= toUpper ghcCommand'; ghcCommandCaps= toUpper ghcCommand';
in in
@ -268,6 +275,8 @@ stdenv.mkDerivation ({
runHook postCompileBuildDriver runHook postCompileBuildDriver
''; '';
inherit configureFlags;
configurePhase = '' configurePhase = ''
runHook preConfigure runHook preConfigure
@ -393,7 +402,6 @@ stdenv.mkDerivation ({
// optionalAttrs (postCompileBuildDriver != "") { inherit postCompileBuildDriver; } // optionalAttrs (postCompileBuildDriver != "") { inherit postCompileBuildDriver; }
// optionalAttrs (preUnpack != "") { inherit preUnpack; } // optionalAttrs (preUnpack != "") { inherit preUnpack; }
// optionalAttrs (postUnpack != "") { inherit postUnpack; } // optionalAttrs (postUnpack != "") { inherit postUnpack; }
// optionalAttrs (configureFlags != []) { inherit configureFlags; }
// optionalAttrs (patches != []) { inherit patches; } // optionalAttrs (patches != []) { inherit patches; }
// optionalAttrs (patchPhase != "") { inherit patchPhase; } // optionalAttrs (patchPhase != "") { inherit patchPhase; }
// optionalAttrs (preConfigure != "") { inherit preConfigure; } // optionalAttrs (preConfigure != "") { inherit preConfigure; }
@ -412,5 +420,5 @@ stdenv.mkDerivation ({
// optionalAttrs (postFixup != "") { inherit postFixup; } // optionalAttrs (postFixup != "") { inherit postFixup; }
// optionalAttrs (dontStrip) { inherit dontStrip; } // optionalAttrs (dontStrip) { inherit dontStrip; }
// optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; } // optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; }
// optionalAttrs (stdenv.isLinux) { LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; } // optionalAttrs (buildPlatform.isLinux){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; }
) )

View file

@ -1,7 +1,10 @@
# This expression takes a file like `hackage-packages.nix` and constructs # This expression takes a file like `hackage-packages.nix` and constructs
# a full package set out of that. # a full package set out of that.
{ # package-set used for non-haskell dependencies (all of nixpkgs) { # package-set used for build tools (all of nixpkgs)
buildPackages
, # package-set used for non-haskell dependencies (all of nixpkgs)
pkgs pkgs
, # stdenv to use for building haskell packages , # stdenv to use for building haskell packages
@ -28,19 +31,21 @@
self: self:
let let
inherit (stdenv) buildPlatform hostPlatform;
inherit (stdenv.lib) fix' extends makeOverridable; inherit (stdenv.lib) fix' extends makeOverridable;
inherit (haskellLib) overrideCabal; inherit (haskellLib) overrideCabal;
buildHaskellPackages = if hostPlatform != buildPlatform
then self.ghc.bootPkgs
else self;
mkDerivationImpl = pkgs.callPackage ./generic-builder.nix { mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
inherit stdenv; inherit stdenv;
inherit (pkgs) fetchurl pkgconfig glibcLocales coreutils gnugrep gnused; nodejs = buildPackages.nodejs-slim;
nodejs = pkgs.nodejs-slim; inherit (buildHaskellPackages) jailbreak-cabal;
jailbreak-cabal = if (self.ghc.cross or null) != null
then self.ghc.bootPkgs.jailbreak-cabal
else self.jailbreak-cabal;
inherit (self) ghc; inherit (self) ghc;
hscolour = overrideCabal self.hscolour (drv: { hscolour = overrideCabal buildHaskellPackages.hscolour (drv: {
isLibrary = false; isLibrary = false;
doHaddock = false; doHaddock = false;
hyperlinkSource = false; # Avoid depending on hscolour for this build. hyperlinkSource = false; # Avoid depending on hscolour for this build.
@ -104,13 +109,13 @@ let
haskellSrc2nix = { name, src, sha256 ? null }: haskellSrc2nix = { name, src, sha256 ? null }:
let let
sha256Arg = if isNull sha256 then "--sha256=" else ''--sha256="${sha256}"''; sha256Arg = if isNull sha256 then "--sha256=" else ''--sha256="${sha256}"'';
in pkgs.stdenv.mkDerivation { in pkgs.buildPackages.stdenv.mkDerivation {
name = "cabal2nix-${name}"; name = "cabal2nix-${name}";
buildInputs = [ pkgs.haskellPackages.cabal2nix ]; nativeBuildInputs = [ pkgs.buildPackages.haskellPackages.cabal2nix ];
preferLocalBuild = true; preferLocalBuild = true;
phases = ["installPhase"]; phases = ["installPhase"];
LANG = "en_US.UTF-8"; LANG = "en_US.UTF-8";
LOCALE_ARCHIVE = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.glibcLocales}/lib/locale/locale-archive"; LOCALE_ARCHIVE = pkgs.lib.optionalString buildPlatform.isLinux "${buildPackages.glibcLocales}/lib/locale/locale-archive";
installPhase = '' installPhase = ''
export HOME="$TMP" export HOME="$TMP"
mkdir -p "$out" mkdir -p "$out"

View file

@ -36,9 +36,8 @@ let
isHaLVM = ghc.isHaLVM or false; isHaLVM = ghc.isHaLVM or false;
ghc761OrLater = isGhcjs || isHaLVM || lib.versionOlder "7.6.1" ghc.version; ghc761OrLater = isGhcjs || isHaLVM || lib.versionOlder "7.6.1" ghc.version;
packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf"; packageDBFlag = if ghc761OrLater then "--global-package-db" else "--global-conf";
ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else ""; ghcCommand = "${ghc.prefix}${ghcCommand'}";
ghcCommand = "${crossPrefix}${ghcCommand'}";
ghcCommandCaps= lib.toUpper ghcCommand'; ghcCommandCaps= lib.toUpper ghcCommand';
libDir = if isHaLVM then "$out/lib/HaLVM-${ghc.version}" else "$out/lib/${ghcCommand}-${ghc.version}"; libDir = if isHaLVM then "$out/lib/HaLVM-${ghc.version}" else "$out/lib/${ghcCommand}-${ghc.version}";
docDir = "$out/share/doc/ghc/html"; docDir = "$out/share/doc/ghc/html";

View file

@ -2,8 +2,7 @@
{ haskellPackages, src, deps ? p : [], name }: let { haskellPackages, src, deps ? p : [], name }: let
inherit (haskellPackages) ghc ghcWithPackages; inherit (haskellPackages) ghc ghcWithPackages;
with-env = ghcWithPackages deps; with-env = ghcWithPackages deps;
crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else ""; ghcName = "${ghc.prefix}ghc";
ghcName = "${crossPrefix}ghc";
in runCommand name { buildInputs = [ with-env cctools ]; } '' in runCommand name { buildInputs = [ with-env cctools ]; } ''
mkdir -p $out/lib mkdir -p $out/lib
mkdir -p $out/include mkdir -p $out/include