edit New in all-packages.nixThe main nix packages expression has a parameter setting the information for the cross-compilation target. When set, this will allow us to cross-build: ... , crossSystem ? null, ... This crossSystem should be an attribute set with enough information about the target. Therefore it cannot be passed through "--argstr crossSystem mytarget", and it should be written in a nix file apart. For example, we can use this 'comtrend.nix': import ./default.nix # The root nixpkgs default.nix
{
crossSystem = {
config = "mips-unknown-linux";
bigEndian = true;
arch = "mips";
float = "soft";
withTLS = true;
libc = "uclibc";
platform = {
name = "comtrend";
kernelMajor = "2.6";
kernelBaseConfig = "bcm63xx_defconfig";
kernelHeadersBaseConfig = "bcm63xx_defconfig";
uboot = null;
kernelArch = "mips";
kernelAutoModules = false;
kernelTarget = "vmlinux.bin";
};
openssl.system = "linux-generic32";
gcc = {
arch = "mips32";
};
};
}
For more options available, you can check the relevant nix expressions involved in the build you want. Some 'platforms' are defined in nixpkgs already (check the all-packages.nix and platform.nix files there). Hydra cross-builds some packages, to test the cross-building expressions. And you can look at some crossSystem expressions in my configurations directory. edit New stdenv.mkDerivationedit New derivationsThe attribute set resulting from a stdenv.mkDerivation call returns the usual result comming from a usual native build, with two additional attributes:
Thus, these calls equivalently build the native derivation for 'bison' (mentioning the 'comtrend.nix' above): nix-build -A bison default.nix nix-build -A bison comtrend.nix nix-build -A bison.buildDrv comtrend.nix If we want to cross-build bison for the arm target described above, we can run: nix-build -A bison.hostDrv comtrend.nix edit New buildInputsIn the attribute set mkDerivation expect as parameters, the usual buildInputs got a new meaning when building hostDrv derivations, and a new buildNativeInputs got introduced, making a total of:
For usual derivations in the native build, buildInputs and buildNativeInputs get merged and built for the native system, and analogous for propagatedBuildInputs and propagatedBuildNativeInputs. TODO: These variables should be renamed just before merging the branch into the mainline. Attributes ending with "*buildInputs" should be renamed to "*hostInputs" and attributes ending with "*buildNativeInputs" should be renamed to "*buildInputs". This renaming is pending until the final merge to avoid the complexity of merging mainline updates into the branch. edit New variables in the builderIn the environment variables the derivation builder will receive when asking for the hostDrv to be built, there will be the new variable $crossConfig defined to the GNU Configuration triplet set in the crossSystem nixpkgs parameter. edit What are we testingedit Derivations
edit GNU Configurations
edit Actual problems to be solved
edit Historyedit MotivationI wanted to cross-build uboot for the sheevaplug, in order to debug it. edit The stdenv hackWhen I had a working cross compiler to build uboot, Nicolas Pierron insisted on trying to get the whole relationships between packages in nixpkgs to be usable also for cross-compilation. He came in with a stdenv adapter that I used to bring cross-compilation capabilities to nixpkgs stdenv. edit Bootstrap of the compiler
edit gcc-cross-wrapper, the stdenv adapterThe stdenv adapter brings into the builder PATH the gcc-cross-wrapper (it includes the cross-compiler and cross-libc). The gcc-cross-wrapper has a setup-hook that modifies the configureFlags, so the calls to the autotools configure script are attempted for a cross build. Also cmake has an adaptation for crossbuilding. edit Final stdenvThe stdenv in nixpkgs is aware of the nixpkgs parameter "crossSystem", explained above, and according to it, brings into the stdenv generic builder PATH the final gcc-cross-wrapper, and the gcc-cross-wrapper setup-hook sets up the configure scripts properly for a cross-build. It needs some help from the user, defining for each stdenv.mkDerivation the attributes buildInputs and buildNativeInputs properly, as explained above. That will determine what is cross built, what not, what gets into CFLAGS/LDFLAGS for the cross compiler, and what for the native compiler. |