on iko/ghcjs-patch-master help sign in
Cross compilation
commitf2b80ee3efdcd5b1066f5aae9d02b3a4c02b22ad authorWill Fancher <elvishjerricco@gmail.com> dateSun 4 Nov 2018, 05:33 (8 years ago) parent47742dc
7 files changed+40−29
builder/comp-builder.nix+17−10 builder/default.nix+5−4 lib/host-map.nix+2−2 modules/component-driver.nix+3−2 modules/hackage.nix+4−5 modules/plan.nix+2−4 new-package-set.nix+7−2
builder/comp-builder.nix+17−10
@@ -28,10 +28,10 @@ let
2828 in map ({val,...}: val) closure;
2929
3030 exactDep = pdbArg: p: ''
31− if id=$(ghc-pkg ${pdbArg} field ${p} id --simple-output); then
31+ if id=$(${ghc.targetPrefix}ghc-pkg ${pdbArg} field ${p} id --simple-output); then
3232 echo "--dependency=${p}=$id" >> $out/configure-flags
3333 fi
34− if ver=$(ghc-pkg ${pdbArg} field ${p} version --simple-output); then
34+ if ver=$(${ghc.targetPrefix}ghc-pkg ${pdbArg} field ${p} version --simple-output); then
3535 echo "constraint: ${p} == $ver" >> $out/cabal.config
3636 echo "constraint: ${p} installed" >> $out/cabal.config
3737 fi
@@ -39,7 +39,7 @@ let
3939
4040 configFiles = runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
4141 mkdir -p $out
42− ghc-pkg init $out/package.conf.d
42+ ${ghc.targetPrefix}ghc-pkg init $out/package.conf.d
4343
4444 ${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig {
4545 "extra-lib-dirs" = map (p: "${p}/lib") component.libs;
@@ -48,7 +48,7 @@ let
4848 })}
4949
5050 ${lib.concatMapStringsSep "\n" (p: ''
51− ghc-pkg --package-db ${p}/package.conf.d dump | ghc-pkg --force --package-db $out/package.conf.d register -
51+ ${ghc.targetPrefix}ghc-pkg --package-db ${p}/package.conf.d dump | ${ghc.targetPrefix}ghc-pkg --force --package-db $out/package.conf.d register -
5252 '') flatDepends}
5353 ${flagsAndConfig "package-db" ["$out/package.conf.d"]}
5454
@@ -63,13 +63,20 @@ let
6363 ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
6464
6565 '' + ''
66− ghc-pkg --package-db $out/package.conf.d check
66+ ${ghc.targetPrefix}ghc-pkg --package-db $out/package.conf.d check
6767 '');
6868
6969 finalConfigureFlags = lib.concatStringsSep " " (
70− [ "--prefix=$out" "${componentId.ctype}:${componentId.cname}" ]
71− ++ ["$(cat ${configFiles}/configure-flags)"]
72− ++ component.configureFlags
70+ [ "--prefix=$out"
71+ "${componentId.ctype}:${componentId.cname}"
72+ "$(cat ${configFiles}/configure-flags)"
73+ "--with-ghc=${ghc.targetPrefix}ghc"
74+ "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg"
75+ "--with-hsc2hs=${ghc.targetPrefix}hsc2hs"
76+ ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
77+ ["--hsc2hs-option=--cross-compile"]
78+ ++ lib.optional (package.buildType == "Configure") "--configure-option=--host=${stdenv.hostPlatform.config}"
79+ ) ++ component.configureFlags
7380 );
7481
7582in stdenv.mkDerivation {
@@ -131,8 +138,8 @@ in stdenv.mkDerivation {
131138 $SETUP_HS copy
132139 ${lib.optionalString (haskellLib.isLibrary componentId) ''
133140 $SETUP_HS register --gen-pkg-config=${name}.conf
134− ghc-pkg init $out/package.conf.d
135− ghc-pkg --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
141+ ${ghc.targetPrefix}ghc-pkg init $out/package.conf.d
142+ ${ghc.targetPrefix}ghc-pkg --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
136143 ''}
137144 '';
138145}
builder/default.nix+5−4
@@ -1,4 +1,4 @@
1−{ pkgs, stdenv, lib, haskellLib, ghc, fetchurl, writeText, runCommand, pkgconfig, nonReinstallablePkgs }:
1+{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, writeText, runCommand, pkgconfig, nonReinstallablePkgs }:
22
33{ flags
44, package
@@ -19,21 +19,22 @@ let
1919 url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
2020 sha256 = revisionSha256;
2121 };
22+
2223 defaultSetupSrc = builtins.toFile "Setup.hs" ''
2324 import Distribution.Simple
2425 main = defaultMain
2526 '';
26− defaultSetup = runCommand "default-Setup" { nativeBuildInputs = [ghc]; } ''
27+ defaultSetup = buildPackages.runCommand "default-Setup" { nativeBuildInputs = [buildGHC]; } ''
2728 cat ${defaultSetupSrc} > Setup.hs
2829 mkdir -p $out/bin
29− ghc Setup.hs --make -o $out/bin/Setup
30+ ${buildGHC.targetPrefix}ghc Setup.hs --make -o $out/bin/Setup
3031 '';
3132
3233 setup = if package.buildType == "Simple"
3334 then defaultSetup
3435 else stdenv.mkDerivation {
3536 name = "${name}-setup";
36− nativeBuildInputs = [ghc];
37+ nativeBuildInputs = [buildGHC];
3738 inherit src;
3839 phases = ["unpackPhase" "buildPhase" "installPhase"];
3940 buildPhase = ''
lib/host-map.nix+2−2
@@ -13,8 +13,8 @@ stdenv: with stdenv.hostPlatform; {
1313 if isx86 && is64bit then "X86_64" else
1414 if isPowerPC && is32bit then "PPC" else
1515 if isPowerPC && is64bit then "PPC64" else
16− if isArm && is32bit then "Arm" else
17− if isArm && is64bit then "Aarch64" else
16+ if isAarch32 then "Arm" else
17+ if isAarch64 then "Aarch64" else
1818 if isMips then "Mips" else
1919 throw "Unknown Arch";
2020}
modules/component-driver.nix+3−2
@@ -1,9 +1,10 @@
1−{ config, pkgs, lib, haskellLib, ... }:
1+{ config, pkgs, lib, haskellLib, buildModules, ... }:
22let
33 # TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted
44 new-builder = haskellLib.weakCallPackage pkgs ../builder {
55 inherit haskellLib;
66 ghc = config.ghc.package;
7+ buildGHC = buildModules.config.ghc.package;
78 inherit (config) nonReinstallablePkgs;
89 };
910in
@@ -21,7 +22,7 @@ in
2122 type = lib.types.unspecified;
2223 };
2324
24− config.hsPkgs = { buildPackages = config.hsPkgs; }
25+ config.hsPkgs = { buildPackages = buildModules.config.hsPkgs; }
2526 // lib.mapAttrs
2627 (name: pkg: if pkg == null then null else new-builder pkg)
2728 (config.packages // lib.genAttrs config.nonReinstallablePkgs (_: null));
modules/hackage.nix+4−5
@@ -41,12 +41,11 @@ let
4141 (vnum: version: version // {
4242 revisions =
4343 let
44− rev2Config = rev: {
44+ rev2Config = rev: { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs: {
4545 inherit (version) sha256;
46− inherit (rev) outPath;
4746 revision = rev.revNum;
4847 revisionSha256 = rev.sha256;
49− };
48+ } // import rev modArgs;
5049 f = rev: acc: acc // {
5150 # If there's a collision (e.g. a revision was
5251 # reverted), pick the one with the smaller
@@ -67,8 +66,8 @@ in {
6766 # this should allow us to use `config` overrides
6867 # in the nixpkgs setup, and properly override the
6968 # complier as needed.
70− default = pkgs.haskell.compiler.${config.compiler.nix-name};
71− defaultText = "pkgs.haskell.compiler.\${config.compiler.nix-name}";
69+ default = pkgs.buildPackages.haskell.compiler.${config.compiler.nix-name};
70+ defaultText = "pkgs.buildPackages.haskell.compiler.\${config.compiler.nix-name}";
7271 };
7372
7473 options.hackage.db = lib.mkOption {
modules/plan.nix+2−4
@@ -54,10 +54,8 @@ with types;
5454 config = let module = config.plan.pkg-def config.hackage.configs; in {
5555 inherit (module) compiler overlay;
5656 packages = lib.mapAttrs (_: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }@modArgs:
57− let m = import revision.outPath modArgs;
58− in m
59− // builtins.removeAttrs revision ["outPath"]
60− // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
57+ let m = revision modArgs;
58+ in m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
6159 ) module.packages;
6260 };
6361}
new-package-set.nix+7−2
@@ -1,4 +1,6 @@
1−{ hackage, pkgs, pkg-def, modules ? [] }: pkgs.lib.evalModules {
1+let f = { hackage, pkgs, pkg-def, modules ? [] }: let
2+ buildModules = f { inherit hackage pkg-def modules; pkgs = pkgs.buildPackages; };
3+in pkgs.lib.evalModules {
24 modules = modules ++ [
35 ({ lib, ... }: {
46 # Provide all modules with haskellLib, pkgs, and pkgconfPkgs arguments
@@ -12,6 +14,8 @@
1214 # augment the existing pkgs set with the specific mappings:
1315 pkgs = pkgs // (import ./lib/system-nixpkgs-map.nix pkgs);
1416 pkgconfPkgs = pkgs // (import ./lib/pkgconf-nixpkgs-map.nix pkgs);
17+
18+ inherit buildModules;
1519 };
1620
1721 # Set the hackage DB for modules/hackage.nix
@@ -37,4 +41,5 @@
3741 # Configuration that applies to all plans
3842 ./modules/configuration-nix.nix
3943 ];
40−}
44+};
45+in f