Skip to content

Commit

Permalink
Build static Linux binaries with musl (#962)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
elopez committed Mar 7, 2023
1 parent d4cd283 commit 2b91d6e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/container-linux-static/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM fpco/alpine-haskell-stack:9.2.7

RUN apk upgrade --no-cache &&\
apk add --no-cache \
cmake \
libtool \
openssl-dev \
tar \
zlib-dev \
zlib-static

RUN addgroup \
--gid 115 \
runneruser \
&& \
adduser \
--disabled-password \
--gecos "" \
--ingroup runneruser \
--home /github/home \
--uid 1001 \
runneruser

RUN mkdir -p /etc/stack &&\
{ cat /root/.stack/config.yaml ;\
echo "system-ghc: true" ;\
echo "install-ghc: false" ;\
echo "skip-ghc-check: true" ;\
} >> /etc/stack/config.yaml
8 changes: 8 additions & 0 deletions .github/container-linux-static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Static GHC & musl container

This container is used as part of `.github/workflows/ci.yml` to produce
statically-linked amd64 linux builds of Echidna. It is based on the following
container produced by FP Complete and maintained in the
[`fpco/alpine-haskell-stack`](https://github.com/fpco/alpine-haskell-stack/tree/ghc927)
repository, and contains a few extra dependencies and configuration to make it
suitable for the GitHub Actions environment.
26 changes: 14 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ on:
branches:
- master

env:
# Tag for cache invalidation
CACHE_VERSION: v6

jobs:
build:
name: Build Echidna on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
container: ${{ fromJSON(matrix.container || '{"image":null}') }}
strategy:
matrix:
include:
- os: ubuntu-20.04
shell: bash
container: "{\"image\": \"elopeztob/alpine-haskell-stack-echidna:9.2.7\", \"options\": \"--user 1001\"}"
- os: macos-latest
shell: bash
- os: windows-latest
Expand Down Expand Up @@ -55,6 +61,7 @@ jobs:
- name: Install Stack
uses: haskell/actions/setup@v2
id: stack
if: matrix.container == ''
with:
ghc-version: '9.2'
enable-stack: true
Expand All @@ -69,23 +76,18 @@ jobs:
path: |
~/.local
D:\a\_temp\msys64\home\runneradmin\.local
key: ${{ runner.os }}-local-v5-${{ hashFiles('.github/scripts/install-*') }}
key: ${{ runner.os }}-local-${{ env.CACHE_VERSION }}-${{ hashFiles('.github/scripts/install-*') }}

- name: Cache Stack
- name: Cache Stack & Cabal
uses: actions/cache@v3
with:
path: |
.stack-work
${{ steps.stack.outputs.stack-root }}/*
!${{ steps.stack.outputs.stack-root }}/pantry/hackage/*.tar
!${{ steps.stack.outputs.stack-root }}/pantry/hackage/*.tar.gz
key: ${{ runner.os }}-stack-v5-${{ hashFiles('package.yaml', 'stack.yaml') }}

- name: Cache Cabal
uses: actions/cache@v3
with:
path: ${{ steps.stack.outputs.cabal-store }}
key: ${{ runner.os }}-cabal-v5-${{ hashFiles('package.yaml', 'stack.yaml') }}
${{ steps.stack.outputs.cabal-store || '~/.cabal' }}/*
${{ steps.stack.outputs.stack-root || '~/.stack' }}/*
!${{ steps.stack.outputs.stack-root || '~/.stack' }}/pantry/hackage/*.tar
!${{ steps.stack.outputs.stack-root || '~/.stack' }}/pantry/hackage/*.tar.gz
key: ${{ runner.os }}-stack-${{ env.CACHE_VERSION }}-${{ hashFiles('package.yaml', 'stack.yaml') }}

- name: Build Libraries
run: |
Expand Down
18 changes: 6 additions & 12 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,11 @@ executables:
when:
- condition: (os(linux) || os(windows)) && flag(static)
ghc-options:
- -static
- -O2
cc-options: -static
ld-options: -static -pthread
- condition: os(linux)
- -optl-static
- condition: os(linux) || os(windows)
ghc-options:
- -O2
ld-options: -pthread
- -optl-pthread
- condition: os(darwin)
extra-libraries: c++
ld-options: -Wl,-keep_dwarf_unwind
Expand All @@ -105,14 +102,11 @@ tests:
when:
- condition: (os(linux) || os(windows)) && flag(static)
ghc-options:
- -static
- -O2
cc-options: -static
ld-options: -static -pthread
- condition: os(linux)
- -optl-static
- condition: os(linux) || os(windows)
ghc-options:
- -O2
ld-options: -pthread
- -optl-pthread
- condition: os(darwin)
extra-libraries: c++
ld-options: -Wl,-keep_dwarf_unwind
Expand Down

0 comments on commit 2b91d6e

Please sign in to comment.