From 9a0a85827c3bc903d7c82f251fa129e91f457e85 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 10 Mar 2014 04:10:34 +0100 Subject: [PATCH] gcc-4.8: Hook in cross-darwin libc and binutils. Let's finally hook everything into the existing cross-building infrastructure. We're using --with-sysroot instead of --with-headers here, because the XCode SDK contains references to /usr/lib. I've tried to patch those references, but unfortunately (at least with install_name_tool) it isn't possible to change those refernces in stub dylibs. So after bugging @tpoechtrager with annoying questions (thanks again), I think my initial approach (patching the SDK itself and/or regenerating the dylib stubs) was way to complicated so I ended up with this implementation. Also, I've added a condition to binutilsCross to use cctools if the libc is set to libSystem. This might need some cleanups someday, mainly to figure out how to properly bridge cctools and binutils. So, as an example on how to cross-compile GNU Hello to Darwin, you can use something like this: (import { crossSystem = { config = "x86_64-apple-darwin13"; arch = "x86_64"; libc = "libSystem"; platform = {}; }; }).hello.crossDrv Signed-off-by: aszlig --- pkgs/development/compilers/gcc/4.8/default.nix | 10 ++++++++-- pkgs/top-level/all-packages.nix | 17 +++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index aea525933234..8a8a80c090ad 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -117,7 +117,8 @@ let version = "4.8.2"; withMode; /* Cross-gcc settings */ - crossMingw = (cross != null && cross.libc == "msvcrt"); + crossMingw = cross != null && cross.libc == "msvcrt"; + crossDarwin = cross != null && cross.libc == "libSystem"; crossConfigureFlags = let gccArch = stdenv.cross.gcc.arch or null; gccCpu = stdenv.cross.gcc.cpu or null; @@ -161,7 +162,12 @@ let version = "4.8.2"; " --disable-shared" + " --disable-decimal-float" # libdecnumber requires libc else - " --with-headers=${libcCross}/include" + + (if crossDarwin then + " --with-sysroot=${libcCross}/share/sysroot" + + " --with-as=${binutilsCross}/bin/${cross.config}-as" + + " --with-ld=${binutilsCross}/bin/${cross.config}-ld" + else + " --with-headers=${libcCross}/include") + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dfe977678ffd..f65d493b9d6a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2430,8 +2430,10 @@ let gccCrossStageStatic = let isMingw = (stdenv.cross.libc == "msvcrt"); isMingw64 = isMingw && stdenv.cross.config == "x86_64-w64-mingw32"; + isDarwin = stdenv.cross.libc == "libSystem"; libcCross1 = if isMingw64 then windows.mingw_w64_headers else - if isMingw then windows.mingw_headers1 else null; + if isMingw then windows.mingw_headers1 else + if isDarwin then darwin.xcode else null; in wrapGCCCross { gcc = forceNativeDrv (lib.addMetaAttrs { hydraPlatforms = []; } ( @@ -3452,11 +3454,13 @@ let gold = false; }); - binutilsCross = lowPrio (forceNativeDrv (import ../development/tools/misc/binutils { - inherit stdenv fetchurl zlib; - noSysDirs = true; - cross = assert crossSystem != null; crossSystem; - })); + binutilsCross = + if crossSystem != null && crossSystem.libc == "libSystem" then darwin.cctools + else lowPrio (forceNativeDrv (import ../development/tools/misc/binutils { + inherit stdenv fetchurl zlib; + noSysDirs = true; + cross = assert crossSystem != null; crossSystem; + })); bison2 = callPackage ../development/tools/parsing/bison/2.x.nix { }; bison3 = callPackage ../development/tools/parsing/bison/3.x.nix { }; @@ -4249,6 +4253,7 @@ let else if name == "msvcrt" && stdenv.cross.config == "x86_64-w64-mingw32" then windows.mingw_w64 else if name == "msvcrt" then windows.mingw_headers3 + else if name == "libSystem" then darwin.xcode else throw "Unknown libc"; libcCross = assert crossSystem != null; libcCrossChooser crossSystem.libc;