From 327b80cf5677d84097177300aaa847c455157326 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Thu, 15 Jul 2021 22:39:37 +0200 Subject: [PATCH] Add cross compilation to CI test --- .gitlab-ci.yml | 23 +++++++++ .gitlab/before_script/linux/install_deps.sh | 13 ++++-- .gitlab/script/ghcup_cross.sh | 52 +++++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100755 .gitlab/script/ghcup_cross.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc59375..dd9f92f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,6 +21,7 @@ variables: OS: "LINUX" ARCH: "64" CABAL_DIR: "$CI_PROJECT_DIR/cabal" + CROSS: "" .alpine:64bit: image: "alpine:3.12" @@ -268,6 +269,24 @@ test:linux:latest: CABAL_VERSION: "3.4.0.0" needs: [] +test:linux:cross-armv7: + stage: test + extends: + - .test_ghcup_version + - .debian + variables: + GHC_VERSION: "8.10.4" + GHC_TARGET_VERSION: "8.10.5" + CABAL_VERSION: "3.4.0.0" + CROSS: "arm-linux-gnueabihf" + needs: [] + when: manual + before_script: + - ./.gitlab/before_script/linux/install_deps.sh + script: + - ./.gitlab/script/ghcup_cross.sh + + ######## linux 32bit test ######## test:linux:recommended:32bit: @@ -286,6 +305,7 @@ test:linux:recommended:armv7: variables: GHC_VERSION: "8.10.4" CABAL_VERSION: "3.4.0.0" + CROSS: "" when: manual needs: [] @@ -295,6 +315,7 @@ test:linux:recommended:aarch64: variables: GHC_VERSION: "8.10.4" CABAL_VERSION: "3.4.0.0" + CROSS: "" when: manual needs: [] @@ -394,6 +415,7 @@ release:linux:armv7: ARTIFACT: "armv7-linux-ghcup" GHC_VERSION: "8.10.4" CABAL_VERSION: "3.4.0.0" + CROSS: "" release:linux:aarch64: stage: release @@ -407,6 +429,7 @@ release:linux:aarch64: ARTIFACT: "aarch64-linux-ghcup" GHC_VERSION: "8.10.4" CABAL_VERSION: "3.4.0.0" + CROSS: "" ######## darwin release ######## diff --git a/.gitlab/before_script/linux/install_deps.sh b/.gitlab/before_script/linux/install_deps.sh index 062b1a5..31fe99c 100755 --- a/.gitlab/before_script/linux/install_deps.sh +++ b/.gitlab/before_script/linux/install_deps.sh @@ -9,6 +9,13 @@ mkdir -p "${TMPDIR}" sudo apt-get update -y sudo apt-get install -y libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https +if [ "${CROSS}" = "arm-linux-gnueabihf" ] ; then + sudo apt-get install -y autoconf build-essential gcc-arm-linux-gnueabihf + sudo dpkg --add-architecture armhf + sudo apt-get update -y + sudo apt-get install -y libncurses-dev:armhf +fi + case "${ARCH}" in ARM*) case "${ARCH}" in @@ -57,9 +64,9 @@ case "${ARCH}" in chmod +x ghcup-bin ./ghcup-bin upgrade -i -f - ./ghcup-bin install ${GHC_VERSION} - ./ghcup-bin set ${GHC_VERSION} - ./ghcup-bin install-cabal ${CABAL_VERSION} + ./ghcup-bin install ghc ${GHC_VERSION} + ./ghcup-bin set ghc ${GHC_VERSION} + ./ghcup-bin install cabal ${CABAL_VERSION} ;; esac diff --git a/.gitlab/script/ghcup_cross.sh b/.gitlab/script/ghcup_cross.sh new file mode 100755 index 0000000..e76caac --- /dev/null +++ b/.gitlab/script/ghcup_cross.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +set -eux + +. "$( cd "$(dirname "$0")" ; pwd -P )/../ghcup_env" + +mkdir -p "$CI_PROJECT_DIR"/.local/bin + +CI_PROJECT_DIR=$(pwd) + +ecabal() { + cabal "$@" +} + +eghcup() { + ghcup -v -c -s file://$CI_PROJECT_DIR/ghcup-${JSON_VERSION}.yaml "$@" +} + +git describe --always + +### build + +ecabal update + +ecabal build -w ghc-${GHC_VERSION} +cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')" "$CI_PROJECT_DIR"/.local/bin/ghcup + +### cleanup + +rm -rf "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup + +### manual cli based testing + +eghcup --numeric-version + +eghcup install ghc ${GHC_VERSION} +eghcup set ghc ${GHC_VERSION} +eghcup install cabal ${CABAL_VERSION} + +cabal --version + +eghcup debug-info + +eghcup compile ghc -j $(nproc) -v ${GHC_TARGET_VERSION} -b ${GHC_VERSION} -x ${CROSS} -- --enable-unregisterised +eghcup set ghc ${CROSS}-${GHC_TARGET_VERSION} + +[ `$(eghcup whereis ghc ${CROSS}-${GHC_TARGET_VERSION}) --numeric-version` = "${GHC_TARGET_VERSION}" ] + +# nuke +eghcup nuke +[ ! -e "${GHCUP_INSTALL_BASE_PREFIX}/.ghcup" ] +