My first attempt at getting cross compilers in nixpkgs.

My idea is to provide special stdenv expressions that will contain in the path
additional cross compilers. As most expressions for programs accept a stdenv parameter, 
we could substitute this parameter with the special stdenv, which will have a
generic builder that attempts the usual "--target=..." and can additionally
have an env variable like "cross" with the target architecture set.
So, finally we could have additional expressions like this:

bashRealArm = makeOverridable (import ../shells/bash) {
    inherit fetchurl bison;
    stdenv = stdenvCross "armv5tel-unknown-linux-gnueabi";
};

Meanwhile it does not work - I still cannot get the cross-gcc to build.

I think it does not fill the previous expressions with a lot of noise, so I
think it may be a good path to follow.

I only touched some files of the current stdenv: gcc-4.3, kernel headers
2.6.28, glibc 2.9, ...

I tried to use the gcc-cross-wrapper, that may be very outdated. Maybe I will
update it, or update the gcc-wrapper expression to make it fit the cross tools,
but meanwhile I even cannot build gcc, so I have not tested the wrapper.

This new idea on cross compiling is not similar to that of the
nixpkgs/branches/cross-compilation, which mostly added bare new expressions for
anything to be cross compiled, if I understood it correctly.

I cared not to break anything of the usual stdenv in all this work.


svn path=/nixpkgs/branches/stdenv-updates/; revision=18343
This commit is contained in:
Lluís Batlle i Rossell
2009-11-14 08:11:30 +00:00
parent 6864119104
commit 2aba922d30
11 changed files with 219 additions and 18 deletions

View File

@@ -87,10 +87,12 @@ postInstall() {
}
if test -z "$profiledCompiler"; then
buildFlags="bootstrap $buildFlags"
else
buildFlags="profiledbootstrap $buildFlags"
if test -n "$cross"; then
if test -z "$profiledCompiler"; then
buildFlags="bootstrap $buildFlags"
else
buildFlags="profiledbootstrap $buildFlags"
fi
fi
genericBuild

View File

@@ -10,16 +10,22 @@
, zlib ? null, boehmgc ? null
, enableMultilib ? false
, name ? "gcc"
, cross ? null
, binutilsCross ? null
, glibcHeadersCross ? null
}:
assert langTreelang -> bison != null && flex != null;
assert cross != null -> profiledCompiler == false && enableMultilib == true;
with stdenv.lib;
let version = "4.3.4"; in
stdenv.mkDerivation ({
name = "${name}-${version}";
name = "${name}-${version}" +
stdenv.lib.optionalString (cross != null) "-${cross}";
builder = ./builder.sh;
@@ -53,6 +59,7 @@ stdenv.mkDerivation ({
++ (optionals langTreelang [bison flex])
++ (optional (zlib != null) zlib)
++ (optional (boehmgc != null) boehmgc)
++ (optionals (cross != null) [binutilsCross])
;
configureFlags = "
@@ -71,7 +78,16 @@ stdenv.mkDerivation ({
)
}
${if stdenv.isi686 then "--with-arch=i686" else ""}
${if cross != null then "--disable-libssp --disable-nls" +
" --with-headers=${glibcHeadersCross}/include --target=${cross}" +
" --disable-shared" else ""}
";
#Above I added a hack on making the build different than the host.
# Needed for the cross compilation to work
AR = "ar";
LD = "ld";
CC = "gcc";
NIX_EXTRA_LDFLAGS = if staticCompiler then "-static" else "";

View File

@@ -1,10 +1,14 @@
{ stdenv, fetchurl, kernelHeaders
, installLocales ? true
, profilingLibraries ? false
, cross ? null
, binutilsCross ? null
, gccCross ? null
}:
stdenv.mkDerivation rec {
name = "glibc-2.9";
name = "glibc-2.9" +
stdenv.lib.optionalString (cross != null) "-${cross}";
builder = ./builder.sh;
@@ -60,12 +64,16 @@ stdenv.mkDerivation rec {
"--enable-add-ons"
"--with-headers=${kernelHeaders}/include"
(if profilingLibraries then "--enable-profile" else "--disable-profile")
] ++ stdenv.lib.optionals (cross != null) [
"--target=${cross}"
] ++ (if (stdenv.system == "armv5tel-linux") then [
"--host=arm-linux-gnueabi"
"--build=arm-linux-gnueabi"
"--without-fp"
] else []);
buildInputs = stdenv.lib.optionals (cross != null) [ binutilsCross gccCross ];
preInstall = ''
ensureDir $out/lib
ln -s ${stdenv.gcc.gcc}/lib/libgcc_s.so.1 $out/lib/libgcc_s.so.1

View File

@@ -0,0 +1,63 @@
{ stdenv, fetchurl, kernelHeaders
, profilingLibraries ? false
}:
stdenv.mkDerivation rec {
name = "glibc-headers-2.9";
builder = ./headersbuilder.sh;
src = fetchurl {
url = http://ftp.gnu.org/gnu/glibc/glibc-2.9.tar.bz2;
sha256 = "0v53m7flx6qcx7cvrvvw6a4dx4x3y6k8nvpc4wfv5xaaqy2am2q9";
};
srcPorts = fetchurl {
url = http://ftp.gnu.org/gnu/glibc/glibc-ports-2.9.tar.bz2;
sha256 = "0r2sn527wxqifi63di7ns9wbjh1cainxn978w178khhy7yw9fk42";
};
inherit kernelHeaders;
inherit (stdenv) is64bit;
patches = [
/* Support GNU Binutils 2.20 and above. */
./binutils-2.20.patch
];
configureFlags = [
"--enable-add-ons"
"--with-headers=${kernelHeaders}/include"
"--disable-sanity-checks"
"--enable-hacker-mode"
(if profilingLibraries then "--enable-profile" else "--disable-profile")
] ++ (if (stdenv.system == "armv5tel-linux") then [
"--host=arm-linux-gnueabi"
"--build=arm-linux-gnueabi"
"--without-fp"
] else []);
buildPhase = "true";
# I took some tricks from crosstool-0.43
installPhase = ''
make cross-compiling=yes CFLAGS=-DBOOTSTRAP_GCC install-headers
mkdir -p $out/include/gnu
touch $out/include/gnu/stubs.h
cp ../include/features.h $out/include/features.h
(cd $out/include && ln -s $kernelHeaders/include/* .) || exit 1
'';
# Workaround for this bug:
# http://sourceware.org/bugzilla/show_bug.cgi?id=411
# I.e. when gcc is compiled with --with-arch=i686, then the
# preprocessor symbol `__i686' will be defined to `1'. This causes
# the symbol __i686.get_pc_thunk.dx to be mangled.
NIX_CFLAGS_COMPILE = "-U__i686";
meta = {
homepage = http://www.gnu.org/software/libc/;
description = "The GNU C Library";
};
}

View File

@@ -0,0 +1,38 @@
# Glibc cannot have itself in its RPATH.
export NIX_NO_SELF_RPATH=1
source $stdenv/setup
# Explicitly tell glibc to use our pwd, not /bin/pwd.
export PWD_P=$(type -tP pwd)
# Needed to install share/zoneinfo/zone.tab. Set to impure /bin/sh to
# prevent a retained dependency on the bootstrap tools in the
# stdenv-linux bootstrap.
export BASH_SHELL=/bin/sh
preConfigure() {
for i in configure io/ftwtest-sh; do
# Can't use substituteInPlace here because replace hasn't been
# built yet in the bootstrap.
sed -i "$i" -e "s^/bin/pwd^$PWD_P^g"
done
# In the glibc 2.6/2.7 tarballs C-translit.h is a little bit older
# than C-translit.h.in, forcing Make to rebuild it unnecessarily.
# This wouldn't be problem except that it requires Perl, which we
# don't want as a dependency in the Nixpkgs bootstrap. So force
# the output file to be newer.
touch locale/C-translit.h
tar xvjf "$srcPorts"
mkdir build
cd build
configureScript=../configure
}
genericBuild

View File

@@ -1,10 +1,13 @@
{stdenv, fetchurl, noSysDirs}:
{stdenv, fetchurl, noSysDirs, cross ? null}:
let
basename = "binutils-2.20";
in
stdenv.mkDerivation rec {
name = "binutils-2.20";
name = basename + stdenv.lib.optionalString (cross != null) "-${cross}";
src = fetchurl {
url = "mirror://gnu/binutils/${name}.tar.bz2";
url = "mirror://gnu/binutils/${basename}.tar.bz2";
sha256 = "1c3m789p5rwmmnck5ms4zcnc40axss3gxzivz571al1vmbq0kpz1";
};
@@ -24,7 +27,8 @@ stdenv.mkDerivation rec {
fi
'';
configureFlags = "--disable-werror"; # needed for dietlibc build
configureFlags = "--disable-werror" # needed for dietlibc build
+ stdenv.lib.optionalString (cross != null) " --target=${cross}";
meta = {
description = "GNU Binutils, tools for manipulating binaries (linker, assembler, etc.)";