[Nix-dev] cross toolchain howto request

Sergey Mironov ierton at gmail.com
Tue Mar 5 09:21:13 CET 2013


Hello. I continue my work on having several cross-toolchains and here
is what I have for now [1]. I've managed to write nix-expression which
can install a cross-toolchain for  one arch, but this expression can't
be used to install several toolchains simultaneously. That is the
problem.

For example, having all-packages.nix, patched with [1], I can type as user:

$ nix-env -i -A i386_toolchain.gcc
installing `gcc-wrapper-4.6.3-static-i386-unknown-elf'
... <installing the cross-compiler>

$ nix-env -i -A i386_toolchain.binutils
installing `binutils-2.21.1a-i386-unknown-elf'
... installing binutils

Now everything is all-right. User can use i386-unknown-elf-gcc and
other tools. But what if I want to install armv5tel_toolchain?

$ nix-env -i -A armv5tel_toolchain.gcc
replacing old `gcc-wrapper-4.6.3-static-i386-unknown-elf'
installing `gcc-wrapper-4.6.3-static-armv5tel-unknown-elf'

That is bad: I don't want to replace i386, I want to keep it but
install armv5tel as well. Looks like Nixos treats both toolchains as
one package, but why is that? I know that gccCrossStageStatic actually
calls gcc-cross-wrapper, but it changes the name argument.. Any ideas?

Sergey.

[1] - Add name to the gccCrossStageStatic plus two cross-toolchains expressions

diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index cd9c7a0..36daf8d 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2037,17 +2037,18 @@ let
                    if isMingw then windows.mingw_headers1 else null;
     in
       wrapGCCCross {
-      gcc = forceBuildDrv (lib.addMetaAttrs { platforms = []; } (
-        gcc_realCross.override {
-          crossStageStatic = true;
-          langCC = false;
-          libcCross = libcCross1;
-          enableShared = false;
-        }));
-      libc = libcCross1;
-      binutils = binutilsCross;
-      cross = assert crossSystem != null; crossSystem;
-  };
+        gcc = forceBuildDrv (lib.addMetaAttrs { platforms = []; } (
+          gcc_realCross.override {
+            crossStageStatic = true;
+            langCC = false;
+            libcCross = libcCross1;
+            enableShared = false;
+          }));
+        libc = libcCross1;
+        binutils = binutilsCross;
+        cross = assert crossSystem != null; crossSystem;
+        name = assert crossSystem != null; gcc.name + "-static-" +
crossSystem.config;
+      };

   # Only needed for mingw builds
   gccCrossMingw2 = wrapGCCCross {
@@ -9154,4 +9155,32 @@ let

   bullet = callPackage ../development/libraries/bullet {};

+  cross_toolchain_stage_static = cs :
+    let
+      pkgsCross = (import ./all-packages.nix) {
+        inherit system bootStdenv noSysDirs gccWithCC gccWithProfiling config;
+        crossSystem = cs;
+      };
+    in {
+      gcc = pkgsCross.gccCrossStageStatic;
+      binutils = pkgsCross.binutilsCross;
+    };
+
+  i386_toolchain = cross_toolchain_stage_static {
+    config = "i386-unknown-elf";
+    arch = "i386";
+    libc = null;
+    platform = {};
+  };
+
+  armv5tel_toolchain = cross_toolchain_stage_static {
+    config = "armv5tel-unknown-elf";
+    bigEndian = false;
+    arch = "arm";
+    float = "soft";
+    withTLS = true;
+    platform = {};
+    libc = null;
+  };
+
 }; in pkgs


More information about the nix-dev mailing list