Skip to content

Commit 17e5a84

Browse files
authored
Add darwin aarch64 support to CI (haskell#7636)
1 parent 6261490 commit 17e5a84

File tree

4 files changed

+141
-95
lines changed

4 files changed

+141
-95
lines changed

.gitlab-ci.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ variables:
33
DOCKER_REV: "853f348f9caf38b08740b280296fbd34e09abb3a"
44

55
GHC_VERSION: 8.10.7
6-
CABAL_INSTALL_VERSION: 3.2.0.0
6+
CABAL_INSTALL_VERSION: 3.4.0.0
77

88
workflow:
99
rules:
@@ -48,14 +48,39 @@ build-x86_64-linux-alpine:
4848
build-x86_64-freebsd:
4949
extends: .build
5050
tags:
51-
- x86_64-freebsd
51+
- x86_64-freebsd13
5252

5353
build-x86_64-darwin:
5454
extends: .build
5555
tags:
5656
- x86_64-darwin
5757

58+
build-aarch64-darwin:
59+
tags:
60+
- aarch64-darwin-m1
61+
script: |
62+
set -Eeuo pipefail
63+
function runInNixShell() {
64+
time nix-shell $CI_PROJECT_DIR/.gitlab/shell.nix \
65+
-I nixpkgs=https://github.com/angerman/nixpkgs/archive/75f7281738b.tar.gz \
66+
--argstr system "aarch64-darwin" \
67+
--pure \
68+
--keep CI_PROJECT_DIR \
69+
--keep MACOSX_DEPLOYMENT_TARGET \
70+
--keep GHC_VERSION \
71+
--keep CABAL_INSTALL_VERSION \
72+
--run "$1" 2>&1
73+
}
74+
runInNixShell "cabal update && mkdir vendored && cd vendored && cabal unpack network-3.1.2.1 && cd network-3.1.2.1 && autoreconf -fi" 2>&1
75+
runInNixShell "./.gitlab/ci.sh" 2>&1
76+
variables:
77+
MACOSX_DEPLOYMENT_TARGET: "10.7"
78+
artifacts:
79+
expire_in: 2 week
80+
paths:
81+
- out
82+
5883
build-x86_64-windows:
5984
extends: .build
6085
tags:
61-
- new-x86_64-windows
86+
- new-x86_64-windows

.gitlab/ci.sh

100644100755
Lines changed: 22 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,42 @@
22

33
set -Eeuo pipefail
44

5-
TOP="$(pwd)"
6-
source "$TOP/.gitlab/common.sh"
5+
source "$CI_PROJECT_DIR/.gitlab/common.sh"
76

8-
# We don't have sudo access in GitLab CI, so we can't just dump binaries in
9-
# the usual PATH locations.
10-
toolchain="$(pwd)/toolchain"
11-
mkdir -p "$toolchain/bin"
12-
export PATH="$toolchain/bin:$PATH"
137

14-
export CABAL_DIR="$TOP/cabal"
15-
mkdir -p "$CABAL_DIR"
8+
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR/toolchain"
9+
export CABAL_DIR="$CI_PROJECT_DIR/cabal"
1610

17-
# Platform-specific bits
18-
MAKE="make"
1911
case "$(uname)" in
2012
MSYS_*|MINGW*)
21-
CABAL_DIR="$(cygpath -w "$CABAL_DIR")"
22-
;;
23-
FreeBSD)
24-
MAKE="gmake"
13+
export CABAL_DIR="$(cygpath -w "$CABAL_DIR")"
14+
GHCUP_BINDIR="${GHCUP_INSTALL_BASE_PREFIX}/ghcup/bin"
2515
;;
16+
*)
17+
GHCUP_BINDIR="${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/bin"
18+
;;
2619
esac
2720

28-
fetch_cabal_install_unix() {
29-
local cabal_url="$1"
30-
run curl -L -o cabal.tar.xz "$cabal_url"
31-
run tar --directory "$toolchain/bin/" -xf cabal.tar.xz cabal
32-
chmod +x "$toolchain/bin/cabal"
33-
CABAL="$toolchain/bin/cabal"
34-
}
35-
36-
setup_cabal_install() {
37-
if [ -z "${CABAL:-}" ]; then
38-
info "Fetching GHC..."
39-
case "$(uname)" in
40-
FreeBSD)
41-
fetch_cabal_install_unix "https://hasufell.de/d/d3e215db133e4fcaa61e/files/?p=/cabal-install-$CABAL_INSTALL_VERSION-x86_64-portbld-freebsd.tar.xz&dl=1" ;;
42-
Darwin)
43-
fetch_cabal_install_unix "https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL_VERSION/cabal-install-$CABAL_INSTALL_VERSION-x86_64-apple-darwin17.7.0.tar.xz" ;;
44-
MSYS_*|MINGW*)
45-
cabal_url="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL_VERSION/cabal-install-$CABAL_INSTALL_VERSION-x86_64-unknown-mingw32.zip"
46-
run curl -L -o cabal.zip "$cabal_url"
47-
run unzip cabal.zip
48-
cp cabal.exe "$toolchain/bin/cabal.exe"
49-
chmod +x "$toolchain/bin/cabal.exe"
50-
CABAL="$toolchain/bin/cabal.exe"
51-
;;
52-
*) fail "no cabal-install bindist for $(uname)"
53-
esac
54-
55-
fi
56-
export CABAL
57-
run "$CABAL" --version
58-
}
59-
60-
61-
fetch_ghc_unix() {
62-
local ghc_url="$1"
63-
run curl -sSfL -o ghc.tar.xz "$ghc_url"
64-
run tar -xf ghc.tar.xz
65-
66-
pushd "ghc-${GHC_VERSION}"
67-
run ./configure --prefix="$toolchain"
68-
run "$MAKE" install
69-
popd
70-
GHC="$toolchain/bin/ghc"
71-
}
72-
73-
setup_ghc() {
74-
if [ -z "${GHC:-}" ]; then
75-
info "Fetching GHC..."
76-
case "$(uname)" in
77-
FreeBSD)
78-
fetch_ghc_unix "https://downloads.haskell.org/~ghc/$GHC_VERSION/ghc-$GHC_VERSION-x86_64-unknown-freebsd.tar.xz" ;;
79-
Darwin)
80-
fetch_ghc_unix "https://downloads.haskell.org/~ghc/$GHC_VERSION/ghc-$GHC_VERSION-x86_64-apple-darwin.tar.xz" ;;
81-
MSYS_*|MINGW*)
82-
ghc_url="https://downloads.haskell.org/~ghc/$GHC_VERSION/ghc-$GHC_VERSION-x86_64-unknown-mingw32.tar.xz"
83-
run curl -sSfL -o ghc.tar.xz "$ghc_url"
84-
run tar -xf ghc.tar.xz
85-
cp -R ghc-$GHC_VERSION/* "$toolchain"
86-
GHC="$toolchain/bin/ghc.exe"
87-
run "$GHC" --version
88-
GHC="$(cygpath -w $GHC)"
89-
return
90-
;;
91-
*) fail "no GHC bindist for $(uname)"
92-
esac
93-
fi
21+
mkdir -p "$CABAL_DIR"
22+
mkdir -p "$GHCUP_BINDIR"
23+
export PATH="$GHCUP_BINDIR:$PATH"
9424

95-
export GHC
96-
run "$GHC" --version
97-
}
25+
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
26+
export BOOTSTRAP_HASKELL_GHC_VERSION=$GHC_VERSION
27+
export BOOTSTRAP_HASKELL_CABAL_VERSION=$CABAL_INSTALL_VERSION
28+
export BOOTSTRAP_HASKELL_VERBOSE=1
29+
export BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG=yes
9830

99-
setup_cabal_install
100-
setup_ghc
31+
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
10132

102-
run "$CABAL" update
103-
run "$CABAL" v2-install cabal-install \
104-
-w "$GHC" \
105-
--installdir="$TOP/out" \
33+
run cabal v2-install cabal-install \
34+
-w "ghc-$GHC_VERSION" \
35+
--installdir="$CI_PROJECT_DIR/out" \
10636
--install-method=copy \
10737
--overwrite-policy=always \
10838
--enable-executable-static \
10939
--disable-profiling \
11040
--enable-split-sections \
11141
--enable-executable-stripping
42+
43+
cp dist-newstyle/cache/plan.json "$CI_PROJECT_DIR/out/plan.json"

.gitlab/shell.nix

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{ system ? "aarch64-darwin"
2+
#, nixpkgs ? fetchTarball https://github.com/angerman/nixpkgs/archive/257cb120334.tar.gz #apple-silicon.tar.gz
3+
, pkgs ? import <nixpkgs> { inherit system; }
4+
, compiler ? if system == "aarch64-darwin" then "ghc8103Binary" else "ghc8103"
5+
}: pkgs.mkShell {
6+
# this prevents nix from trying to write the env-vars file.
7+
# we can't really, as NIX_BUILD_TOP/env-vars is not set.
8+
noDumpEnvVars=1;
9+
10+
# stop polluting LDFLAGS with -liconv
11+
dontAddExtraLibs = true;
12+
13+
# we need to inject ncurses into --with-curses-libraries.
14+
# the real fix is to teach terminfo to use libcurses on macOS.
15+
# CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=${pkgs.ncurses.out}/lib";
16+
CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib SH=/bin/bash";
17+
18+
# magic speedup pony :facepalm:
19+
#
20+
# nix has the ugly habbit of duplicating ld flags more than necessary. This
21+
# somewhat consolidates this.
22+
shellHook = ''
23+
export NIX_LDFLAGS=$(for a in $NIX_LDFLAGS; do echo $a; done |sort|uniq|xargs)
24+
export NIX_LDFLAGS_FOR_TARGET=$(for a in $NIX_LDFLAGS_FOR_TARGET; do echo $a; done |sort|uniq|xargs)
25+
export NIX_LDFLAGS_FOR_TARGET=$(comm -3 <(for l in $NIX_LDFLAGS_FOR_TARGET; do echo $l; done) <(for l in $NIX_LDFLAGS; do echo $l; done))
26+
27+
28+
# Impurity hack for GHC releases.
29+
#################################
30+
# We don't want binary releases to depend on nix, thus we'll need to make sure we don't leak in references.
31+
# GHC externally depends only on iconv and curses. However we can't force a specific curses library for
32+
# the terminfo package, as such we'll need to make sure we only look in the system path for the curses library
33+
# and not pick up the tinfo from the nix provided ncurses package.
34+
#
35+
# We also need to force us to use the systems COREFOUNDATION, not the one that nix builds. Again this is impure,
36+
# but it will allow us to have proper binary distributions.
37+
#
38+
# do not use nixpkgs provided core foundation
39+
export NIX_COREFOUNDATION_RPATH=/System/Library/Frameworks
40+
# drop curses from the LDFLAGS, we really want the system ones, not the nix ones.
41+
export NIX_LDFLAGS=$(for lib in $NIX_LDFLAGS; do case "$lib" in *curses*);; *) echo -n "$lib ";; esac; done;)
42+
export NIX_CFLAGS_COMPILE+=" -Wno-nullability-completeness -Wno-availability -Wno-expansion-to-defined -Wno-builtin-requires-header -Wno-unused-command-line-argument"
43+
44+
# unconditionally add the MacOSX.sdk and TargetConditional.h
45+
export NIX_CFLAGS_COMPILE+=" -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
46+
export NIX_LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib $NIX_LDFLAGS"
47+
48+
'';
49+
50+
nativeBuildInputs = (with pkgs; [
51+
# This needs to come *before* ghc,
52+
# otherwise we migth end up with the clang from
53+
# the bootstrap GHC in PATH with higher priority.
54+
clang_11
55+
llvm_11
56+
57+
haskell.compiler.${compiler}
58+
haskell.packages.${compiler}.cabal-install
59+
haskell.packages.${compiler}.alex
60+
haskell.packages.${compiler}.happy # _1_19_12 is needed for older GHCs.
61+
62+
automake
63+
autoconf
64+
m4
65+
66+
gmp
67+
zlib.out
68+
zlib.dev
69+
glibcLocales
70+
# locale doesn't build yet :-/
71+
# locale
72+
73+
git
74+
75+
python3
76+
# python3Full
77+
# python3Packages.sphinx
78+
perl
79+
80+
which
81+
wget
82+
curl
83+
file
84+
85+
xz
86+
xlibs.lndir
87+
88+
cacert ])
89+
++ (with pkgs.darwin.apple_sdk.frameworks; [ Foundation Security ]);
90+
}

cabal.project

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ packages: cabal-benchmarks/
1313

1414
packages: vendor/cabal-doctest-1.0.8
1515

16-
-- Uncomment to allow picking up extra local unpacked deps:
17-
--optional-packages: */
16+
optional-packages: ./vendored/*/*.cabal
1817

1918
-- Remove after hackage-repo-tool release
2019
allow-newer:

0 commit comments

Comments
 (0)