Commit 89fcb633 authored by John Ericson's avatar John Ericson Committed by GitHub
Browse files

Merge pull request #27179 from obsidiansystems/platforms-from-stdenv

Define {build,host,target}Platform in stdenv
parents 3abfc161 9dc2a3ae
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -37,8 +37,9 @@
    </para>
    <para>
      In Nixpkgs, these three platforms are defined as attribute sets under the names <literal>buildPlatform</literal>, <literal>hostPlatform</literal>, and <literal>targetPlatform</literal>.
      All three are always defined at the top level, so one can get at them just like a dependency in a function that is imported with <literal>callPackage</literal>:
      <programlisting>{ stdenv, buildPlatform, hostPlatform, fooDep, barDep, .. }: ...</programlisting>
      All three are always defined as attributes in the standard environment, and at the top level. That means one can get at them just like a dependency in a function that is imported with <literal>callPackage</literal>:
      <programlisting>{ stdenv, buildPlatform, hostPlatform, fooDep, barDep, .. }: ...buildPlatform...</programlisting>, or just off <varname>stdenv</varname>:
      <programlisting>{ stdenv, fooDep, barDep, .. }: ...stdenv.buildPlatform...</programlisting>.
    </para>
    <variablelist>
      <varlistentry>
+3 −2
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@
, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
, dyld ? null # TODO: should this be a setup-hook on dyld?
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
, hostPlatform, targetPlatform
, runCommand ? null
}:

@@ -22,12 +21,14 @@ assert !nativeTools ->
assert !(nativeLibc && noLibc);
assert (noLibc || nativeLibc) == (libc == null);

assert targetPlatform != hostPlatform -> runCommand != null;
assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null;

# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
assert cc.langVhdl or false -> zlib != null;

let
  inherit (stdenv) hostPlatform targetPlatform;

  # Prefix for binaries. Customarily ends with a dash separator.
  #
  # TODO(@Ericson2314) Make unconditional, or optional but always true by
+3 −5
Original line number Diff line number Diff line
@@ -61,11 +61,9 @@ rec {
                    , buildPlatform, hostPlatform, targetPlatform
                    } @ overrideArgs: let
    stdenv = overrideArgs.stdenv.override {
      # TODO(@Ericson2314): Cannot do this for now because then Nix thinks the
      # resulting derivation should be built on the host platform.
      #hostPlatform = buildPlatform;
      #targetPlatform = hostPlatform;
      inherit cc;
      inherit
        buildPlatform hostPlatform targetPlatform
        cc;

      allowedRequisites = null;

+4 −7
Original line number Diff line number Diff line
@@ -14,21 +14,18 @@ in bootStages ++ [

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

  # Run Packages
  (buildPackages: {
    buildPlatform = localSystem;
    hostPlatform = crossSystem;
    targetPlatform = crossSystem;
    inherit config overlays;
    selfBuild = false;
    stdenv = buildPackages.makeStdenvCross {
+4 −4
Original line number Diff line number Diff line
@@ -15,11 +15,11 @@ in bootStages ++ [

  # Additional stage, built using custom stdenv
  (vanillaPackages: {
    buildPlatform = localSystem;
    hostPlatform = localSystem;
    targetPlatform = localSystem;
    inherit config overlays;
    stdenv = config.replaceStdenv { pkgs = vanillaPackages; };
    stdenv =
      assert vanillaPackages.hostPlatform == localSystem;
      assert vanillaPackages.targetPlatform == localSystem;
      config.replaceStdenv { pkgs = vanillaPackages; };
  })

]
Loading