Merge pull request #105026 from thefloweringash/apple-silicon

Native support for Apple Silicon
This commit is contained in:
Jonathan Ringer
2021-05-16 11:38:18 -07:00
committed by GitHub
101 changed files with 2498 additions and 315 deletions
+36 -9
View File
@@ -30,7 +30,18 @@ in
# just the plain stdenv.
stdenv_32bit = lowPrio (if stdenv.hostPlatform.is32bit then stdenv else multiStdenv);
stdenvNoCC = stdenv.override { cc = null; hasCC = false; };
stdenvNoCC = stdenv.override (
{ cc = null; hasCC = false; }
// lib.optionalAttrs (stdenv.hostPlatform.isDarwin && (stdenv.hostPlatform != stdenv.buildPlatform)) {
# TODO: This is a hack to use stdenvNoCC to produce a CF when cross
# compiling. It's not very sound. The cross stdenv has:
# extraBuildInputs = [ targetPackages.darwin.apple_sdks.frameworks.CoreFoundation ]
# and uses stdenvNoCC. In order to make this not infinitely recursive, we need to exclude
# this extraBuildInput.
extraBuildInputs = [];
}
);
mkStdenvNoLibs = stdenv: let
bintools = stdenv.cc.bintools.override {
@@ -627,11 +638,15 @@ in
replaceDependency = callPackage ../build-support/replace-dependency.nix { };
nukeReferences = callPackage ../build-support/nuke-references { };
nukeReferences = callPackage ../build-support/nuke-references {
inherit (darwin) signingUtils;
};
referencesByPopularity = callPackage ../build-support/references-by-popularity { };
removeReferencesTo = callPackage ../build-support/remove-references-to { };
removeReferencesTo = callPackage ../build-support/remove-references-to {
inherit (darwin) signingUtils;
};
vmTools = callPackage ../build-support/vm { };
@@ -641,7 +656,9 @@ in
setJavaClassPath = makeSetupHook { } ../build-support/setup-hooks/set-java-classpath.sh;
fixDarwinDylibNames = makeSetupHook { } ../build-support/setup-hooks/fix-darwin-dylib-names.sh;
fixDarwinDylibNames = makeSetupHook {
substitutions = { inherit (binutils) targetPrefix; };
} ../build-support/setup-hooks/fix-darwin-dylib-names.sh;
keepBuildTree = makeSetupHook { } ../build-support/setup-hooks/keep-build-tree.sh;
@@ -6677,7 +6694,9 @@ in
mbutil = python3Packages.callPackage ../applications/misc/mbutil { };
mc = callPackage ../tools/misc/mc { };
mc = callPackage ../tools/misc/mc {
inherit (darwin) autoSignDarwinBinariesHook;
};
mcabber = callPackage ../applications/networking/instant-messengers/mcabber { };
@@ -9985,15 +10004,21 @@ in
any-nix-shell = callPackage ../shells/any-nix-shell { };
bash = lowPrio (callPackage ../shells/bash/4.4.nix { });
bash_5 = lowPrio (callPackage ../shells/bash/5.1.nix { });
bash = lowPrio (callPackage ../shells/bash/4.4.nix {
binutils = stdenv.cc.bintools;
});
bash_5 = lowPrio (callPackage ../shells/bash/5.1.nix {
binutils = stdenv.cc.bintools;
});
bashInteractive_5 = lowPrio (callPackage ../shells/bash/5.1.nix {
binutils = stdenv.cc.bintools;
interactive = true;
withDocs = true;
});
# WARNING: this attribute is used by nix-shell so it shouldn't be removed/renamed
bashInteractive = callPackage ../shells/bash/4.4.nix {
binutils = stdenv.cc.bintools;
interactive = true;
withDocs = true;
};
@@ -11223,7 +11248,7 @@ in
# This returns the minimum suported version for the platform. The
# assumption is that or any later version is good.
choose = platform:
/**/ if platform.isDarwin then 7
/**/ if platform.isDarwin then (if platform.isAarch64 then 11 else 7)
else if platform.isFreeBSD then 7
else if platform.isAndroid then 12
else if platform.isLinux then 7
@@ -11837,6 +11862,7 @@ in
noLibc = (self.libc == null);
inherit bintools libc;
inherit (darwin) postLinkSignHook signingUtils;
} // extraArgs; in self);
yaml-language-server = nodePackages.yaml-language-server;
@@ -14821,6 +14847,7 @@ in
inherit (stdenv.targetPlatform) libc;
in if libc == "msvcrt" then targetPackages.windows.mingw_w64_headers or windows.mingw_w64_headers
else if libc == "nblibc" then targetPackages.netbsdCross.headers or netbsdCross.headers
else if libc == "libSystem" && stdenv.targetPlatform.isAarch64 then targetPackages.darwin.LibsystemCross or darwin.LibsystemCross
else null;
# We can choose:
@@ -14840,7 +14867,7 @@ in
else if name == "libSystem" then
if stdenv.targetPlatform.useiOSPrebuilt
then targetPackages.darwin.iosSdkPkgs.libraries or darwin.iosSdkPkgs.libraries
else throw "don't yet have a `targetPackages.darwin.LibsystemCross`"
else targetPackages.darwin.LibsystemCross or (throw "don't yet have a `targetPackages.darwin.LibsystemCross for ${stdenv.targetPlatform.config}`")
else if name == "nblibc" then targetPackages.netbsdCross.libc or netbsdCross.libc
else if name == "wasilibc" then targetPackages.wasilibc or wasilibc
else if name == "relibc" then targetPackages.relibc or relibc
+87 -8
View File
@@ -14,6 +14,12 @@ let
selfTargetTarget = pkgsTargetTarget.darwin or {}; # might be missing
};
# Prefix for binaries. Customarily ends with a dash separator.
#
# TODO(@Ericson2314) Make unconditional, or optional but always true by
# default.
targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
(stdenv.targetPlatform.config + "-");
in
lib.makeScopeWithSplicing splicePackages newScope otherSplices (_: {}) (spliced: spliced.apple_sdk.frameworks) (self: let
@@ -21,17 +27,48 @@ lib.makeScopeWithSplicing splicePackages newScope otherSplices (_: {}) (spliced:
# Must use pkgs.callPackage to avoid infinite recursion.
apple-source-releases = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self;
# Open source packages that are built from source
appleSourcePackages = pkgs.callPackage ../os-specific/darwin/apple-source-releases { } self;
impure-cmds = pkgs.callPackage ../os-specific/darwin/impure-cmds { };
apple_sdk = pkgs.callPackage ../os-specific/darwin/apple-sdk {
# macOS 10.12 SDK
apple_sdk_10_12 = pkgs.callPackage ../os-specific/darwin/apple-sdk {
inherit (buildPackages.darwin) print-reexports;
inherit (self) darwin-stubs;
};
# macOS 11.0 SDK
apple_sdk_11_0 = pkgs.callPackage ../os-specific/darwin/apple-sdk-11.0 { };
# Pick an SDK
apple_sdk = if stdenv.hostPlatform.isAarch64 then apple_sdk_11_0 else apple_sdk_10_12;
# Pick the source of libraries: either Apple's open source releases, or the
# SDK.
useAppleSDKLibs = stdenv.hostPlatform.isAarch64;
selectAttrs = attrs: names:
lib.listToAttrs (lib.concatMap (n: if attrs ? "${n}" then [(lib.nameValuePair n attrs."${n}")] else []) names);
chooseLibs = (
# There are differences in which libraries are exported. Avoid evaluation
# errors when a package is not provided.
selectAttrs (
if useAppleSDKLibs
then apple_sdk
else appleSourcePackages
) ["Libsystem" "LibsystemCross" "libcharset" "libunwind" "objc4" "configd" "IOKit"]
) // {
inherit (
if useAppleSDKLibs
then apple_sdk.frameworks
else appleSourcePackages
) Security;
};
in
impure-cmds // apple-source-releases // {
impure-cmds // appleSourcePackages // chooseLibs // {
inherit apple_sdk;
@@ -41,7 +78,7 @@ impure-cmds // apple-source-releases // {
binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
inherit (pkgs) binutils-unwrapped;
inherit (pkgs.llvmPackages_7) llvm clang-unwrapped;
inherit (pkgs.llvmPackages) llvm clang-unwrapped;
};
binutils = pkgs.wrapBintoolsWith {
@@ -59,7 +96,6 @@ impure-cmds // apple-source-releases // {
cctools = callPackage ../os-specific/darwin/cctools/port.nix {
stdenv = if stdenv.isDarwin then stdenv else pkgs.libcxxStdenv;
libcxxabi = pkgs.libcxxabi;
};
# TODO: remove alias.
@@ -69,7 +105,31 @@ impure-cmds // apple-source-releases // {
darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { };
print-reexports = callPackage ../os-specific/darwin/apple-sdk/print-reexports { };
print-reexports = callPackage ../os-specific/darwin/print-reexports { };
rewrite-tbd = callPackage ../os-specific/darwin/rewrite-tbd { };
checkReexportsHook = pkgs.makeSetupHook {
deps = [ pkgs.darwin.print-reexports ];
} ../os-specific/darwin/print-reexports/setup-hook.sh;
sigtool = callPackage ../os-specific/darwin/sigtool { };
postLinkSignHook = pkgs.writeTextFile {
name = "post-link-sign-hook";
executable = true;
text = ''
CODESIGN_ALLOCATE=${targetPrefix}codesign_allocate \
${self.sigtool}/bin/codesign -f -s - "$linkerOutput"
'';
};
signingUtils = callPackage ../os-specific/darwin/signing-utils { };
autoSignDarwinBinariesHook = pkgs.makeSetupHook {
deps = [ self.signingUtils ];
} ../os-specific/darwin/signing-utils/auto-sign-hook.sh;
maloader = callPackage ../os-specific/darwin/maloader {
};
@@ -84,7 +144,7 @@ impure-cmds // apple-source-releases // {
iproute2mac = callPackage ../os-specific/darwin/iproute2mac { };
libobjc = apple-source-releases.objc4;
libobjc = self.objc4;
lsusb = callPackage ../os-specific/darwin/lsusb { };
@@ -105,7 +165,26 @@ impure-cmds // apple-source-releases // {
CoreSymbolication = callPackage ../os-specific/darwin/CoreSymbolication { };
CF = callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { };
# TODO: make swift-corefoundation build with apple_sdk_11_0.Libsystem
CF = if useAppleSDKLibs
then
# This attribute (CF) is included in extraBuildInputs in the stdenv. This
# is typically the open source project. When a project refers to
# "CoreFoundation" it has an extra setup hook to force impure system
# CoreFoundation into the link step.
#
# In this branch, we only have a single "CoreFoundation" to choose from.
# To be compatible with the existing convention, we define
# CoreFoundation with the setup hook, and CF as the same package but
# with the setup hook removed.
#
# This may seem unimportant, but without it packages (e.g., bacula) will
# fail with linker errors referring ___CFConstantStringClassReference.
# It's not clear to me why some packages need this extra setup.
lib.overrideDerivation apple_sdk.frameworks.CoreFoundation (drv: {
setupHook = null;
})
else callPackage ../os-specific/darwin/swift-corelibs/corefoundation.nix { };
# As the name says, this is broken, but I don't want to lose it since it's a direction we want to go in
# libdispatch-broken = callPackage ../os-specific/darwin/swift-corelibs/libdispatch.nix { };
+2
View File
@@ -27,6 +27,7 @@ rec {
pkgs_x86_64_linux = packageSet' { system = "x86_64-linux"; };
pkgs_i686_linux = packageSet' { system = "i686-linux"; };
pkgs_aarch64_linux = packageSet' { system = "aarch64-linux"; };
pkgs_aarch64_darwin = packageSet' { system = "aarch64-darwin"; };
pkgs_armv6l_linux = packageSet' { system = "armv6l-linux"; };
pkgs_armv7l_linux = packageSet' { system = "armv7l-linux"; };
pkgs_x86_64_darwin = packageSet' { system = "x86_64-darwin"; };
@@ -39,6 +40,7 @@ rec {
if system == "x86_64-linux" then pkgs_x86_64_linux
else if system == "i686-linux" then pkgs_i686_linux
else if system == "aarch64-linux" then pkgs_aarch64_linux
else if system == "aarch64-darwin" then pkgs_aarch64_darwin
else if system == "armv6l-linux" then pkgs_armv6l_linux
else if system == "armv7l-linux" then pkgs_armv7l_linux
else if system == "x86_64-darwin" then pkgs_x86_64_darwin
+9
View File
@@ -176,6 +176,15 @@ let
# Test a full stdenv bootstrap from the bootstrap tools definition
inherit (bootstrap.test-pkgs) stdenv;
};
# Cross compiled bootstrap tools
aarch64-darwin =
let
bootstrap = import ../stdenv/darwin/make-bootstrap-tools.nix { system = "x86_64-darwin"; crossSystem = "aarch64-darwin"; };
in {
# Distribution only for now
inherit (bootstrap) dist;
};
};
} // (mapTestOn ((packagePlatforms pkgs) // {