From bfa8f3049989739223687324aec986d4da3b5dae Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Apr 2017 21:51:24 -0400 Subject: [PATCH 1/6] linux cross stdenv: Use the cross stdenv and `nativeBuildInputs` This is a cross derivation---it's built on one platform to run on another---so let's structure it like all the other cross derivations. --- pkgs/stdenv/linux/make-bootstrap-tools-cross.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix index b55f2bc7b7d..77471e6dfdb 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix @@ -146,11 +146,11 @@ rec { build = - pkgs.buildPackages.stdenv.mkDerivation { + pkgs.stdenv.mkDerivation { name = "stdenv-bootstrap-tools-cross"; crossConfig = pkgs.hostPlatform.config; - buildInputs = [ + nativeBuildInputs = [ pkgs.buildPackages.nukeReferences pkgs.buildPackages.cpio pkgs.buildPackages.binutils @@ -285,7 +285,7 @@ rec { allowedReferences = []; }; - dist = pkgs.buildPackages.stdenv.mkDerivation { + dist = pkgs.stdenv.mkDerivation { name = "stdenv-bootstrap-tools-cross"; buildCommand = '' From 88ea6463a342c2084266395b210d57b1218bad62 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Apr 2017 16:00:11 -0400 Subject: [PATCH 2/6] binutils on darwin: Clean up the rats nest - No more *Cross duplication for binutils on darwin either. `cctools_cross` is merged into plain `cctools`, so `buildPackages` chains alone are used to disambiguate. - Always use a mashup of cctools and actual GNU Binutils as `binutils`. Previously, this was only done in the native case as nobody had bothered to implement the masher in the cross case. Implemented it basically consisted of extending the wrapper to deal with prefixed binaries. --- .../tools/misc/binutils/default.nix | 3 +- pkgs/os-specific/darwin/binutils/default.nix | 22 ++++-- pkgs/os-specific/darwin/cctools/port.nix | 68 +++++++++++-------- pkgs/top-level/all-packages.nix | 15 ++-- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index b0819f6133b..37c312c6c6b 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -40,6 +40,7 @@ stdenv.mkDerivation rec { ./no-plugins.patch ]; + # TODO: all outputs on all platform outputs = [ "out" ] ++ optional (cross == null && !stdenv.isDarwin) "lib" # problems in Darwin stdenv ++ [ "info" ] @@ -75,7 +76,7 @@ stdenv.mkDerivation rec { configureFlags = [ "--enable-shared" "--enable-deterministic-archives" "--disable-werror" ] ++ optional (stdenv.system == "mips64el-linux") "--enable-fix-loongson2f-nop" - ++ optional (cross != null) "--target=${cross.config}" + ++ optional (cross != null) "--target=${cross.config}" # TODO: make this unconditional ++ optionals gold [ "--enable-gold" "--enable-plugins" ] ++ optional (stdenv.system == "i686-linux") "--enable-targets=x86_64-linux-gnu"; diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix index c4ccdb94b81..bde42e45e9c 100644 --- a/pkgs/os-specific/darwin/binutils/default.nix +++ b/pkgs/os-specific/darwin/binutils/default.nix @@ -1,11 +1,25 @@ -{ stdenv, binutils-raw, cctools }: +{ stdenv, binutils-raw, cctools +, hostPlatform, targetPlatform +}: +let + prefix = stdenv.lib.optionalString + (targetPlatform != hostPlatform) + "${targetPlatform.config}-"; + + cmds = [ + "ar" "ranlib" "as" "dsymutil" "install_name_tool" + "ld" "strip" "otool" "lipo" "nm" "strings" "size" + ]; +in + +# TODO loop over prefixed binaries too stdenv.mkDerivation { name = "cctools-binutils-darwin"; buildCommand = '' mkdir -p $out/bin $out/include - ln -s ${binutils-raw.out}/bin/c++filt $out/bin/c++filt + ln -s ${binutils-raw.out}/bin/${prefix}c++filt $out/bin/${prefix}c++filt # We specifically need: # - ld: binutils doesn't provide it on darwin @@ -18,11 +32,11 @@ stdenv.mkDerivation { # - strip: the binutils one seems to break mach-o files # - lipo: gcc build assumes it exists # - nm: the gnu one doesn't understand many new load commands - for i in ar ranlib as dsymutil install_name_tool ld strip otool lipo nm strings size; do + for i in ${stdenv.lib.concatStringsSep " " (builtins.map (e: prefix + e) cmds)}; do ln -sf "${cctools}/bin/$i" "$out/bin/$i" done - for i in ${binutils-raw.dev}/include/*.h; do + for i in ${binutils-raw.dev or binutils-raw.out}/include/*.h; do ln -s "$i" "$out/include/$(basename $i)" done diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix index 0154d395216..204a4789bcc 100644 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ b/pkgs/os-specific/darwin/cctools/port.nix @@ -1,8 +1,22 @@ -{ stdenv, fetchFromGitHub, autoconf, automake, libtool_2 +{ stdenv, fetchFromGitHub, makeWrapper, autoconf, automake, libtool_2 , llvm, libcxx, libcxxabi, clang, libuuid -, libobjc ? null +, libobjc ? null, maloader ? null, xctoolchain ? null +, buildPlatform, hostPlatform, targetPlatform }: +let + inherit (stdenv.lib.systems.parse) isDarwin; + + prefix = stdenv.lib.optionalString + (targetPlatform != hostPlatform) + "${targetPlatform.config}-"; +in + +assert isDarwin targetPlatform.parsed; + +# Non-Darwin alternatives +assert (!isDarwin hostPlatform.parsed) -> (maloader != null && xctoolchain != null); + let baseParams = rec { name = "cctools-port-${version}"; @@ -26,7 +40,14 @@ let enableParallelBuilding = true; - configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [ "CXXFLAGS=-I${libcxx}/include/c++/v1" ]; + configureFlags = stdenv.lib.optionals (!stdenv.isDarwin) [ + "CXXFLAGS=-I${libcxx}/include/c++/v1" + ] ++ stdenv.lib.optionals (targetPlatform != buildPlatform) [ + # TODO make unconditional next hash break + "--build=${buildPlatform.config}" + "--host=${hostPlatform.config}" + "--target=${targetPlatform.config}" + ]; postPatch = '' sed -i -e 's/addStandardLibraryDirectories = true/addStandardLibraryDirectories = false/' cctools/ld64/src/ld/Options.cpp @@ -69,33 +90,26 @@ let popd ''; + postInstall = + if isDarwin hostPlatform.parsed + then '' + cat >$out/bin/dsymutil << EOF + #!${stdenv.shell} + EOF + chmod +x $out/bin/dsymutil + '' + else '' + for tool in dyldinfo dwarfdump dsymutil; do + ${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${targetPlatform.config}-$tool" \ + --add-flags "${xctoolchain}/bin/$tool" + ln -s "$out/bin/${targetPlatform.config}-$tool" "$out/bin/$tool" + done + ''; + meta = { homepage = "http://www.opensource.apple.com/source/cctools/"; description = "Mac OS X Compiler Tools (cross-platform port)"; license = stdenv.lib.licenses.apsl20; }; }; -in { - native = stdenv.mkDerivation (baseParams // { - # A hack for now... - postInstall = '' - cat >$out/bin/dsymutil << EOF - #!${stdenv.shell} - EOF - chmod +x $out/bin/dsymutil - ''; - }); - - cross = - { cross, maloader, makeWrapper, xctoolchain}: stdenv.mkDerivation (baseParams // { - configureFlags = baseParams.configureFlags ++ [ "--target=${cross.config}" ]; - - postInstall = '' - for tool in dyldinfo dwarfdump dsymutil; do - ${makeWrapper}/bin/makeWrapper "${maloader}/bin/ld-mac" "$out/bin/${cross.config}-$tool" \ - --add-flags "${xctoolchain}/bin/$tool" - ln -s "$out/bin/${cross.config}-$tool" "$out/bin/$tool" - done - ''; - }); -} +in stdenv.mkDerivation baseParams diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1abdf7d2d0c..d2a171a732d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6396,7 +6396,10 @@ with pkgs; bin_replace_string = callPackage ../development/tools/misc/bin_replace_string { }; - binutils = if stdenv.isDarwin then darwin.binutils else binutils-raw; + binutils = + if lib.systems.parse.isDarwin targetPlatform.parsed + then darwin.binutils + else binutils-raw; binutils-raw = callPackage ../development/tools/misc/binutils { # FHS sys dirs presumably only have stuff for the build platform @@ -11444,17 +11447,13 @@ with pkgs; darwin = let apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { }; in apple-source-releases // rec { - cctools_cross = callPackage (forcedNativePackages.callPackage ../os-specific/darwin/cctools/port.nix {}).cross { - cross = assert targetPlatform != buildPlatform; targetPlatform; + cctools = callPackage ../os-specific/darwin/cctools/port.nix { + inherit libobjc; + stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv; inherit maloader; xctoolchain = xcode.toolchain; }; - cctools = (callPackage ../os-specific/darwin/cctools/port.nix { - inherit libobjc; - stdenv = if stdenv.isDarwin then stdenv else libcxxStdenv; - }).native; - cf-private = callPackage ../os-specific/darwin/cf-private { inherit (apple-source-releases) CF; inherit osx_private_sdk; From 7018dfb9f4d1457d77495014a2e22febe2b9181a Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Apr 2017 16:00:11 -0400 Subject: [PATCH 3/6] binutils and cctools: Prefix derivation names with target for cross We want platform triple prefixes and suffixes on derivation names to be used consistently. The ideom this commit strives for is - suffix means build != host, i.e. cross *built* packages. This is already done. - prefix means build != target, i.e. cross tools. This matches the tradition of such binaries themselves being prefixed to disambiguate.] Binutils and cctools, as build tools, now use the latter --- pkgs/development/tools/misc/binutils/default.nix | 2 +- pkgs/os-specific/darwin/binutils/default.nix | 2 +- pkgs/os-specific/darwin/cctools/port.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index 37c312c6c6b..6bfd933bf9b 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -7,7 +7,7 @@ let basename = "binutils-2.28"; in let inherit (stdenv.lib) optional optionals optionalString; in stdenv.mkDerivation rec { - name = basename + optionalString (cross != null) "-${cross.config}"; + name = optionalString (cross != null) "${cross.config}-" + basename; src = fetchurl { url = "mirror://gnu/binutils/${basename}.tar.bz2"; diff --git a/pkgs/os-specific/darwin/binutils/default.nix b/pkgs/os-specific/darwin/binutils/default.nix index bde42e45e9c..f88f761f65a 100644 --- a/pkgs/os-specific/darwin/binutils/default.nix +++ b/pkgs/os-specific/darwin/binutils/default.nix @@ -15,7 +15,7 @@ in # TODO loop over prefixed binaries too stdenv.mkDerivation { - name = "cctools-binutils-darwin"; + name = "${prefix}cctools-binutils-darwin"; buildCommand = '' mkdir -p $out/bin $out/include diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix index 204a4789bcc..14c4c6e9973 100644 --- a/pkgs/os-specific/darwin/cctools/port.nix +++ b/pkgs/os-specific/darwin/cctools/port.nix @@ -19,7 +19,7 @@ assert (!isDarwin hostPlatform.parsed) -> (maloader != null && xctoolchain != nu let baseParams = rec { - name = "cctools-port-${version}"; + name = "${prefix}cctools-port-${version}"; version = "895"; src = fetchFromGitHub { From 20fa6fd87146a55ca5b66b88bf3d30012acbdac0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 15 Feb 2017 18:19:40 -0500 Subject: [PATCH 4/6] gcc: When cross compiling, always expect prefixed binutils Previously this was just done on Darwin. --- pkgs/development/compilers/gcc/4.5/default.nix | 3 +++ pkgs/development/compilers/gcc/4.8/default.nix | 7 +++---- pkgs/development/compilers/gcc/4.9/default.nix | 8 +++----- pkgs/development/compilers/gcc/5/default.nix | 8 +++----- pkgs/development/compilers/gcc/6/default.nix | 8 +++----- pkgs/development/compilers/gcc/snapshot/default.nix | 7 +++---- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/pkgs/development/compilers/gcc/4.5/default.nix b/pkgs/development/compilers/gcc/4.5/default.nix index 19a538e613e..288a91398d2 100644 --- a/pkgs/development/compilers/gcc/4.5/default.nix +++ b/pkgs/development/compilers/gcc/4.5/default.nix @@ -78,6 +78,9 @@ let version = "4.5.4"; withArch + withCpu + withAbi + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + diff --git a/pkgs/development/compilers/gcc/4.8/default.nix b/pkgs/development/compilers/gcc/4.8/default.nix index 714554019e4..2d615e3b8e8 100644 --- a/pkgs/development/compilers/gcc/4.8/default.nix +++ b/pkgs/development/compilers/gcc/4.8/default.nix @@ -143,6 +143,9 @@ let version = "4.8.5"; withFpu + withFloat + withMode + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + @@ -169,10 +172,6 @@ let version = "4.8.5"; (if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot" else " --with-headers=${libcCross.dev}/include") + # Ensure that -print-prog-name is able to find the correct programs. - (stdenv.lib.optionalString (crossMingw || crossDarwin) ( - " --with-as=${binutils}/bin/${cross.config}-as" + - " --with-ld=${binutils}/bin/${cross.config}-ld" - )) + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then diff --git a/pkgs/development/compilers/gcc/4.9/default.nix b/pkgs/development/compilers/gcc/4.9/default.nix index 3bf279635aa..93f46fdd0f6 100644 --- a/pkgs/development/compilers/gcc/4.9/default.nix +++ b/pkgs/development/compilers/gcc/4.9/default.nix @@ -145,6 +145,9 @@ let version = "4.9.4"; withFpu + withFloat + withMode + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + @@ -169,11 +172,6 @@ let version = "4.9.4"; else (if crossDarwin then " --with-sysroot=${libcCross.out}/share/sysroot" else " --with-headers=${libcCross.dev}/include") + - # Ensure that -print-prog-name is able to find the correct programs. - (stdenv.lib.optionalString (crossMingw || crossDarwin) ( - " --with-as=${binutils}/bin/${cross.config}-as" + - " --with-ld=${binutils}/bin/${cross.config}-ld" - )) + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix index 79c5b805f45..296b899830b 100644 --- a/pkgs/development/compilers/gcc/5/default.nix +++ b/pkgs/development/compilers/gcc/5/default.nix @@ -149,6 +149,9 @@ let version = "5.4.0"; withFpu + withFloat + withMode + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + @@ -173,11 +176,6 @@ let version = "5.4.0"; else (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot" else " --with-headers=${getDev libcCross}/include") + - # Ensure that -print-prog-name is able to find the correct programs. - (stdenv.lib.optionalString (crossMingw || crossDarwin) ( - " --with-as=${binutils}/bin/${cross.config}-as" + - " --with-ld=${binutils}/bin/${cross.config}-ld" - )) + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 57bb336ccbf..c23968d2126 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -145,6 +145,9 @@ let version = "6.3.0"; withFpu + withFloat + withMode + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + @@ -169,11 +172,6 @@ let version = "6.3.0"; else (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot" else " --with-headers=${getDev libcCross}/include") + - # Ensure that -print-prog-name is able to find the correct programs. - (stdenv.lib.optionalString (crossMingw || crossDarwin) ( - " --with-as=${binutils}/bin/${cross.config}-as" + - " --with-ld=${binutils}/bin/${cross.config}-ld" - )) + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then diff --git a/pkgs/development/compilers/gcc/snapshot/default.nix b/pkgs/development/compilers/gcc/snapshot/default.nix index 6b08f279790..9c3b7a4e7df 100644 --- a/pkgs/development/compilers/gcc/snapshot/default.nix +++ b/pkgs/development/compilers/gcc/snapshot/default.nix @@ -145,6 +145,9 @@ let version = "7-20170409"; withFpu + withFloat + withMode + + # Ensure that -print-prog-name is able to find the correct programs. + " --with-as=${binutils}/bin/${cross.config}-as" + + " --with-ld=${binutils}/bin/${cross.config}-ld" + (if crossMingw && crossStageStatic then " --with-headers=${libcCross}/include" + " --with-gcc" + @@ -170,10 +173,6 @@ let version = "7-20170409"; (if crossDarwin then " --with-sysroot=${getLib libcCross}/share/sysroot" else " --with-headers=${getDev libcCross}/include") + # Ensure that -print-prog-name is able to find the correct programs. - (stdenv.lib.optionalString (crossMingw || crossDarwin) ( - " --with-as=${binutils}/bin/${cross.config}-as" + - " --with-ld=${binutils}/bin/${cross.config}-ld" - )) + " --enable-__cxa_atexit" + " --enable-long-long" + (if crossMingw then From d34079c2d9d22e3d13778e7a948b16247610ec7c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 7 Feb 2017 12:25:01 -0500 Subject: [PATCH 5/6] release-cross: Add arms test from Darwin for binutils This does a decent job of testing everything in this PR up to here. --- pkgs/top-level/release-cross.nix | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index b22eff33dc0..861b3abe1ad 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -1,5 +1,8 @@ -{ # The platforms for which we build Nixpkgs. - supportedSystems ? [ builtins.currentSystem ] +/* This file defines some basic smoke tests for cross compilation. +*/ + +{ # The platforms *from* which we cross compile. + supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ] , # Strip most of attributes when evaluating to spare memory usage scrubJobs ? true }: @@ -83,6 +86,25 @@ in guile = nativePlatforms; }; + darwinToAarch64 = let + crossSystem = { + config = "aarch64-apple-darwin14"; + arch = "arm64"; + libc = "libSystem"; + }; + in mapTestOnCross crossSystem { + buildPackages.binutils = darwin; + }; + + darwinToArm = let + crossSystem = { + config = "arm-apple-darwin10"; + arch = "armv7-a"; + libc = "libSystem"; + }; + in mapTestOnCross crossSystem { + buildPackages.binutils = darwin; + }; /* Test some cross builds to the Sheevaplug */ crossSheevaplugLinux = let From 80ed251f176aefa4c31a93ebb550df009d9bb49e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Apr 2017 23:25:37 -0400 Subject: [PATCH 6/6] lib platform parsing: Whitelist `darwin10` and `darwin14` as stopgap Something better should be done longer term to support such version suffixes. --- lib/systems/parse.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 8f65a69b17a..b9758f44fc1 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -83,6 +83,9 @@ rec { solaris = { execFormat = elf; families = { inherit unix; }; }; windows = { execFormat = pe; families = { }; }; } // { # aliases + # TODO(@Ericson2314): Handle these Darwin version suffixes more generally. + darwin10 = kernels.darwin; + darwin14 = kernels.darwin; win32 = kernels.windows; };