Merge pull request #113916 from siraben/xcompile-docs-patch-1

stdenv: cross-compilation documentation enhancements

authored by

Ryan Mulligan and committed by
GitHub
f838cf9c a7d68c87

+15 -4
+15 -4
doc/stdenv/cross-compilation.chapter.md
··· 16 16 In Nixpkgs, these three platforms are defined as attribute sets under the names `buildPlatform`, `hostPlatform`, and `targetPlatform`. They are always defined as attributes in the standard environment. That means one can access them like: 17 17 18 18 ```nix 19 - { stdenv, fooDep, barDep, .. }: ...stdenv.buildPlatform... 19 + { stdenv, fooDep, barDep, ... }: ...stdenv.buildPlatform... 20 20 ``` 21 21 22 22 `buildPlatform` ··· 99 99 100 100 Some frequently encountered problems when packaging for cross-compilation should be answered here. Ideally, the information above is exhaustive, so this section cannot provide any new information, but it is ludicrous and cruel to expect everyone to spend effort working through the interaction of many features just to figure out the same answer to the same common problem. Feel free to add to this list! 101 101 102 + #### My package fails to find a binutils command (`cc`/`ar`/`ld` etc.) {#cross-qa-fails-to-find-binutils} 103 + Many packages assume that an unprefixed binutils (`cc`/`ar`/`ld` etc.) is available, but Nix doesn't provide one. It only provides a prefixed one, just as it only does for all the other binutils programs. It may be necessary to patch the package to fix the build system to use a prefix. For instance, instead of `cc`, use `${stdenv.cc.targetPrefix}cc`. 104 + 105 + ```nix 106 + makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ]; 107 + ``` 108 + 109 + #### How do I avoid compiling a GCC cross-compiler from source? {#cross-qa-avoid-compiling-gcc-cross-compiler} 110 + On less powerful machines, it can be inconvenient to cross-compile a package only to find out that GCC has to be compiled from source, which could take up to several hours. Nixpkgs maintains a limited [cross-related jobset on Hydra](https://hydra.nixos.org/jobset/nixpkgs/cross-trunk), which tests cross-compilation to various platforms from build platforms "x86\_64-darwin", "x86\_64-linux", and "aarch64-linux". See `pkgs/top-level/release-cross.nix` for the full list of target platforms and packages. For instance, the following invocation fetches the pre-built cross-compiled GCC for `armv6l-unknown-linux-gnueabihf` and builds GNU Hello from source. 111 + 112 + ```ShellSession 113 + $ nix-build '<nixpkgs>' -A pkgsCross.raspberryPi.hello 114 + ``` 115 + 102 116 #### What if my package's build system needs to build a C program to be run under the build environment? {#cross-qa-build-c-program-in-build-environment} 103 117 Add the following to your `mkDerivation` invocation. 104 118 ```nix 105 119 depsBuildBuild = [ buildPackages.stdenv.cc ]; 106 120 ``` 107 - 108 - #### My package fails to find `ar`. {#cross-qa-fails-to-find-ar} 109 - Many packages assume that an unprefixed `ar` is available, but Nix doesn't provide one. It only provides a prefixed one, just as it only does for all the other binutils programs. It may be necessary to patch the package to fix the build system to use a prefixed `ar`. 110 121 111 122 #### My package's testsuite needs to run host platform code. {#cross-testsuite-runs-host-code} 112 123