Skip to content

Commit

Permalink
doc/stdenv/cross-compilation: Add 'Using -static outside a `isStati…
Browse files Browse the repository at this point in the history
…c` platform'

This issue often comes up when builds use `-static` in their own build
system

This may not be the correct location for this as it's not strictly a
cross issue, but it's the best one I can think of

Inspired by someone wanting to build a `riscv-busybox-initramfs` and just
adding `pkgsCross.riscv32.stdenv.cc` to `nativeBuildInputs`
  • Loading branch information
Artturin committed Sep 28, 2024
1 parent 3876b1b commit 92ecc3f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/stdenv/cross-compilation.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ Example of an error which this fixes.

`[Errno 8] Exec format error: './gdk3-scan'`

#### Using `-static` outside a `isStatic` platform. {#cross-static-on-non-static-platform}

Add `stdenv.cc.libc.static` (static output of glibc) to `buildInputs` conditionally on if `hostPlatform` uses `glibc`.


e.g.

```nix
{
buildInputs = lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
}
```

Example of an error which this fixes.

`cannot find -lm: No such file or directory`

::: {.note}
At the time of writing it is assumed the issue only happens on `glibc` because it splits the static libraries in to a different output.

## Cross-building packages {#sec-cross-usage}

Nixpkgs can be instantiated with `localSystem` alone, in which case there is no cross-compiling and everything is built by and for that system, or also with `crossSystem`, in which case packages run on the latter, but all building happens on the former. Both parameters take the same schema as the 3 (build, host, and target) platforms defined in the previous section. As mentioned above, `lib.systems.examples` has some platforms which are used as arguments for these parameters in practice. You can use them programmatically, or on the command line:
Expand Down

0 comments on commit 92ecc3f

Please sign in to comment.