Skip to content

Commit

Permalink
Update to GHC 9.4 (#1096)
Browse files Browse the repository at this point in the history
* Update to GHC 9.4

* ci: Update to GHC 9.4

* ci: fix GHC 9.4 support on Windows

GHC 9.4 has changed toolchains to Clang, which causes issues when building
with our current setup. We perform the following changes to support
GHC 9.4 and later:

  * Use MSYS2 CLANG64 MSYS. See https://gitlab.haskell.org/ghc/ghc/-/issues/22561
  * Use MSYS2 minimal $PATH. There's many things in the default GitHub
    environment that cause conflicts. To achieve this, we have to also
    manually re-add the Stack, Cabal and GHC paths.
  * Bump the Stack resolver. GHC 9.4.7 has some compilation fixes that
    are good to have around.
  * Replace the GHC linker with our MSYS2 linker. The GHC linker is old
    (~LLVM 14?) and does not fully understand the static libraries
    produced by the newer Clang 17 in MSYS2.
  * Refactor the way we invoke Stack and take advantage of the Stack
    config to indicate extra library and include paths.
  * Drop the 'strip' workaround for the test suite, as it is not needed
    any longer.
  * Fix the linking of the standard C++ library. GHC 9.4 introduces a
    nice way to do it in a platform-independent way, but unfortunately
    it does not work properly in Nix and it attempts to link clang++
    instead of libc++.so, so we have to use some trickery.

        addDLL: stdc++ or dependencies not loaded. (Win32 error 126)

See also:
  * https://gitlab.haskell.org/ghc/ghc/-/issues/22738
  * https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.4?version_id=b60e52482a666d25638d59cd7e86851ddf971dc1#link-against-system-cxx-std-lib-instead-of-stdc

* hevm: pin to newer version supporting GHC 9.4

* ci: linux: update to GHC 9.4.7

* ci: do not cache Stack config

---------

Co-authored-by: Emilio López <[email protected]>
  • Loading branch information
arcz and elopez authored Oct 25, 2023
1 parent c42eff0 commit e03efba
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 40 deletions.
49 changes: 47 additions & 2 deletions .github/container-linux-static/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,47 @@
FROM fpco/alpine-haskell-stack:9.2.7
FROM alpine:3.18.4
# Based on https://github.com/fpco/alpine-haskell-stack/blob/9.2.8v2/ghc-Dockerfile

RUN apk upgrade --no-cache &&\
apk add --no-cache \
curl \
gcc \
git \
libc-dev \
xz \
gmp-dev \
autoconf \
automake \
binutils \
build-base \
coreutils \
cpio \
linux-headers \
libffi-dev \
musl-dev \
zlib-dev \
zlib-static \
ncurses-dev \
ncurses-libs \
ncurses-static \
bash \
lld \
shadow # for stack --docker, provides groupadd

RUN curl -sSLo /usr/local/bin/stack https://github.com/commercialhaskell/stack/releases/download/v2.13.1/stack-2.13.1-linux-x86_64-bin && \
chmod +x /usr/local/bin/stack

# https://stackoverflow.com/a/41517423
RUN ln -s /usr/lib/libncurses.a /usr/lib/libtinfo.a

COPY stack-config.yaml /root/.stack/config.yaml

RUN cd /tmp && \
curl -sSLo /tmp/ghc.tar.xz https://downloads.haskell.org/~ghc/9.4.7/ghc-9.4.7-x86_64-alpine3_12-linux.tar.xz && \
tar xf ghc.tar.xz && \
cd ghc-9.4.7-x86_64-unknown-linux && \
./configure --prefix=/usr/local && \
make install && \
rm -rf /tmp/ghc.tar.xz /tmp/ghc-9.4.7-x86_64-unknown-linux

RUN apk upgrade --no-cache &&\
apk add --no-cache \
Expand Down Expand Up @@ -26,4 +69,6 @@ RUN mkdir -p /etc/stack &&\
echo "system-ghc: true" ;\
echo "install-ghc: false" ;\
echo "skip-ghc-check: true" ;\
} >> /etc/stack/config.yaml
} >> /etc/stack/config.yaml &&\
chmod 664 /etc/stack/config.yaml &&\
chown root:runneruser /etc/stack/config.yaml
66 changes: 52 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
include:
- os: ubuntu-20.04
shell: bash
container: "{\"image\": \"elopeztob/alpine-haskell-stack-echidna:9.2.7\", \"options\": \"--user 1001\"}"
container: "{\"image\": \"elopeztob/alpine-haskell-stack-echidna:ghc-9.4.7\", \"options\": \"--user 1001\"}"
- os: macos-latest
shell: bash
- os: windows-latest
Expand All @@ -41,8 +41,9 @@ jobs:
uses: msys2/setup-msys2@v2
if: runner.os == 'Windows'
with:
msystem: UCRT64
path-type: inherit
msystem: CLANG64
release: false
path-type: minimal
update: true
install: >-
base-devel
Expand All @@ -53,20 +54,57 @@ jobs:
pacboy: >-
cmake:p
ninja:p
gcc:p
clang:p
lld:p
autotools:p
gmp:p
openssl:p
- name: Install Stack
uses: haskell/actions/setup@v2
uses: haskell-actions/setup@v2
id: stack
if: matrix.container == ''
with:
ghc-version: '9.2'
ghc-version: '9.4'
enable-stack: true
stack-version: 'latest'

- name: Configure Stack environment
run: |
HOME="${{ (runner.os == 'Windows' && '$(cygpath -m ~)') || '$HOME' }}"
mkdir -p "$STACK_ROOT"
{ echo "extra-include-dirs:";
echo "- $HOME/.local/include";
echo "$EXTRA_INCLUDE_WIN";
echo;
echo "extra-lib-dirs:";
echo "- $HOME/.local/lib";
echo "$EXTRA_LIB_WIN";
echo;
echo "ghc-options:";
echo -n ' "$locals": -Werror'
"$REPLACE_LINKER_WIN" && echo ' -pgml=C:/msys64/clang64/bin/clang.exe -pgml-supports-no-pie' || echo;
echo;
"$SKIP_MSYS" && echo "skip-msys: true" || true
} >> "$STACK_ROOT/config.yaml"
cat "$STACK_ROOT/config.yaml"
env:
STACK_ROOT: ${{ steps.stack.outputs.stack-root || '/etc/stack' }}
EXTRA_INCLUDE_WIN: ${{ (runner.os == 'Windows' && '- C:/msys64/clang64/include') || '' }}
EXTRA_LIB_WIN: ${{ (runner.os == 'Windows' && '- C:/msys64/clang64/lib') || '' }}
REPLACE_LINKER_WIN: ${{ (runner.os == 'Windows' && 'true') || 'false' }}
SKIP_MSYS: ${{ (runner.os == 'Windows' && 'true') || 'false' }}

- name: Configure Haskell paths (Windows)
if: runner.os == 'Windows'
run: |
HASKELL_PATHS="$(cygpath -u "$GHC_PATH"):$(cygpath -u "$CABAL_PATH"):$(cygpath -u "$STACK_PATH")"
echo "HASKELL_PATHS=$HASKELL_PATHS" >> "$GITHUB_ENV"
env:
GHC_PATH: ${{ steps.stack.outputs.ghc-path }}
CABAL_PATH: ${{ steps.stack.outputs.cabal-path }}
STACK_PATH: ${{ steps.stack.outputs.stack-path }}

- name: Checkout
uses: actions/checkout@v4

Expand All @@ -75,7 +113,7 @@ jobs:
with:
path: |
~/.local
D:\a\_temp\msys64\home\runneradmin\.local
C:\msys64\home\runneradmin\.local
key: ${{ runner.os }}-local-${{ env.CACHE_VERSION }}-${{ hashFiles('.github/scripts/install-*') }}

- name: Cache Stack & Cabal
Expand All @@ -87,6 +125,7 @@ jobs:
${{ 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
!${{ steps.stack.outputs.stack-root || '~/.stack' }}/config.yaml
key: ${{ runner.os }}-stack-${{ env.CACHE_VERSION }}-${{ hashFiles('package.yaml', 'stack.yaml') }}

- name: Build Libraries
Expand All @@ -98,11 +137,13 @@ jobs:

- name: Build Dependencies
run: |
stack build --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib --only-dependencies
export PATH="$HASKELL_PATHS:$PATH"
stack build --ghc-options="-Werror" --only-dependencies
- name: Build and install echidna
run: |
stack install --flag echidna:static --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib
export PATH="$HASKELL_PATHS:$PATH"
stack install --flag echidna:static --ghc-options="-Werror"
- name: Amend and compress binaries (macOS)
if: runner.os == 'macOS'
Expand All @@ -125,12 +166,9 @@ jobs:
- name: Build and copy test suite
if: runner.os != 'macOS'
run: |
stack build --flag echidna:static --test --no-run-tests --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib
export PATH="$HASKELL_PATHS:$PATH"
stack build --flag echidna:static --test --no-run-tests --ghc-options="-Werror"
cp "$(find "$PWD" -name 'echidna-testsuite*' -type f)" .
if [ "${{ runner.os }}" = "Windows" ]; then
# work around https://gitlab.haskell.org/ghc/ghc/-/issues/21109
strip echidna-testsuite*
fi
- name: Upload testsuite
if: runner.os != 'macOS'
Expand Down
19 changes: 10 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
Expand Down Expand Up @@ -40,18 +40,21 @@

hevm = pkgs.haskell.lib.dontCheck (
pkgs.haskellPackages.callCabal2nix "hevm" (pkgs.fetchFromGitHub {
owner = "ethereum";
owner = "elopez";
repo = "hevm";
rev = "release/0.51.3";
sha256 = "sha256-H6oURBGoQWSOuPhBB+UKg2UarVzXgv1tmfDBLnOtdhU=";
rev = "release/0.51.3-plus-ghc-9.4-support";
sha256 = "sha256-gJMFYfsPqf5XZyyPDGJLqr9q9RpXkemGeUQUvFT6V0E";
}) { secp256k1 = pkgs.secp256k1; });

echidna = with pkgs; lib.pipe
# FIXME: figure out solc situation, it conflicts with the one from
# solc-select that is installed with slither, disable tests in the meantime
echidna = pkgs.haskell.lib.dontCheck (
with pkgs; lib.pipe
(haskellPackages.callCabal2nix "echidna" ./. { inherit hevm; })
[
(haskell.lib.compose.addTestToolDepends [ haskellPackages.hpack slither-analyzer solc ])
(haskell.lib.compose.disableCabalFlag "static")
];
]);
in rec {
packages.echidna = echidna;
packages.default = echidna;
Expand Down
2 changes: 1 addition & 1 deletion lib/Echidna/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ui vm world dict initialCorpus = do
, now = now
, fetchedContracts = mempty
, fetchedSlots = mempty
, fetchedDialog = B.dialog (Just " Fetched contracts/slots ") Nothing 80
, fetchedDialog = B.dialog (Just $ str " Fetched contracts/slots ") Nothing 80
, displayFetchedDialog = False
, workerEvents = mempty
, corpusSize = 0
Expand Down
6 changes: 3 additions & 3 deletions lib/Echidna/UI/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Echidna.UI.Widgets where

#ifdef INTERACTIVE_UI

import Brick
import Brick hiding (style)
import Brick.AttrMap qualified as A
import Brick.Widgets.Border
import Brick.Widgets.Center
Expand Down Expand Up @@ -43,7 +43,7 @@ data UIState = UIState
, now :: LocalTime
, fetchedContracts :: Map Addr (Maybe Contract)
, fetchedSlots :: Map Addr (Map W256 (Maybe W256))
, fetchedDialog :: B.Dialog ()
, fetchedDialog :: B.Dialog () Name
, displayFetchedDialog :: Bool

, workerEvents :: Seq (Int, LocalTime, CampaignEvent)
Expand Down Expand Up @@ -222,7 +222,7 @@ perfWidget uiState =
ppSeed :: [WorkerState] -> String
ppSeed campaigns = show (head campaigns).genDict.defSeed

fetchedDialogWidget :: UIState -> Widget n
fetchedDialogWidget :: UIState -> Widget Name
fetchedDialogWidget uiState =
B.renderDialog uiState.fetchedDialog $ padLeftRight 1 $
foldl (<=>) emptyWidget (Map.mapWithKey renderContract uiState.fetchedContracts)
Expand Down
8 changes: 6 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ executables:
extra-libraries: c++
ld-options: -Wl,-keep_dwarf_unwind
ghc-options: -fcompact-unwind
- condition: os(windows)
- condition: os(windows) && impl(ghc >= 9.4)
dependencies: system-cxx-std-lib
- condition: os(windows) && impl(ghc < 9.4)
extra-libraries: stdc++

tests:
Expand All @@ -114,7 +116,9 @@ tests:
extra-libraries: c++
ld-options: -Wl,-keep_dwarf_unwind
ghc-options: -fcompact-unwind
- condition: os(windows)
- condition: os(windows) && impl(ghc >= 9.4)
dependencies: system-cxx-std-lib
- condition: os(windows) && impl(ghc < 9.4)
extra-libraries: stdc++

flags:
Expand Down
6 changes: 3 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
resolver: lts-20.17
resolver: lts-21.17

packages:
- '.'

extra-deps:
- git: https://github.com/ethereum/hevm.git
commit: 211fff90a32824c39bed48e61d4ef722b8d1bad1
- git: https://github.com/elopez/hevm.git
commit: 6ffb685574b556ef148c884b412a92c6909c2b4f

- restless-git-0.7@sha256:346a5775a586f07ecb291036a8d3016c3484ccdc188b574bcdec0a82c12db293,968
- s-cargot-0.1.4.0@sha256:61ea1833fbb4c80d93577144870e449d2007d311c34d74252850bb48aa8c31fb,3525
Expand Down

0 comments on commit e03efba

Please sign in to comment.