Skip to content

Commit 3f144b1

Browse files
committed
doc/stdenv/cross-compilation: Add 'Using -static outside a isStatic 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`
1 parent 3876b1b commit 3f144b1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/stdenv/cross-compilation.chapter.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ Example of an error which this fixes.
181181

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

184+
#### Using `-static` outside a `isStatic` platform. {#cross-static-on-non-static-platform}
185+
186+
Add `stdenv.cc.libc.static` (static output of glibc) to `buildInputs` conditionally on if `hostPlatform` uses `glibc`.
187+
188+
189+
e.g.
190+
191+
```nix
192+
{
193+
buildInputs = lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
194+
}
195+
```
196+
197+
Examples of errors which this fixes.
198+
199+
`cannot find -lm: No such file or directory`
200+
201+
`cannot find -lc: No such file or directory`
202+
203+
::: {.note}
204+
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.
205+
206+
::: {.note}
207+
You may want to look in to using `stdenvAdapters.makeStatic` or `pkgsStatic` or a `isStatic = true` platform.
208+
184209
## Cross-building packages {#sec-cross-usage}
185210

186211
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:

0 commit comments

Comments
 (0)