Commit 8950c056 authored by Rhys-T's avatar Rhys-T
Browse files

ldc: Fix compiler and output crashing on macOS Sequoia 15.4

Currently, programs built with LDC get a segfault on macOS 15.4, before
they've even reached `main`. (See ldc-developers/ldc#4899.) Upstream has
merged the fix, but it hasn't made it into a release yet. This commit
fixes the problem by:
- Downgrading the bootstrap compiler to 1.28.1, so that the final
  compiler itself can run correctly, and
- Backporting the `druntime` [fix][] into the final compiler, so that
  its _output_ can run correctly.

Resolves #398443, at least for `ldc`. `dmd` uses `druntime` as well,
and thus would have the same issue (dlang/dmd#21126), but it's currently
`broken` on Darwin for unrelated reasons, so I can't test any fix there.

[fix]: https://github.com/ldc-developers/ldc/commit/60079c3b596053b1a70f9f2e0cf38a287089df56
parent e79237cb
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -14,13 +14,17 @@ let
  OS = if hostPlatform.isDarwin then "osx" else hostPlatform.parsed.kernel.name;
  ARCH =
    if hostPlatform.isDarwin && hostPlatform.isAarch64 then "arm64" else hostPlatform.parsed.cpu.name;
  version = "1.30.0";
  # Work around macOS Sequoia 15.4 segfault by downgrading the bootstrap compiler - see:
  # - https://github.com/NixOS/nixpkgs/issues/398443
  # - https://github.com/dlang/dmd/issues/21126#issuecomment-2775948553
  # TODO: Remove this when bootstrap can be upgraded to a fixed version (>= 1.41.0-beta2)?
  version = if hostPlatform.isDarwin then "1.28.1" else "1.30.0";
  hashes = {
    # Get these from `nix store prefetch-file https://github.com/ldc-developers/ldc/releases/download/v1.19.0/ldc2-1.19.0-osx-x86_64.tar.xz` etc..
    osx-x86_64 = "sha256-AAWZvxuZC82xvrW6fpYm783TY+H8k3DvqE94ZF1yjmk=";
    osx-x86_64 = "sha256-mqQ+hNlDePOGX2mwgEEzHGiOAx3SxfNA6x8+ML3qYmw=";
    linux-x86_64 = "sha256-V4TUzEfQhFrwiX07dHOgjdAoGkzausCkhnQIQNAU/eE=";
    linux-aarch64 = "sha256-kTeglub75iv/jWWNPCn15aCGAbmck0RQl6L7bFOUu7Y=";
    osx-arm64 = "sha256-Nb/owBdIeroB9jLMDvwjo8bvsTC9vFyJPLMTOMsSAd4=";
    osx-arm64 = "sha256-m93rGywncBnPEWslcrXuGBnZ+Z/mNgLIaevkL/uBOu0=";
  };
in
stdenv.mkDerivation {
+12 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
  lib,
  stdenv,
  fetchFromGitHub,
  fetchpatch,
  callPackage,
  makeWrapper,
  removeReferencesTo,
@@ -45,6 +46,17 @@ stdenv.mkDerivation (finalAttrs: {
  # https://issues.dlang.org/show_bug.cgi?id=19553
  hardeningDisable = [ "fortify" ];

  # Fix output programs segfaulting on macOS Sequoia 15.4 - see:
  # https://github.com/NixOS/nixpkgs/issues/398443
  # https://github.com/ldc-developers/ldc/issues/4899
  # TODO: Remove this when upgrading to a fixed version (>= 1.41.0-beta2)
  patches = [
    (fetchpatch {
      url = "https://github.com/ldc-developers/ldc/commit/60079c3b596053b1a70f9f2e0cf38a287089df56.patch";
      hash = "sha256-Y/5+zt5ou9rzU7rLJq2OqUxMDvC7aSFS6AsPeDxNATQ=";
    })
  ];

  postPatch =
    ''
      patchShebangs runtime tools tests