Skip to content

Commit a64cea7

Browse files
committed
Re #3420 Add information on building statically-linked executables
1 parent 2261f68 commit a64cea7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

doc/faq.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,35 @@ Yes, Stack supports using Docker with images that contain preinstalled Stackage
338338
packages and the tools. See [Docker integration](docker_integration.md) for
339339
details.
340340

341+
## How do I build a statically-linked executable on Linux?
342+
343+
The way that Stack itself builds statically-linked Stack executables for Linux
344+
is as follows:
345+
346+
* In the Cabal file, the following
347+
[`ld-options`](https://cabal.readthedocs.io/en/stable/cabal-package.html#pkg-field-ld-options)
348+
are set: `-static` and `-pthread`.
349+
350+
* The Stack command is run in a Docker container based on Alpine Linux. The
351+
relevant Docker image repository is set out in Stack's `stack.yaml` file. See
352+
also https://gitlab.com/benz0li/ghc-musl.
353+
354+
* Stack's configuration includes:
355+
356+
~~~yaml
357+
extra-include-dirs:
358+
- /usr/include
359+
extra-lib-dirs:
360+
- /lib
361+
- /usr/lib
362+
~~~
363+
364+
* The build command is `stack build --docker --system-ghc --no-install-ghc` (on
365+
x86_64) or
366+
`stack build --docker --docker-stack-exe=image --system-ghc --no-install-ghc`
367+
(on AArch64; the host Stack and the image Stack must have the same version
368+
number).
369+
341370
## How do I use this with Travis CI?
342371

343372
See the [Travis CI instructions](travis_ci.md)

0 commit comments

Comments
 (0)