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 <nixpkgs> {
  crossSystem = {
    config = "x86_64-apple-darwin13";
    arch = "x86_64";
    libc = "libSystem";
    platform = {};
  };
}).hello.crossDrv

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
aszlig 2014-03-10 04:10:34 +01:00
parent dd10bb3181
commit 9a0a85827c
No known key found for this signature in database
GPG key ID: D0EBD0EC8C2DC961
2 changed files with 19 additions and 8 deletions

View file

@ -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

View file

@ -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;