在堆栈中强制静态编译

Force static compilation in stack

我在多个项目中使用 stack,我需要有两种方法来编译它们,一种用于日常开发的“正常”方法,一种用于部署。

我使用 hpack,我的项目看起来像这样:

name:                test
version:             0.1.0
github:              "th/ng"
author:              "Me"
description:         Ok


dependencies:
- base >= 4.7 && < 5

executables:
  test-bootstrap:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N

对于我的部署,我需要按如下方式配置它们:

executables:
  test-bootstrap:
    main:                Main.hs
    source-dirs:         app
    cc-options:          -static
    ld-options:          -static -pthread
    extra-lib-dirs:      ./.system-work/lib
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -static

这迫使我 运行 和 stack build --docker

我尝试利用 stack build --ghc-options "-static"

但我有一个可怕的痕迹:

test          > /usr/bin/ld.gold: error: /home/stackage/.stack/programs/x86_64-linux/ghc-8.8.3/lib/ghc-8.8.3/ghc-prim-0.5.3/libHSghc-prim-0.5.3.a(Classes.o): requires unsupported dynamic reloc 11; recompile with -fPIC

有没有办法把 cc-optionsld-optionsstack,或者有多个项目标志?

我已经利用了 Yaml 包含机制,这里是我的 flags.yaml 静态编译:

- &deployed_exe
  cc-options:          -static
  ld-options:          -static -pthread
  extra-lib-dirs:      ./.system-work/lib
  ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -static

还有我的 package.yamls:

_flags: !include "../flags.yaml"


executables:
  test-bootstrap:
    <<: *deployed_exe
    main:                Main.hs
    source-dirs:         app

我有一个象征性的link我根据需要切换