Skip to content

Commit b18e248

Browse files
committed
Re #6048 Improve documentation about GHC options
1 parent 7888ce3 commit b18e248

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

doc/build_command.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,15 @@ GHC's optimisations (which is GHC's default).
337337

338338
### `--ghc-options` option
339339

340-
`stack build ghc-options <ghc_options>` passes the specified options to GHC.
340+
`stack build --ghc-options <ghc_options>` passes the specified command line
341+
options to GHC, depending on Stack's
342+
[`apply-ghc-options`](yaml_configuration.md#apply-ghc-options) YAML
343+
configuration option. This option can be specified multiple times.
344+
345+
GHC's command line options are _order-dependent_ and evaluated from left to
346+
right. Later options can override earlier options. Stack applies the options
347+
specified at the command line last. Any existing GHC command line options of a
348+
package are applied after those specified at the command line.
341349

342350
### `--[no-]library-profiling` flag
343351

doc/yaml_configuration.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,21 @@ allow-newer-deps:
390390

391391
Default: `locals`
392392

393-
Which packages do ghc-options on the command line get applied to? Before Stack
394-
0.1.6, the default value was `targets`
393+
Related command line:
394+
[`stack build --ghc-options`](build_command.md#ghc-options-option) option
395395

396-
~~~yaml
397-
apply-ghc-options: locals # all local packages
398-
# apply-ghc-options: targets # all local packages that are targets
399-
# apply-ghc-options: everything # applied even to snapshot and extra-deps
400-
~~~
396+
Determines to which packages any GHC command line options specified on the
397+
command line are applied. Possible values are: `everything` (all packages, local
398+
or otherwise), `locals` (all local packages, targets or otherwise), and
399+
`targets` (all local packages that are targets).
400+
401+
!!! note
402+
403+
The use of `everything` can break invariants about your snapshot database.
404+
405+
!!! note
401406

402-
Note that `everything` is a slightly dangerous value, as it can break invariants
403-
about your snapshot database.
407+
Before Stack 0.1.6.0, the default value was `targets`.
404408

405409
### arch
406410

@@ -760,17 +764,30 @@ arguments include `standard`, `gmp4`, `nopie`, `tinfo6`, `tinfo6-nopie`,
760764

761765
[:octicons-tag-24: 0.1.4.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.4.0)
762766

763-
Allows specifying per-package and global GHC options:
767+
Default: `{}`
768+
769+
Related command line (takes precedence):
770+
[`stack build --ghc-options`](build_command.md#ghc-options-option) option
771+
772+
`ghc-options` can specify GHC command line options for a named package, all
773+
local packages that are targets (using the `$targets` key), all local packages
774+
(targets or otherwise) (using the `$locals` key), or all packages (local or
775+
otherwise) (using the `$everything` key).
764776

765777
~~~yaml
766778
ghc-options:
767-
# All packages
768-
"$locals": -Wall
769-
"$targets": -Werror
770-
"$everything": -O2
771-
some-package: -DSOME_CPP_FLAG
779+
"$everything": -O2
780+
"$locals": -Wall
781+
"$targets": -Werror
782+
some-package: -DSOME_CPP_FLAG
772783
~~~
773784

785+
GHC's command line options are _order-dependent_ and evaluated from left to
786+
right. Later options can override earlier options. Stack applies options (as
787+
applicable) in the order of `$everything`, `$locals`, `$targets`, and then those
788+
for the named package. Any existing GHC command line options of a package are
789+
applied after those specified in Stack's YAML configuration.
790+
774791
Since Stack 1.6.0, setting a GHC options for a specific package will
775792
automatically promote it to a local package (much like setting a custom package
776793
flag). However, setting options via `$everything` on all flags will not do so
@@ -779,17 +796,10 @@ flag). However, setting options via `$everything` on all flags will not do so
779796
for reasoning). This can lead to unpredictable behavior by affecting your
780797
snapshot packages.
781798

782-
The behavior of the `$locals`, `$targets`, and `$everything` special keys
783-
mirrors the behavior for the
784-
[`apply-ghc-options` setting](#apply-ghc-options), which affects command line
785-
parameters.
786-
787799
!!! note
788800

789-
Prior to Stack 1.6.0, the `$locals`, `$targets`, and `$everything` keys
790-
were not supported. Instead, you could use `"*"` for the behavior
791-
represented now by `$everything`. It is highly recommended to switch to the
792-
new, more expressive, keys.
801+
Before Stack 1.6.0, the key `*` (now deprecated) had the same function as
802+
the key `$everything`.
793803

794804
### ghc-variant
795805

0 commit comments

Comments
 (0)