我用于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-options
和ld-options
给予stack
,或者拥有多项目标志?
我利用了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.yaml
的:
_flags: !include "../flags.yaml"
executables:
test-bootstrap:
<<: *deployed_exe
main: Main.hs
source-dirs: app
我有一个符号链接,可以根据需要进行切换。