summary refs log tree commit diff
path: root/pkgs/stdenv/cross/default.nix
blob: 44d412e041b7c7bd6874ff83fb0431fe95b6e1dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ lib
, localSystem, crossSystem, config, overlays, crossOverlays ? []
}:

let
  bootStages = import ../. {
    inherit lib localSystem overlays;

    crossSystem = localSystem;
    crossOverlays = [];

    # Ignore custom stdenvs when cross compiling for compatability
    config = builtins.removeAttrs config [ "replaceStdenv" ];
  };

in lib.init bootStages ++ [

  # Regular native packages
  (somePrevStage: lib.last bootStages somePrevStage // {
    # It's OK to change the built-time dependencies
    allowCustomOverrides = true;
  })

  # Build tool Packages
  (vanillaPackages: {
    inherit config overlays;
    selfBuild = false;
    stdenv =
      assert vanillaPackages.stdenv.buildPlatform == localSystem;
      assert vanillaPackages.stdenv.hostPlatform == localSystem;
      assert vanillaPackages.stdenv.targetPlatform == localSystem;
      vanillaPackages.stdenv.override { targetPlatform = crossSystem; };
    # It's OK to change the built-time dependencies
    allowCustomOverrides = true;
  })

  # Run Packages
  (buildPackages: {
    inherit config;
    overlays = overlays ++ crossOverlays
      ++ (if crossSystem.isWasm then [(import ../../top-level/static.nix)] else []);
    selfBuild = false;
    stdenv = buildPackages.stdenv.override (old: rec {
      buildPlatform = localSystem;
      hostPlatform = crossSystem;
      targetPlatform = crossSystem;

      # Prior overrides are surely not valid as packages built with this run on
      # a different platform, and so are disabled.
      overrides = _: _: {};
      extraBuildInputs = [ ]; # Old ones run on wrong platform
      allowedRequisites = null;

      hasCC = !targetPlatform.isGhcjs;

      cc = if crossSystem.useiOSPrebuilt or false
             then buildPackages.darwin.iosSdkPkgs.clang
           else if crossSystem.useAndroidPrebuilt or false
             then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
           else if targetPlatform.isGhcjs
             # Need to use `throw` so tryEval for splicing works, ugh.  Using
             # `null` or skipping the attribute would cause an eval failure
             # `tryEval` wouldn't catch, wrecking accessing previous stages
             # when there is a C compiler and everything should be fine.
             then throw "no C compile provided for this platform"
           else if crossSystem.useLLVM or false
             then buildPackages.llvmPackages_8.lldClang
           else buildPackages.gcc;

      extraNativeBuildInputs = old.extraNativeBuildInputs
        ++ lib.optionals
             (hostPlatform.isLinux && !buildPlatform.isLinux)
             [ buildPackages.patchelf ]
        ++ lib.optional
             (let f = p: !p.isx86 || p.libc == "musl" || p.libc == "wasilibc" || p.isiOS; in f hostPlatform && !(f buildPlatform))
             buildPackages.updateAutotoolsGnuConfigScriptsHook
           # without proper `file` command, libtool sometimes fails
           # to recognize 64-bit DLLs
        ++ lib.optional (hostPlatform.config == "x86_64-w64-mingw32") buildPackages.file
        ;
    });
  })

]