Allow our own cabal-install bindist builds

This commit is contained in:
Julian Ospald 2023-11-16 21:02:01 +08:00
parent 988dcdac63
commit 67885734c9
No known key found for this signature in database
GPG Key ID: 4275CDA6A29BED43
5 changed files with 638 additions and 0 deletions

28
.github/scripts/brew.sh vendored Normal file
View File

@ -0,0 +1,28 @@
#!/bin/sh
set -eux
# shellcheck disable=SC1091
. .github/scripts/env.sh
if [ -e "$HOME/.brew" ] ; then
(
cd "$HOME/.brew"
git fetch --depth 1
git reset --hard origin/master
)
else
git clone --depth=1 https://github.com/Homebrew/brew "$HOME/.brew"
fi
export PATH="$HOME/.brew/bin:$HOME/.brew/sbin:$PATH"
mkdir -p "$CI_PROJECT_DIR/.brew_cache"
export HOMEBREW_CACHE="$CI_PROJECT_DIR/.brew_cache"
mkdir -p "$CI_PROJECT_DIR/.brew_logs"
export HOMEBREW_LOGS="$CI_PROJECT_DIR/.brew_logs"
mkdir -p /private/tmp/.brew_tmp
export HOMEBREW_TEMP=/private/tmp/.brew_tmp
#brew update
brew install ${1+"$@"}

66
.github/scripts/build.sh vendored Normal file
View File

@ -0,0 +1,66 @@
#!/bin/bash
set -eux
# shellcheck disable=SC1091
. .github/scripts/env.sh
# shellcheck disable=SC1091
. .github/scripts/common.sh
uname -a
uname -p
uname
pwd
env
# ensure ghcup
install_ghcup
# build
ghcup install ghc "${GHC_VERSION}"
ghcup set ghc "${GHC_VERSION}"
sed -i.bak -e '/DELETE MARKER FOR CI/,/END DELETE/d' cabal.project # see comment in cabal.project
ecabal update
ecabal user-config diff
ecabal user-config init -f
"ghc-${GHC_VERSION}" --info
"ghc" --info
# https://github.com/haskell/cabal/issues/7313#issuecomment-811851884
if [ "$(getconf LONG_BIT)" == "32" ] || [ "${DISTRO}" == "CentOS" ] ; then
echo 'constraints: lukko -ofd-locking' >> cabal.project.release.local
fi
# shellcheck disable=SC2206
args=(
-w "ghc-$GHC_VERSION"
--disable-profiling
--enable-executable-stripping
--project-file=cabal.project.release
${ADD_CABAL_ARGS}
)
run cabal v2-build "${args[@]}" cabal-install
mkdir -p "$CI_PROJECT_DIR/out"
# shellcheck disable=SC2154
cp "$(cabal list-bin "${args[@]}" cabal-install:exe:cabal)" "$CI_PROJECT_DIR/out/cabal$ext"
cp dist-newstyle/cache/plan.json "$CI_PROJECT_DIR/out/plan.json"
cd "$CI_PROJECT_DIR/out/"
# create tarball/zip
TARBALL_PREFIX="cabal-install-$("$CI_PROJECT_DIR/out/cabal" --numeric-version)"
case "${TARBALL_EXT}" in
zip)
zip "${TARBALL_PREFIX}-${ARTIFACT}.${TARBALL_EXT}" "cabal${ext}" plan.json
;;
tar.xz)
tar caf "${TARBALL_PREFIX}-${ARTIFACT}.${TARBALL_EXT}" "cabal${ext}" plan.json
;;
*)
fail "Unknown TARBALL_EXT: ${TARBALL_EXT}"
;;
esac
rm cabal plan.json

110
.github/scripts/common.sh vendored Normal file
View File

@ -0,0 +1,110 @@
#!/bin/bash
# shellcheck disable=SC1091
. .github/scripts/env.sh
# Colors
RED="0;31"
LT_BROWN="1;33"
LT_BLUE="1;34"
ecabal() {
cabal "$@"
}
nonfatal() {
"$@" || "$* failed"
}
sha_sum() {
if [ "${RUNNER_OS}" = "FreeBSD" ] ; then
sha256 "$@"
else
sha256sum "$@"
fi
}
git_describe() {
git config --global --get-all safe.directory | grep '^\*$' || git config --global --add safe.directory "*"
git describe --always
}
install_ghcup() {
# find "$GHCUP_INSTALL_BASE_PREFIX"
mkdir -p "$GHCUP_BIN"
mkdir -p "$GHCUP_BIN"/../cache
if [ "${RUNNER_OS}" = "FreeBSD" ] ; then
curl -o ghcup https://downloads.haskell.org/ghcup/tmp/x86_64-portbld-freebsd-ghcup-0.1.18.1
chmod +x ghcup
mv ghcup "$HOME/.local/bin/ghcup"
else
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_MINIMAL=1 sh
source "$(dirname "${GHCUP_BIN}")/env"
ghcup install cabal --set "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
fi
}
strip_binary() {
(
set -e
local binary=$1
case "$(uname -s)" in
"Darwin"|"darwin")
;;
MSYS_*|MINGW*)
;;
*)
strip -s "${binary}"
;;
esac
)
}
# GitLab Pipelines log section delimiters
# https://gitlab.com/gitlab-org/gitlab-foss/issues/14664
start_section() {
name="$1"
echo -e "section_start:$(date +%s):$name\015\033[0K"
}
end_section() {
name="$1"
echo -e "section_end:$(date +%s):$name\015\033[0K"
}
echo_color() {
local color="$1"
local msg="$2"
echo -e "\033[${color}m${msg}\033[0m"
}
error() { echo_color "${RED}" "$1"; }
warn() { echo_color "${LT_BROWN}" "$1"; }
info() { echo_color "${LT_BLUE}" "$1"; }
fail() { error "error: $1"; exit 1; }
run() {
info "Running $*..."
"$@" || ( error "$* failed"; return 1; )
}
emake() {
if command -v gmake >/dev/null 2>&1 ; then
gmake "$@"
else
make "$@"
fi
}
mktempdir() {
case "$(uname -s)" in
"Darwin"|"darwin")
mktemp -d -t cabal_ci.XXXXXXX
;;
*)
mktemp -d
;;
esac
}

38
.github/scripts/env.sh vendored Normal file
View File

@ -0,0 +1,38 @@
#!/bin/bash
mkdir -p "$HOME"/.local/bin
if [ "${RUNNER_OS}" = "Windows" ] ; then
ext=".exe"
else
# shellcheck disable=SC2034
ext=''
fi
export PATH="$HOME/.local/bin:$PATH"
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
export BOOTSTRAP_HASKELL_CABAL_VERSION="${CABAL_VER:-3.8.1.0}"
export BOOTSTRAP_HASKELL_ADJUST_CABAL_CONFIG=no
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK=yes
export BOOTSTRAP_HASKELL_ADJUST_BASHRC=1
if [ "${RUNNER_OS}" = "Windows" ] ; then
# on windows use pwd to get unix style path
CI_PROJECT_DIR="$(pwd)"
export CI_PROJECT_DIR
export GHCUP_INSTALL_BASE_PREFIX="/c"
export GHCUP_BIN="$GHCUP_INSTALL_BASE_PREFIX/ghcup/bin"
export PATH="$GHCUP_BIN:$PATH"
export CABAL_DIR="C:\\Users\\runneradmin\\AppData\\Roaming\\cabal"
else
export CI_PROJECT_DIR="${GITHUB_WORKSPACE}"
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR"
export GHCUP_BIN="$GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin"
export PATH="$GHCUP_BIN:$PATH"
export CABAL_DIR="$CI_PROJECT_DIR/cabal"
export CABAL_CACHE="$CI_PROJECT_DIR/cabal-cache"
fi
export DEBIAN_FRONTEND=noninteractive
export TZ=Asia/Singapore

396
.github/workflows/cabal-release.yaml vendored Normal file
View File

@ -0,0 +1,396 @@
name: Cabal Bindist build
defaults:
run:
shell: bash
on:
workflow_dispatch:
inputs:
repo:
description: Repo
required: true
default: hasufell/cabal
type: string
ref:
description: Git ref
required: true
type: string
jobs:
build-linux:
name: Build linux binaries
runs-on: ubuntu-latest
env:
TARBALL_EXT: tar.xz
ARCH: 64
DEBIAN_FRONTEND: noninteractive
TZ: Asia/Singapore
GHC_VERSION: 9.2.3
strategy:
fail-fast: false
matrix:
platform: [ { image: "debian:9"
, installCmd: "sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list && sed -i 's|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list && sed -i /-updates/d /etc/apt/sources.list && apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Debian"
, ARTIFACT: "x86_64-linux-deb9"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "debian:10"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Debian"
, ARTIFACT: "x86_64-linux-deb10"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "debian:11"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Debian"
, ARTIFACT: "x86_64-linux-deb11"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "ubuntu:18.04"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Ubuntu"
, ARTIFACT: "x86_64-linux-ubuntu18.04"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "ubuntu:20.04"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Ubuntu"
, ARTIFACT: "x86_64-linux-ubuntu20.04"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "ubuntu:22.04"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Ubuntu"
, ARTIFACT: "x86_64-linux-ubuntu22.04"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "linuxmintd/mint19.3-amd64"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Mint"
, ARTIFACT: "x86_64-linux-mint19.3"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "linuxmintd/mint20.2-amd64"
, installCmd: "apt-get update && apt-get install -y"
, toolRequirements: "libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https gcc autoconf automake build-essential curl ghc gzip libffi-dev libncurses-dev libncurses5 libtinfo5 patchelf"
, DISTRO: "Mint"
, ARTIFACT: "x86_64-linux-mint20.2"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "fedora:27"
, installCmd: "dnf install -y"
, toolRequirements: "autoconf automake binutils bzip2 coreutils curl elfutils-devel elfutils-libs findutils gcc gcc-c++ git gmp gmp-devel jq lbzip2 make ncurses ncurses-compat-libs ncurses-devel openssh-clients patch perl pxz python3 sqlite sudo wget which xz zlib-devel patchelf"
, DISTRO: "Fedora"
, ARTIFACT: "x86_64-linux-fedora27"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "fedora:33"
, installCmd: "dnf install -y"
, toolRequirements: "autoconf automake binutils bzip2 coreutils curl elfutils-devel elfutils-libs findutils gcc gcc-c++ git gmp gmp-devel jq lbzip2 make ncurses ncurses-compat-libs ncurses-devel openssh-clients patch perl pxz python3 sqlite sudo wget which xz zlib-devel patchelf"
, DISTRO: "Fedora"
, ARTIFACT: "x86_64-linux-fedora33"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "centos:7"
, installCmd: "yum -y install epel-release && yum install -y"
, toolRequirements: "autoconf automake binutils bzip2 coreutils curl elfutils-devel elfutils-libs findutils gcc gcc-c++ git gmp gmp-devel jq lbzip2 make ncurses ncurses-compat-libs ncurses-devel openssh-clients patch perl pxz python3 sqlite sudo wget which xz zlib-devel patchelf"
, DISTRO: "CentOS"
, ARTIFACT: "x86_64-linux-centos7"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "rockylinux:8"
, installCmd: "yum -y install epel-release && yum install -y --allowerasing"
, toolRequirements: "autoconf automake binutils bzip2 coreutils curl elfutils-devel elfutils-libs findutils gcc gcc-c++ git gmp gmp-devel jq lbzip2 make ncurses ncurses-compat-libs ncurses-devel openssh-clients patch perl pxz python3 sqlite sudo wget which xz zlib-devel patchelf"
, DISTRO: "Unknown"
, ARTIFACT: "x86_64-linux-rocky8"
, ADD_CABAL_ARGS: "--enable-split-sections"
},
{ image: "alpine:latest"
, installCmd: "apk update && apk add"
, toolRequirements: "binutils-gold curl gcc g++ gmp-dev libc-dev libffi-dev make musl-dev ncurses-dev perl tar xz autoconf automake bzip2 coreutils elfutils-dev findutils git jq bzip2-dev patch python3 sqlite sudo wget which zlib-dev patchelf zlib zlib-dev zlib-static"
, DISTRO: "Unknown"
, ARTIFACT: "x86_64-linux-unknown"
, ADD_CABAL_ARGS: "--enable-split-sections --enable-executable-static"
}
]
container:
image: ${{ matrix.platform.image }}
steps:
- name: Install requirements
shell: sh
run: |
${{ matrix.platform.installCmd }} curl bash git ${{ matrix.platform.toolRequirements }}
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- name: Run build
run: |
bash .github/scripts/build.sh
env:
ARTIFACT: ${{ matrix.platform.ARTIFACT }}
DISTRO: ${{ matrix.platform.DISTRO }}
ADD_CABAL_ARGS: ${{ matrix.platform.ADD_CABAL_ARGS }}
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
build-linux-32bit:
name: Build linux binaries (32bit)
runs-on: ubuntu-latest
env:
TARBALL_EXT: tar.xz
ARCH: 32
TZ: Asia/Singapore
GHC_VERSION: 9.2.1
DISTRO: "Unknown"
ARTIFACT: "i386-linux-unknown"
ADD_CABAL_ARGS: "--enable-split-sections --enable-executable-static"
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
submodules: 'true'
- name: Run build (32 bit linux)
uses: docker://hasufell/i386-alpine-haskell:3.12
with:
args: sh -c "apk update && apk add bash binutils-gold curl gcc g++ gmp-dev libc-dev libffi-dev make musl-dev ncurses-dev perl tar xz autoconf automake bzip2 coreutils elfutils-dev findutils git jq bzip2-dev patch python3 sqlite sudo wget which zlib-dev patchelf zlib zlib-dev zlib-static && bash .github/scripts/build.sh"
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
build-arm:
name: Build ARM binary
runs-on: ${{ matrix.os }}
env:
TARBALL_EXT: tar.xz
ADD_CABAL_ARGS: ""
DEBIAN_FRONTEND: noninteractive
TZ: Asia/Singapore
ARCH: ARM64
DISTRO: Ubuntu
GHC_VERSION: 9.2.2
strategy:
fail-fast: false
matrix:
include:
- os: [self-hosted, Linux, ARM64]
ARCH: ARM
ARTIFACT: "armv7-linux-ubuntu20"
- os: [self-hosted, Linux, ARM64]
ARCH: ARM64
ARTIFACT: "aarch64-linux-ubuntu20"
steps:
- uses: docker://arm64v8/ubuntu:focal
name: Cleanup (aarch64 linux)
with:
args: "find . -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +"
- name: git config
run: |
git config --global --get-all safe.directory | grep '^\*$' || git config --global --add safe.directory "*"
shell: bash
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- if: matrix.ARCH == 'ARM'
uses: docker://hasufell/arm32v7-ubuntu-haskell:focal
name: Run build (armv7 linux)
with:
args: bash .github/scripts/build.sh
env:
ARTIFACT: ${{ matrix.ARTIFACT }}
- if: matrix.ARCH == 'ARM64'
uses: docker://hasufell/arm64v8-ubuntu-haskell:focal
name: Run build (aarch64 linux)
with:
args: bash .github/scripts/build.sh
env:
ARTIFACT: ${{ matrix.ARTIFACT }}
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
build-mac-x86_64:
name: Build binary (Mac x86_64)
runs-on: macOS-11
env:
MACOSX_DEPLOYMENT_TARGET: 10.13
ADD_CABAL_ARGS: ""
ARTIFACT: "x86_64-apple-darwin"
ARCH: 64
TARBALL_EXT: tar.xz
DISTRO: na
GHC_VERSION: 9.2.3
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- name: Run build
run: |
brew install coreutils tree
bash .github/scripts/build.sh
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
build-mac-aarch64:
name: Build binary (Mac aarch64)
runs-on: [self-hosted, macOS, ARM64]
env:
MACOSX_DEPLOYMENT_TARGET: 10.13
ADD_CABAL_ARGS: ""
ARTIFACT: "aarch64-apple-darwin"
ARCH: ARM64
TARBALL_EXT: tar.xz
DISTRO: na
HOMEBREW_CHANGE_ARCH_TO_ARM: 1
GHC_VERSION: 9.2.3
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- name: Run build
run: |
bash .github/scripts/brew.sh git coreutils autoconf automake tree
export PATH="$HOME/.brew/bin:$HOME/.brew/sbin:$PATH"
export LD=ld
bash .github/scripts/build.sh
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
build-win:
name: Build binary (Win)
runs-on: windows-latest
env:
ADD_CABAL_ARGS: ""
ARTIFACT: "x86_64-mingw64"
ARCH: 64
TARBALL_EXT: "zip"
DISTRO: na
GHC_VERSION: 9.2.3
steps:
- name: install windows deps
shell: pwsh
run: |
C:\msys64\usr\bin\bash -lc "pacman --disable-download-timeout --noconfirm -Syuu"
C:\msys64\usr\bin\bash -lc "pacman --disable-download-timeout --noconfirm -Syuu"
C:\msys64\usr\bin\bash -lc "pacman --disable-download-timeout --noconfirm -S make mingw-w64-x86_64-clang curl autoconf mingw-w64-x86_64-pkgconf ca-certificates base-devel gettext autoconf make libtool automake python p7zip patch unzip zip git"
taskkill /F /FI "MODULES eq msys-2.0.dll"
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- name: Run build (windows)
run: |
$env:CHERE_INVOKING = 1
$env:MSYS2_PATH_TYPE = "inherit"
$ErrorActionPreference = "Stop"
C:\msys64\usr\bin\bash -lc "bash .github/scripts/build.sh"
shell: pwsh
- if: always()
name: Upload artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
retention-days: 2
name: artifacts
path: |
./out/*
release:
name: release
needs: ["build-linux", "build-linux-32bit", "build-arm", "build-mac-x86_64", "build-mac-aarch64", "build-win"]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.ref }}
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: ./out
- name: Install requirements
run: |
sudo apt-get update && sudo apt-get install -y tar xz-utils
shell: bash
- name: build sdists
run: |
cabal sdist -o out all
shell: bash
- name: Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: |
./out/*