Skip to content

Commit

Permalink
gcc: native aarch64-darwin support
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed May 11, 2021
1 parent d67b19f commit 4aa95e3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
6 changes: 4 additions & 2 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,16 @@ stdenv.mkDerivation {
# Always add -march based on cpu in triple. Sometimes there is a
# discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in
# that case.
+ optionalString ((targetPlatform ? gcc.arch) &&
# TODO: aarch64-darwin has mcpu incompatible with gcc
+ optionalString ((targetPlatform ? gcc.arch) && (isClang || !(stdenv.isDarwin && stdenv.isAarch64)) &&
isGccArchSupported targetPlatform.gcc.arch) ''
echo "-march=${targetPlatform.gcc.arch}" >> $out/nix-support/cc-cflags-before
''

# -mcpu is not very useful. You should use mtune and march
# instead. It’s provided here for backwards compatibility.
+ optionalString (targetPlatform ? gcc.cpu) ''
# TODO: aarch64-darwin has mcpu incompatible with gcc
+ optionalString ((targetPlatform ? gcc.cpu) && (isClang || !(stdenv.isDarwin && stdenv.isAarch64))) ''
echo "-mcpu=${targetPlatform.gcc.cpu}" >> $out/nix-support/cc-cflags-before
''

Expand Down
23 changes: 14 additions & 9 deletions pkgs/development/compilers/gcc/11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ let majorVersion = "11";
++ optional langFortran ../gfortran-driving.patch
++ optional (targetPlatform.libc == "musl" && targetPlatform.isPower) ../ppc-musl.patch

++ optional (stdenv.isDarwin && stdenv.isAarch64) (fetchpatch {
url = "https://github.com/fxcoudert/gcc/compare/releases/gcc-11.1.0...gcc-11.1.0-arm-20210504.diff";
sha256 = "sha256-JqCGJAfbOxSmkNyq49aFHteK/RFsCSLQrL9mzUCnaD0=";
})

# Obtain latest patch with ../update-mcfgthread-patches.sh
++ optional (!crossStageStatic && targetPlatform.isMinGW) ./Added-mcf-thread-model-support-from-mcfgthread.patch;

Expand Down Expand Up @@ -103,9 +108,15 @@ stdenv.mkDerivation ({

hardeningDisable = [ "format" "pie" ];

postPatch = ''
configureScripts=$(find . -name configure)
for configureScript in $configureScripts; do
patchShebangs $configureScript
done
''
# This should kill all the stdinc frameworks that gcc and friends like to
# insert into default search paths.
prePatch = lib.optionalString hostPlatform.isDarwin ''
+ lib.optionalString hostPlatform.isDarwin ''
substituteInPlace gcc/config/darwin-c.c \
--replace 'if (stdinc)' 'if (0)'
Expand All @@ -114,14 +125,8 @@ stdenv.mkDerivation ({
substituteInPlace libgfortran/configure \
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
'';

postPatch = ''
configureScripts=$(find . -name configure)
for configureScript in $configureScripts; do
patchShebangs $configureScript
done
'' + (
''
+ (
if targetPlatform != hostPlatform || stdenv.cc.libc != null then
# On NixOS, use the right path to the dynamic linker instead of
# `/lib/ld*.so'.
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ let
++ lib.optional javaAwtGtk "--enable-java-awt=gtk"
++ lib.optional (langJava && javaAntlr != null) "--with-antlr-jar=${javaAntlr}"

++ (import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; })
# TODO: aarch64-darwin has clang stdenv and its arch and cpu flag values are incompatible with gcc
++ lib.optional (!(stdenv.isDarwin && stdenv.isAarch64)) (import ../common/platform-flags.nix { inherit (stdenv) targetPlatform; inherit lib; })
++ lib.optionals (targetPlatform != hostPlatform) crossConfigureFlags
++ lib.optional (targetPlatform != hostPlatform) "--disable-bootstrap"

Expand Down
10 changes: 7 additions & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10350,7 +10350,9 @@ in
else ../development/compilers/gcc/10);
gcc = if (with stdenv.targetPlatform; isVc4 || libc == "relibc")
then gcc6 else
if stdenv.targetPlatform.isAarch64 then gcc9 else gcc10;
# aarch64-darwin doesn't support earlier gcc
if (stdenv.targetPlatform.isAarch64 && stdenv.isDarwin) then gcc11
else if stdenv.targetPlatform.isAarch64 then gcc9 else gcc10;
gcc-unwrapped = gcc.cc;

gccStdenv = if stdenv.cc.isGNU then stdenv else stdenv.override {
Expand Down Expand Up @@ -10562,7 +10564,8 @@ in

gcc_latest = gcc11;

gfortran = gfortran9;
# aarch64-darwin doesn't support earlier gcc
gfortran = if (stdenv.isDarwin && stdenv.isAarch64) then gfortran11 else gfortran9;

gfortran48 = wrapCC (gcc48.cc.override {
name = "gfortran";
Expand Down Expand Up @@ -10650,7 +10653,8 @@ in
inherit (gnome2) libart_lgpl;
});

gnat = gnat9;
# aarch64-darwin doesn't support earlier gcc
gnat = if (stdenv.isDarwin && stdenv.isAarch64) then gnat11 else gnat9;

gnat6 = wrapCC (gcc6.cc.override {
name = "gnat";
Expand Down

0 comments on commit 4aa95e3

Please sign in to comment.