From de296540406072f6d933d37e35b93c9f04366638 Mon Sep 17 00:00:00 2001 From: Martijn Bastiaan Date: Fri, 29 Mar 2024 20:12:03 +0100 Subject: [PATCH] Use own Docker image, add openocd --- .github/docker/Dockerfile | 82 +++++++++++++++++++ .../docker/build-and-publish-docker-image.sh | 48 +++++++++++ .github/workflows/ci.yml | 29 +------ 3 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 .github/docker/Dockerfile create mode 100755 .github/docker/build-and-publish-docker-image.sh diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile new file mode 100644 index 0000000..604a0f2 --- /dev/null +++ b/.github/docker/Dockerfile @@ -0,0 +1,82 @@ +# syntax=docker/dockerfile:1.2 + +# SPDX-FileCopyrightText: 2024 Google LLC + +# SPDX-License-Identifier: CC0-1.0 + +ARG UBUNTU_VERSION +FROM ubuntu:$UBUNTU_VERSION AS builder + +LABEL vendor="QBayLogic B.V." maintainer="devops@qbaylogic.com" +ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8 PREFIX=/opt + +ARG DEPS_COMMON="build-essential ca-certificates curl git locales ca-certificates" + +RUN apt-get update \ + && apt-get install -y --no-install-recommends $DEPS_COMMON \ + && locale-gen en_US.UTF-8 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +FROM builder AS build-openocd-vexriscv + +ARG DEPS_OPENOCD_VEXRISCV="autoconf automake libtool pkg-config libusb-1.0-0-dev libftdi-dev libhidapi-dev libusb-dev libyaml-dev" + +RUN apt-get update \ + && apt-get install -y --no-install-recommends $DEPS_OPENOCD_VEXRISCV \ + && git clone --recursive https://github.com/SpinalHDL/openocd_riscv.git \ + && cd openocd_riscv \ + && ./bootstrap \ + && ./configure --enable-ftdi --enable-dummy --prefix=/opt \ + && make -j$(nproc) \ + && make install + +FROM builder AS build-verilator + +ARG DEPS_VERILATOR="perl python3 make autoconf g++ flex bison ccache libgoogle-perftools-dev numactl perl-doc libfl2 libfl-dev zlib1g zlib1g-dev help2man" +RUN apt-get update \ + && apt-get install -y --no-install-recommends $DEPS_VERILATOR + +ARG verilator_version="v5.020" +RUN git clone https://github.com/verilator/verilator verilator \ + && cd verilator \ + && git checkout $verilator_version \ + && autoconf \ + && ./configure --prefix $PREFIX \ + && make PREFIX=$PREFIX -j$(nproc) \ + && make PREFIX=$PREFIX install \ + && cd ../.. \ + && rm -Rf verilator + +FROM builder AS build-ghc + +ARG ghcup_version="0.1.22.0" + +# Must be explicitly set +ARG ghc_version +ARG cabal_version + +RUN curl "https://downloads.haskell.org/~ghcup/$ghcup_version/x86_64-linux-ghcup-$ghcup_version" --output /usr/bin/ghcup \ + && chmod +x /usr/bin/ghcup \ + && ghcup install ghc $ghc_version --set \ + && ghcup install cabal $cabal_version --set + +FROM builder AS run + +LABEL vendor="QBayLogic B.V." maintainer="devops@qbaylogic.com" +ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 LC_ALL=C.UTF-8 PATH="$PATH:/opt/bin:/root/.ghcup/bin" + +ARG DEPS_RUNTIME="gnupg pkg-config openjdk-8-jdk gdb picocom libtinfo5 build-essential curl" +RUN apt-get update \ + && apt-get install -y --no-install-recommends $DEPS_RUNTIME \ + && echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list \ + && echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list \ + && curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add \ + && apt-get update \ + && apt-get install -y --no-install-recommends sbt \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build-verilator /opt /opt +COPY --from=build-openocd-vexriscv /opt /opt +COPY --from=build-ghc /root/.ghcup /root/.ghcup diff --git a/.github/docker/build-and-publish-docker-image.sh b/.github/docker/build-and-publish-docker-image.sh new file mode 100755 index 0000000..8c47cb3 --- /dev/null +++ b/.github/docker/build-and-publish-docker-image.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2024 Google LLC + +# SPDX-License-Identifier: CC0-1.0 +set -xeo pipefail + +REPO="ghcr.io/clash-lang" +NAME="clash-vexriscv-ci" +DIR=$(dirname "$0") +now=$(date +%Y%m%d) + +if [[ "$1" == "-y" ]]; then + push=y +elif [[ "$1" != "" ]]; then + echo "Unrecognized argument: $1" >&2 + exit 1 +fi + +UBUNTU_VERSION=jammy-20240125 +GHC_VERSIONS=( "9.4.8" "9.2.8" "9.0.2") +CABAL_VERSIONS=("3.10.2.0" "3.10.2.0" "3.10.2.0") + +for i in "${!GHC_VERSIONS[@]}" +do + GHC_VERSION="${GHC_VERSIONS[i]}" + CABAL_VERSION="${CABAL_VERSIONS[i]}" + + docker buildx build \ + --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} \ + --build-arg cabal_version=${CABAL_VERSION} \ + --build-arg ghc_version=${GHC_VERSION} \ + -t "${REPO}/${NAME}:${GHC_VERSION}-$now" \ + "$DIR" +done + +if [[ "${push}" == "" ]]; then + read -p "Push to GitHub? (y/N) " push +fi + +if [[ $push =~ ^[Yy]$ ]]; then + for i in "${!GHC_VERSIONS[@]}" + do + GHC_VERSION="${GHC_VERSIONS[i]}" + docker push "${REPO}/${NAME}:${GHC_VERSION}-$now" + done +else + echo "Skipping push to container registry" +fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edf1b89..6608848 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,10 +33,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Install dependencies - run: | - apt-get update - apt-get install -y curl build-essential - uses: actions-rs/toolchain@v1 with: toolchain: 1.67 # See Note [Updating Rust versions] @@ -69,7 +65,6 @@ jobs: run: | apt-get update apt-get install -y curl build-essential - - uses: actions-rs/toolchain@v1 with: toolchain: 1.67.1 # See Note [Updating Rust versions] @@ -116,7 +111,7 @@ jobs: - "9.4.8" container: - image: ghcr.io/clash-lang/clash-ci:${{ matrix.ghc }}-20240221 + image: ghcr.io/clash-lang/clash-vexriscv-ci:${{ matrix.ghc }}-20240329 steps: - name: Checkout @@ -132,27 +127,9 @@ jobs: with: path: | ~/.local/state/cabal/store/ - key: packages-cachebust-2-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze', 'cabal.project') }} - restore-keys: packages-cachebust-2-${{ matrix.ghc }} + key: packages-cachebust-3-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze', 'cabal.project') }} + restore-keys: packages-cachebust-3-${{ matrix.ghc }} - - name: Install build deps - run: | - apt-get update - apt-get install gnupg pkg-config -y - - name: Install Java - run: | - # install Java 8 - apt-get update - apt-get install openjdk-8-jdk -y - update-alternatives --config java - update-alternatives --config javac - - name: Install SBT - run: | - echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list - echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list - curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add - apt-get update - apt-get install sbt -y - name: Stash existing VexRiscv.v run: | cp clash-vexriscv/example-cpu/VexRiscv.v clash-vexriscv/example-cpu/VexRiscv.v.comitted