Warm tip: This article is reproduced from serverfault.com, please click

haskell-强制在堆栈中进行静态编译

(haskell - Force static compilation in stack)

发布于 2020-11-25 22:25:29

我用于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-options给予stack,或者拥有多项目标志?

Questioner
GlinesMome
Viewed
11
GlinesMome 2020-11-28 20:29:08

我利用了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

我有一个符号链接,可以根据需要进行切换。