Skip to content

Commit 2b91d6e

Browse files
authored
Build static Linux binaries with musl (#962)
* Build static Linux binaries with musl Statically building glibc can be problematic, e.g. it requires the same (dynamic) glibc version in the system you're running the binary: function hsnet_getaddrinfo: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking This changes the build workflow to build the Linux binaries on a musl environment. * Add container used for static builds * Adjust package guards to match after merge * ci: Fix defaults duplication after merge * ci: disable haskell setup when using a container * ci: bump GHC to 9.2.7 * ci: Add README documenting container * ci: unify cache artifacts
1 parent d4cd283 commit 2b91d6e

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM fpco/alpine-haskell-stack:9.2.7
2+
3+
RUN apk upgrade --no-cache &&\
4+
apk add --no-cache \
5+
cmake \
6+
libtool \
7+
openssl-dev \
8+
tar \
9+
zlib-dev \
10+
zlib-static
11+
12+
RUN addgroup \
13+
--gid 115 \
14+
runneruser \
15+
&& \
16+
adduser \
17+
--disabled-password \
18+
--gecos "" \
19+
--ingroup runneruser \
20+
--home /github/home \
21+
--uid 1001 \
22+
runneruser
23+
24+
RUN mkdir -p /etc/stack &&\
25+
{ cat /root/.stack/config.yaml ;\
26+
echo "system-ghc: true" ;\
27+
echo "install-ghc: false" ;\
28+
echo "skip-ghc-check: true" ;\
29+
} >> /etc/stack/config.yaml
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Static GHC & musl container
2+
3+
This container is used as part of `.github/workflows/ci.yml` to produce
4+
statically-linked amd64 linux builds of Echidna. It is based on the following
5+
container produced by FP Complete and maintained in the
6+
[`fpco/alpine-haskell-stack`](https://github.com/fpco/alpine-haskell-stack/tree/ghc927)
7+
repository, and contains a few extra dependencies and configuration to make it
8+
suitable for the GitHub Actions environment.

.github/workflows/ci.yml

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ on:
88
branches:
99
- master
1010

11+
env:
12+
# Tag for cache invalidation
13+
CACHE_VERSION: v6
14+
1115
jobs:
1216
build:
1317
name: Build Echidna on ${{ matrix.os }}
1418
runs-on: ${{ matrix.os }}
19+
container: ${{ fromJSON(matrix.container || '{"image":null}') }}
1520
strategy:
1621
matrix:
1722
include:
1823
- os: ubuntu-20.04
1924
shell: bash
25+
container: "{\"image\": \"elopeztob/alpine-haskell-stack-echidna:9.2.7\", \"options\": \"--user 1001\"}"
2026
- os: macos-latest
2127
shell: bash
2228
- os: windows-latest
@@ -55,6 +61,7 @@ jobs:
5561
- name: Install Stack
5662
uses: haskell/actions/setup@v2
5763
id: stack
64+
if: matrix.container == ''
5865
with:
5966
ghc-version: '9.2'
6067
enable-stack: true
@@ -69,23 +76,18 @@ jobs:
6976
path: |
7077
~/.local
7178
D:\a\_temp\msys64\home\runneradmin\.local
72-
key: ${{ runner.os }}-local-v5-${{ hashFiles('.github/scripts/install-*') }}
79+
key: ${{ runner.os }}-local-${{ env.CACHE_VERSION }}-${{ hashFiles('.github/scripts/install-*') }}
7380

74-
- name: Cache Stack
81+
- name: Cache Stack & Cabal
7582
uses: actions/cache@v3
7683
with:
7784
path: |
7885
.stack-work
79-
${{ steps.stack.outputs.stack-root }}/*
80-
!${{ steps.stack.outputs.stack-root }}/pantry/hackage/*.tar
81-
!${{ steps.stack.outputs.stack-root }}/pantry/hackage/*.tar.gz
82-
key: ${{ runner.os }}-stack-v5-${{ hashFiles('package.yaml', 'stack.yaml') }}
83-
84-
- name: Cache Cabal
85-
uses: actions/cache@v3
86-
with:
87-
path: ${{ steps.stack.outputs.cabal-store }}
88-
key: ${{ runner.os }}-cabal-v5-${{ hashFiles('package.yaml', 'stack.yaml') }}
86+
${{ steps.stack.outputs.cabal-store || '~/.cabal' }}/*
87+
${{ steps.stack.outputs.stack-root || '~/.stack' }}/*
88+
!${{ steps.stack.outputs.stack-root || '~/.stack' }}/pantry/hackage/*.tar
89+
!${{ steps.stack.outputs.stack-root || '~/.stack' }}/pantry/hackage/*.tar.gz
90+
key: ${{ runner.os }}-stack-${{ env.CACHE_VERSION }}-${{ hashFiles('package.yaml', 'stack.yaml') }}
8991

9092
- name: Build Libraries
9193
run: |

package.yaml

+6-12
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,11 @@ executables:
7979
when:
8080
- condition: (os(linux) || os(windows)) && flag(static)
8181
ghc-options:
82-
- -static
83-
- -O2
84-
cc-options: -static
85-
ld-options: -static -pthread
86-
- condition: os(linux)
82+
- -optl-static
83+
- condition: os(linux) || os(windows)
8784
ghc-options:
8885
- -O2
89-
ld-options: -pthread
86+
- -optl-pthread
9087
- condition: os(darwin)
9188
extra-libraries: c++
9289
ld-options: -Wl,-keep_dwarf_unwind
@@ -105,14 +102,11 @@ tests:
105102
when:
106103
- condition: (os(linux) || os(windows)) && flag(static)
107104
ghc-options:
108-
- -static
109-
- -O2
110-
cc-options: -static
111-
ld-options: -static -pthread
112-
- condition: os(linux)
105+
- -optl-static
106+
- condition: os(linux) || os(windows)
113107
ghc-options:
114108
- -O2
115-
ld-options: -pthread
109+
- -optl-pthread
116110
- condition: os(darwin)
117111
extra-libraries: c++
118112
ld-options: -Wl,-keep_dwarf_unwind

0 commit comments

Comments
 (0)