summary refs log tree commit diff
diff options
context:
space:
mode:
authorIvan Babrou <github@ivan.computer>2021-03-16 21:27:34 -0700
committerGitHub <noreply@github.com>2021-03-17 00:27:34 -0400
commita730703e6f48d0d3189dc21115d7f8b9495489e5 (patch)
tree12465dca6dfbf026816e1fef2b3508aa1b519e74
parenteffe752c6113a70b487248c56861d90e8b14ac15 (diff)
downloadnixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar.gz
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar.bz2
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar.lz
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar.xz
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.tar.zst
nixpkgs-a730703e6f48d0d3189dc21115d7f8b9495489e5.zip
darwin.binutils: use clang for as on aarch64-darwin (#115167)
Without this change `as` on `aarch64-darwin` is defunct:

```
$ /nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/bin/as -v
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/bin/as: assembler (/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/arm64/as or /nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/arm64/as) for architecture arm64 not installed
Installed assemblers are:
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/ppc64/as for architecture ppc64
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/x86_64/as for architecture x86_64
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/ppc/as for architecture ppc
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/i386/as for architecture i386
/nix/store/g11xba8ch20zndaf32hfnap46z47b5k3-cctools-port-949.0.1/libexec/as/arm/as for architecture arm
```

Apple defaults to Clang in all cases from what I see, but nixpkgs prefers `cctools`: #51881.
-rw-r--r--pkgs/os-specific/darwin/binutils/default.nix13
-rw-r--r--pkgs/top-level/darwin-packages.nix2
2 files changed, 13 insertions, 2 deletions
diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix
index e9aa706da2d..29ae1871ddb 100644
--- a/pkgs/os-specific/darwin/binutils/default.nix
+++ b/pkgs/os-specific/darwin/binutils/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, binutils-unwrapped, cctools, llvm }:
+{ lib, stdenv, makeWrapper, binutils-unwrapped, cctools, llvm, clang-unwrapped }:
 
 # Make sure both underlying packages claim to have prepended their binaries
 # with the same targetPrefix.
@@ -49,8 +49,19 @@ stdenv.mkDerivation {
         ln -sv "$path" "$dest_path"
       done
     done
+  ''
+  # On aarch64-darwin we must use clang, because "as" from cctools just doesn't
+  # handle the arch. Proxying calls to clang produces quite a bit of warnings,
+  # and using clang directly here is a better option than relying on cctools.
+  # On x86_64-darwin the Clang version is too old to support this mode.
+  + lib.optionalString stdenv.isAarch64 ''
+    rm $out/bin/as
+    makeWrapper "${clang-unwrapped}/bin/clang" "$out/bin/as" \
+      --add-flags "-x assembler -integrated-as -c"
   '';
 
+  nativeBuildInputs = lib.optionals stdenv.isAarch64 [ makeWrapper ];
+
   passthru = {
     inherit targetPrefix;
   };
diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix
index 2197f128388..3ece95c5845 100644
--- a/pkgs/top-level/darwin-packages.nix
+++ b/pkgs/top-level/darwin-packages.nix
@@ -23,7 +23,7 @@ in
   binutils-unwrapped = callPackage ../os-specific/darwin/binutils {
     inherit (darwin) cctools;
     inherit (pkgs) binutils-unwrapped;
-    inherit (pkgs.llvmPackages_7) llvm;
+    inherit (pkgs.llvmPackages_7) llvm clang-unwrapped;
   };
 
   binutils = pkgs.wrapBintoolsWith {