Unverified Commit e5182111 authored by Randy Eckenrode's avatar Randy Eckenrode Committed by GitHub
Browse files

pkgs/stdenv/darwin: bootstrap Darwin using update tools (#384254)

parents b0f809f1 069f2754
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
let
  # This can be made unconditional once jq is available in the bootstrap tools. If corecrypto is  not removed from
  # the umbrella framework, linking will fail in stage 1 because it can’t find the tbd.
  disallowedPackages' = builtins.fromJSON (builtins.readFile ../metadata/disallowed-packages.json);
  disallowedPackages = builtins.fromJSON (builtins.readFile ../metadata/disallowed-packages.json);
in

{
@@ -10,13 +8,6 @@ in
  stdenv,
}:

let
  disallowedPackages =
    if jq == null then
      lib.filter (p: p.package != "corecrypto") disallowedPackages'
    else
      disallowedPackages';
in
self: super: {
  # Remove headers and stubs for packages that are available in nixpkgs.
  buildPhase =
+1 −5
Original line number Diff line number Diff line
@@ -36,12 +36,8 @@ let
      (callPackage ./common/passthru-private-frameworks.nix { inherit sdkVersion; })
      (callPackage ./common/passthru-source-release-files.nix { inherit sdkVersion; })
      (callPackage ./common/remove-disallowed-packages.nix { })
      (callPackage ./common/process-stubs.nix { })
    ]
    # Only process stubs and convert them to tbd-v4 if jq is available. This can be made unconditional once
    # the bootstrap tools have jq and llvm-readtapi.
    ++ lib.optional (jq != null && lib.getName llvm != "bootstrap-stage0-llvm") (
      callPackage ./common/process-stubs.nix { }
    )
    # Avoid infinite recursions by not propagating certain packages, so they can themselves build with the SDK.
    ++ lib.optionals (!enableBootstrap) [
      (callPackage ./common/propagate-inputs.nix { })
+22 −39
Original line number Diff line number Diff line
@@ -15,10 +15,6 @@
}:

let
  # ld64 uses `#embed` to embed `compile_stubs`, which is only implemented in Clang 19.
  # This can be done unconditionally once the bootstrap tools have been updated.
  hasEmbed = lib.versionAtLeast (lib.getVersion stdenv.cc) "19";

  # Copy the files from their original sources instead of using patches to reduce the size of the patch set in nixpkgs.
  otherSrcs = {
    # The last version of ld64 to have dyldinfo
@@ -55,11 +51,11 @@ stdenv.mkDerivation (finalAttrs: {
    hash = "sha256-CVIyL2J9ISZnI4+r+wp4QtOb3+3Tmz2z2Z7/qeRqHS0=";
  };

  patches =
    [
  patches = [
    # These patches are vendored from https://github.com/reckenrode/ld64/tree/ld64-951.9-nixpkgs.
    # See their comments for more on what they do.
    ./patches/0001-Always-use-write-instead-of-mmap.patch
    ./patches/0002-Add-compile_stubs.h-using-Clang-s-embed-extension-fo.patch
    ./patches/0003-Inline-missing-definitions-instead-of-using-private-.patch
    ./patches/0004-Removed-unused-Blob-clone-method.patch
    ./patches/0005-Use-std-atomics-and-std-mutex-for-portability.patch
@@ -76,9 +72,6 @@ stdenv.mkDerivation (finalAttrs: {
    ./patches/0016-Add-dyldinfo-to-the-ld64-build.patch
    ./patches/0017-Fix-dyldinfo-build.patch
    ./patches/0018-Use-STL-containers-instead-of-LLVM-containers.patch
    ]
    ++ lib.optionals (hasEmbed) [
      ./patches/0002-Add-compile_stubs.h-using-Clang-s-embed-extension-fo.patch
  ];

  prePatch = ''
@@ -106,16 +99,6 @@ stdenv.mkDerivation (finalAttrs: {
    done
  '';

  # Clang 16 doesn’t support C23, but the patchset expects a compiler that supports it. Only `#embed` is used, so stub
  # out its usage and request an older C standard version. This can be dropped once the bootstrap tools are updated.
  postPatch = lib.optionalString (!hasEmbed) ''
    for meson_build in meson.build subprojects/libcodedirectory/meson.build subprojects/libtapi/meson.build; do
      substituteInPlace $meson_build --replace-fail c23 c2x
    done
    echo '#pragma once' > src/ld/compile_stubs.h
    echo 'static const char compile_stubs[] = "";' >> src/ld/compile_stubs.h
  '';

  xcodeHash = "sha256-qip/1eiGn8PdLThonhPq3oq2veN4E1zOiamDPBfTeNE=";
  xcodeProject = "ld64.xcodeproj";

+0 −4
Original line number Diff line number Diff line
@@ -78,10 +78,6 @@ mkAppleDerivation {
        --replace-fail '__ptrcheck_abi_assume_single()' "" \
        --replace-fail '__unsafe_indexable' ""
    done

    # clang 16 does not support C23 empty initializers. This can be removed once the bootstrap tools are updated.
    substituteInPlace copyfile.c \
      --replace-fail 'filesec_t fsec_tmp = {};' 'filesec_t fsec_tmp = {0};'
  '';

  env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
+0 −17
Original line number Diff line number Diff line
{
  writeTextFile,
  cctools,
  sigtool,
}:

writeTextFile {
  name = "post-link-sign-hook";
  executable = true;

  text = ''
    if [ "$linkerOutput" != "/dev/null" ]; then
      CODESIGN_ALLOCATE=${cctools}/bin/${cctools.targetPrefix}codesign_allocate \
        ${sigtool}/bin/codesign -f -s - "$linkerOutput"
    fi
  '';
}
Loading