Skip to content

Commit

Permalink
treewide: Do a number of no-op cleanups for cross and darwin
Browse files Browse the repository at this point in the history
I am taking the non-invasive parts of #110914 to hopefully help out with #111988.

In particular:

 - Use `lib.makeScopeWithSplicing` to make the `darwin` package set have
   a proper `callPackage`.

 - Adjust Darwin `stdenv`'s overlays keeping things from the previous
   stage to not stick around too much.

 - Expose `binutilsNoLibc` / `darwin.binutilsNoLibc` to hopefully get us
   closer to a unified LLVM and GCC bootstrap.
  • Loading branch information
Ericson2314 committed May 6, 2021
1 parent b418e17 commit 470640e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 83 deletions.
8 changes: 5 additions & 3 deletions lib/customisation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,17 @@ rec {

/* Like the above, but aims to support cross compilation. It's still ugly, but
hopefully it helps a little bit. */
makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: f:
makeScopeWithSplicing = splicePackages: newScope: otherSplices: keep: extra: f:
let
spliced = splicePackages {
spliced0 = splicePackages {
pkgsBuildBuild = otherSplices.selfBuildBuild;
pkgsBuildHost = otherSplices.selfBuildHost;
pkgsBuildTarget = otherSplices.selfBuildTarget;
pkgsHostHost = otherSplices.selfHostHost;
pkgsHostTarget = self; # Not `otherSplices.selfHostTarget`;
pkgsTargetTarget = otherSplices.selfTargetTarget;
} // keep self;
};
spliced = extra spliced0 // spliced0 // keep self;
self = f self // {
newScope = scope: newScope (spliced // scope);
callPackage = newScope spliced; # == self.newScope {};
Expand All @@ -239,6 +240,7 @@ rec {
newScope
otherSplices
keep
extra
(lib.fixedPoints.extends g f);
packages = f;
};
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/interpreters/python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ with pkgs;
recursivePthLoader
;
};
extra = _: {};
optionalExtensions = cond: as: if cond then as else [];
python2Extension = import ../../../top-level/python2-packages.nix;
extensions = lib.composeManyExtensions ((optionalExtensions (!self.isPy3k) [python2Extension]) ++ [ overrides ]);
Expand All @@ -77,6 +78,7 @@ with pkgs;
pkgs.newScope
otherSplices
keep
extra
(lib.extends extensions pythonPackagesFun))
{
overrides = packageOverrides;
Expand Down
49 changes: 28 additions & 21 deletions pkgs/os-specific/darwin/apple-source-releases/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{ lib, stdenv, fetchurl, fetchzip, pkgs }:
{ lib, stdenv, stdenvNoCC, fetchurl, fetchzip, pkgs }:

let
macosPackages_11_0_1 = import ./macos-11.0.1.nix { inherit applePackage'; };
developerToolsPackages_11_3_1 = import ./developer-tools-11.3.1.nix { inherit applePackage'; };

# This attrset can in theory be computed automatically, but for that to work nicely we need
# import-from-derivation to work properly. Currently it's rather ugly when we try to bootstrap
# a stdenv out of something like this. With some care we can probably get rid of this, but for
Expand Down Expand Up @@ -190,17 +187,6 @@ let
}) // (attrs.meta or {});
});

applePackage' = namePath: version: sdkName: sha256: let
pname = builtins.head (lib.splitString "/" namePath);
appleDerivation = appleDerivation' pname version sdkName sha256;
callPackage = pkgs.newScope (packages // pkgs.darwin // { inherit appleDerivation; });
in callPackage (./. + "/${namePath}");

applePackage = namePath: sdkName: sha256: let
pname = builtins.head (lib.splitString "/" namePath);
version = versions.${sdkName}.${pname};
in applePackage' namePath version sdkName sha256;

IOKitSpecs = {
IOAudioFamily = fetchApple "osx-10.10.5" "0ggq7za3iq8g02j16rj67prqhrw828jsw3ah3bxq8a1cvr55aqnq";
IOFireWireFamily = fetchApple "osx-10.10.5" "059qa1m668kwvchl90cqcx35b31zaqdg61zi11y1imn5s389y2g1";
Expand All @@ -225,11 +211,35 @@ let

IOKitSrcs = lib.mapAttrs (name: value: if lib.isFunction value then value name else value) IOKitSpecs;

in

# darwin package set
self:

let
macosPackages_11_0_1 = import ./macos-11.0.1.nix { inherit applePackage'; };
developerToolsPackages_11_3_1 = import ./developer-tools-11.3.1.nix { inherit applePackage'; };

applePackage' = namePath: version: sdkName: sha256:
let
pname = builtins.head (lib.splitString "/" namePath);
appleDerivation = appleDerivation' pname version sdkName sha256;
callPackage = self.newScope { inherit appleDerivation; };
in callPackage (./. + "/${namePath}");

applePackage = namePath: sdkName: sha256: let
pname = builtins.head (lib.splitString "/" namePath);
version = versions.${sdkName}.${pname};
in applePackage' namePath version sdkName sha256;

# Only used for bootstrapping. It’s convenient because it was the last version to come with a real makefile.
adv_cmds-boot = applePackage "adv_cmds/boot.nix" "osx-10.5.8" "102ssayxbg9wb35mdmhswbnw0bg7js3pfd8fcbic83c5q3bqa6c6" {};

# TODO: shorten this list, we should cut down to a minimum set of bootstrap or necessary packages here.
stubPackages = {
in

developerToolsPackages_11_3_1 // macosPackages_11_0_1 // {
# TODO: shorten this list, we should cut down to a minimum set of bootstrap or necessary packages here.

inherit (adv_cmds-boot) ps locale;
architecture = applePackage "architecture" "osx-10.11.6" "1pbpjcd7is69hn8y29i98ci0byik826if8gnp824ha92h90w0fq3" {};
bsdmake = applePackage "bsdmake" "dev-tools-3.2.6" "11a9kkhz5bfgi1i8kpdkis78lhc6b5vxmhd598fcdgra1jw4iac2" {};
Expand Down Expand Up @@ -290,7 +300,4 @@ let
# TODO(matthewbauer):
# To be removed, once I figure out how to build a newer Security version.
Security = applePackage "Security/boot.nix" "osx-10.9.5" "1nv0dczf67dhk17hscx52izgdcyacgyy12ag0jh6nl5hmfzsn8yy" {};
};

packages = developerToolsPackages_11_3_1 // macosPackages_11_0_1 // stubPackages;
in packages
}
44 changes: 22 additions & 22 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ in rec {
'';
};

darwin = super.darwin // {
darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
Libsystem = stdenv.mkDerivation {
name = "bootstrap-stage0-Libsystem";
buildCommand = ''
mkdir -p $out
cp -r ${self.darwin.darwin-stubs}/usr/lib $out/lib
cp -r ${selfDarwin.darwin-stubs}/usr/lib $out/lib
chmod -R +w $out/lib
substituteInPlace $out/lib/libSystem.B.tbd --replace /usr/lib/system $out/lib/system
Expand All @@ -201,7 +201,7 @@ in rec {
'';
};

darwin-stubs = super.darwin.darwin-stubs.override { inherit (self) stdenv fetchurl; };
darwin-stubs = superDarwin.darwin-stubs.override { inherit (self) stdenv fetchurl; };

dyld = {
name = "bootstrap-stage0-dyld";
Expand All @@ -220,10 +220,10 @@ in rec {
nativeTools = false;
nativeLibc = false;
inherit (self) buildPackages coreutils gnugrep;
libc = self.pkgs.darwin.Libsystem;
libc = selfDarwin.Libsystem;
bintools = { name = "bootstrap-stage0-binutils"; outPath = bootstrapTools; };
};
};
});

llvmPackages_7 = {
clang-unwrapped = stdenv.mkDerivation {
Expand Down Expand Up @@ -291,12 +291,12 @@ in rec {
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // {
darwin = super.darwin.overrideScope (selfDarwin: _: {
binutils = darwin.binutils.override {
coreutils = self.coreutils;
libc = self.darwin.Libsystem;
libc = selfDarwin.Libsystem;
};
};
});
};
in with prevStage; stageFun 1 prevStage {
extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
Expand Down Expand Up @@ -337,11 +337,11 @@ in rec {
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // {
darwin = super.darwin.overrideScope (_: _: {
inherit (darwin)
binutils dyld Libsystem xnu configd ICU libdispatch libclosure
launchd CF darwin-stubs;
};
});
};
in with prevStage; stageFun 2 prevStage {
extraPreHook = ''
Expand Down Expand Up @@ -382,11 +382,11 @@ in rec {
});
in { inherit libraries; } // libraries);

darwin = super.darwin // {
darwin = super.darwin.overrideScope (_: _: {
inherit (darwin)
dyld Libsystem xnu configd libdispatch libclosure launchd libiconv
locale darwin-stubs;
};
});
};
in with prevStage; stageFun 3 prevStage {
shell = "${pkgs.bash}/bin/bash";
Expand Down Expand Up @@ -442,14 +442,14 @@ in rec {
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // rec {
darwin = super.darwin.overrideScope (_: superDarwin: {
inherit (darwin) dyld Libsystem libiconv locale darwin-stubs;

CF = super.darwin.CF.override {
CF = superDarwin.CF.override {
inherit libxml2;
python3 = prevStage.python3;
};
};
});
};
in with prevStage; stageFun 4 prevStage {
shell = "${pkgs.bash}/bin/bash";
Expand Down Expand Up @@ -480,11 +480,11 @@ in rec {
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // {
darwin = super.darwin.overrideScope (_: _: {
inherit (darwin) dyld ICU Libsystem libiconv;
} // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
inherit (darwin) binutils binutils-unwrapped cctools;
};
});
} // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
# Need to get rid of these when cross-compiling.
inherit binutils binutils-unwrapped;
Expand Down Expand Up @@ -537,14 +537,14 @@ in rec {
]);

overrides = lib.composeExtensions persistent (self: super: {
darwin = super.darwin.overrideScope (_: superDarwin: {
inherit (prevStage.darwin) CF darwin-stubs;
xnu = superDarwin.xnu.override { inherit (prevStage) python3; };
});
} // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
clang = cc;
llvmPackages = super.llvmPackages // { clang = cc; };
inherit cc;

darwin = super.darwin // {
inherit (prevStage.darwin) CF darwin-stubs;
xnu = super.darwin.xnu.override { inherit (prevStage) python3; };
};
});
};

Expand Down
22 changes: 11 additions & 11 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10395,15 +10395,7 @@ in
# The GCC used to build libc for the target platform. Normal gccs will be
# built with, and use, that cross-compiled libc.
gccCrossStageStatic = assert stdenv.targetPlatform != stdenv.hostPlatform; let
libcCross1 =
if stdenv.targetPlatform.libc == "msvcrt" then targetPackages.windows.mingw_w64_headers
else if stdenv.targetPlatform.libc == "libSystem" then darwin.xcode
else if stdenv.targetPlatform.libc == "nblibc" then netbsd.headers
else null;
binutils1 = wrapBintoolsWith {
bintools = binutils-unwrapped;
libc = libcCross1;
};
libcCross1 = binutilsNoLibc.libc;
in wrapCCWith {
cc = gccFun {
# copy-pasted
Expand All @@ -10416,10 +10408,10 @@ in
crossStageStatic = true;
langCC = false;
libcCross = libcCross1;
targetPackages.stdenv.cc.bintools = binutils1;
targetPackages.stdenv.cc.bintools = binutilsNoLibc;
enableShared = false;
};
bintools = binutils1;
bintools = binutilsNoLibc;
libc = libcCross1;
extraPackages = [];
};
Expand Down Expand Up @@ -12532,6 +12524,14 @@ in
gold = false;
};
});
binutilsNoLibc = wrapBintoolsWith {
bintools = binutils-unwrapped;
libc =
/**/ if stdenv.targetPlatform.libc == "msvcrt" then targetPackages.windows.mingw_w64_headers
else if stdenv.targetPlatform.libc == "libSystem" then darwin.xcode
else if stdenv.targetPlatform.libc == "nblibc" then targetPackages.netbsdCross.headers
else null;
};

bison = callPackage ../development/tools/parsing/bison { };

Expand Down
Loading

0 comments on commit 470640e

Please sign in to comment.