【问题标题】:Force static compilation in stack强制在堆栈中进行静态编译
【发布时间】:2021-03-08 19:58:53
【问题描述】:

我在多个项目中使用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,或者拥有多项目标志?

【问题讨论】:

    标签: haskell build compilation haskell-stack


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-07-18
      • 2011-05-25
      • 2012-08-14
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2023-03-24
      相关资源
      最近更新 更多