about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/darwin/cctools
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/os-specific/darwin/cctools')
-rw-r--r--nixpkgs/pkgs/os-specific/darwin/cctools/darwin-memstream.patch (renamed from nixpkgs/pkgs/os-specific/darwin/cctools/darwin-no-memstream.patch)6
-rw-r--r--nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/darwin/cctools/port.nix10
3 files changed, 21 insertions, 14 deletions
diff --git a/nixpkgs/pkgs/os-specific/darwin/cctools/darwin-no-memstream.patch b/nixpkgs/pkgs/os-specific/darwin/cctools/darwin-memstream.patch
index bb8a4ad68f3b..3e0d0a43ba8d 100644
--- a/nixpkgs/pkgs/os-specific/darwin/cctools/darwin-no-memstream.patch
+++ b/nixpkgs/pkgs/os-specific/darwin/cctools/darwin-memstream.patch
@@ -1,7 +1,3 @@
-MacOS SDKs before 10.13 don't support open_memstream. This is already replaced
-by a runtime check in cctools-port, but because we build with SDK 10.12 by
-default, linking still fails for us. Disable it entirely here.
-
 --- a/cctools/include/stuff/diagnostics.h
 +++ b/cctools/include/stuff/diagnostics.h
 @@ -60,13 +60,6 @@ void diagnostics_log_msg(enum diagnostic_level level, const char* message);
@@ -16,6 +12,6 @@ default, linking still fails for us. Disable it entirely here.
 -#ifndef HAVE_OPENMEMSTREAM_RUNTIME
 -#  define HAVE_OPENMEMSTREAM_RUNTIME 1
 -#endif
-+#define HAVE_OPENMEMSTREAM_RUNTIME 0
++#define HAVE_OPENMEMSTREAM_RUNTIME 1
  
  #endif /* diagnostics_h */
diff --git a/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix b/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix
index 11ec2b4d04fa..f2986bf872f7 100644
--- a/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix
+++ b/nixpkgs/pkgs/os-specific/darwin/cctools/llvm.nix
@@ -1,9 +1,11 @@
 # Create a cctools-compatible bintools that uses equivalent tools from LLVM in place of the ones
 # from cctools when possible.
 
-{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? true }:
+{ lib, stdenv, makeWrapper, cctools-port, llvmPackages, enableManpages ? stdenv.targetPlatform == stdenv.hostPlatform }:
 
 let
+  inherit (stdenv) targetPlatform hostPlatform;
+
   cctoolsVersion = lib.getVersion cctools-port;
   llvmVersion = llvmPackages.release_version;
 
@@ -18,6 +20,10 @@ let
   # not appear to have issues, but the source is not available yet (as of June 2023).
   useLLVMStrip = lib.versionAtLeast llvmVersion "15" || lib.versionAtLeast cctoolsVersion "1005.2";
 
+  # Clang 11 performs an optimization on x86_64 that is sensitive to the presence of debug info.
+  # This causes GCC to fail to bootstrap due to object file differences between stages 2 and 3.
+  useClangAssembler = lib.versionAtLeast llvmVersion "12" || !stdenv.isx86_64;
+
   llvm_bins = [
     "dwarfdump"
     "nm"
@@ -50,9 +56,10 @@ let
   ]
   ++ lib.optional (!useLLVMBitcodeStrip) "bitcode_strip"
   ++ lib.optional (!useLLVMOtool) "otool"
-  ++ lib.optional (!useLLVMStrip) "strip";
+  ++ lib.optional (!useLLVMStrip) "strip"
+  ++ lib.optional (!useClangAssembler) "as";
 
-  inherit (stdenv.cc) targetPrefix;
+  targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
 
   linkManPages = pkg: source: target: lib.optionalString enableManpages ''
     sourcePath=${pkg}/share/man/man1/${source}.1.gz
@@ -77,11 +84,13 @@ stdenv.mkDerivation {
     mkdir -p "$out/bin" "$man"
     ln -s ${lib.getDev cctools-port} "$dev"
 
+  '' + lib.optionalString useClangAssembler ''
     # Use the clang-integrated assembler instead of using `as` from cctools.
     makeWrapper "${lib.getBin llvmPackages.clang-unwrapped}/bin/clang" "$out/bin/${targetPrefix}as" \
       --add-flags "-x assembler -integrated-as -c"
 
-    ln -s "${lib.getBin llvmPackages.bintools-unwrapped}/bin/llvm-ar" "$out/bin/${targetPrefix}ar"
+  '' + ''
+    ln -s "${lib.getBin llvmPackages.bintools-unwrapped}/bin/${targetPrefix}llvm-ar" "$out/bin/${targetPrefix}ar"
     ${linkManPages llvmPackages.llvm-manpages "llvm-ar" "ar"}
 
     for tool in ${toString llvm_bins}; do
@@ -97,7 +106,7 @@ stdenv.mkDerivation {
 
     ${linkManPages (lib.getMan cctools-port) "ld64" "ld64"}
     ${lib.optionalString (!useLLVMOtool)  # The actual man page for otool in cctools is llvm-otool
-      linkManPages (lib.getMan cctools-port) "llvm-otool" "llvm-otool"}
+      (linkManPages (lib.getMan cctools-port) "llvm-otool" "llvm-otool")}
   '';
 
   passthru = { inherit targetPrefix; };
diff --git a/nixpkgs/pkgs/os-specific/darwin/cctools/port.nix b/nixpkgs/pkgs/os-specific/darwin/cctools/port.nix
index 4d8079977513..c9b11ee20155 100644
--- a/nixpkgs/pkgs/os-specific/darwin/cctools/port.nix
+++ b/nixpkgs/pkgs/os-specific/darwin/cctools/port.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook
+{ lib, stdenv, fetchFromGitHub, autoconf, automake, libtool, autoreconfHook, memstreamHook
 , installShellFiles
 , libuuid
 , libobjc ? null, maloader ? null
@@ -35,7 +35,8 @@ stdenv.mkDerivation {
 
   outputs = [ "out" "dev" "man" ];
 
-  nativeBuildInputs = [ autoconf automake libtool autoreconfHook installShellFiles ];
+  nativeBuildInputs = [ autoconf automake libtool autoreconfHook installShellFiles ]
+    ++ lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ memstreamHook ];
   buildInputs = [ libuuid ]
     ++ lib.optionals stdenv.isDarwin [ libobjc ]
     ++ lib.optional enableTapiSupport libtapi;
@@ -51,8 +52,9 @@ stdenv.mkDerivation {
       url = "https://github.com/MercuryTechnologies/cctools-port/commit/025899b7b3593dedb0c681e689e57c0e7bbd9b80.patch";
       hash = "sha256-SWVUzFaJHH2fu9y8RcU3Nx/QKx60hPE5zFx0odYDeQs=";
     })
-  ]
-    ++ lib.optional stdenv.isDarwin ./darwin-no-memstream.patch;
+    # Always use `open_memstream`. This is provided by memstream via hook on x86_64-darwin.
+    ./darwin-memstream.patch
+  ];
 
   __propagatedImpureHostDeps = [
     # As far as I can tell, otool from cctools is the only thing that depends on these two, and we should fix them