From b5c6ef285395e56cb2e002e64bbee5d4a29df3a0 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 26 Jul 2024 10:20:25 -0600 Subject: [PATCH] CI: Install rust and grcov The Rust toolchain is so that we can build and install grcov, which is Mozilla's tool to aggregate test coverage data into a report. --- .gitlab-ci.yml | 13 ++++- .gitlab-ci/env.sh | 2 + .gitlab-ci/install-grcov.sh | 8 +++ .gitlab-ci/install-rust-tools.sh | 11 ++++ .gitlab-ci/install-rust.sh | 92 ++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .gitlab-ci/env.sh create mode 100644 .gitlab-ci/install-grcov.sh create mode 100644 .gitlab-ci/install-rust-tools.sh create mode 100644 .gitlab-ci/install-rust.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 687d00364..da4a78eae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ workflow: variables: FDO_UPSTREAM_REPO: 'cairo/cairo' FDO_DISTRIBUTION_VERSION: '40' - FDO_DISTRIBUTION_TAG: '2024-07-24-coverage.0' + FDO_DISTRIBUTION_TAG: '2024-07-26-coverage.0' # TODO: should probably get its own image at some point instead of reusing the GStreamer one # See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/.gitlab-image-tags.yml for latest @@ -26,6 +26,9 @@ variables: DEFAULT_MESON_ARGS: > --default-library=both + RUST_STABLE: "1.80.0" + RUSTUP_VERSION: "1.27.1" + stages: - prep - build @@ -103,6 +106,14 @@ fedora image: libasan libubsan llvm + wget + FDO_DISTRIBUTION_EXEC: >- + bash .gitlab-ci/install-rust.sh --rustup-version ${RUSTUP_VERSION} \ + --stable ${RUST_STABLE} \ + --arch x86_64-unknown-linux-gnu && + bash .gitlab-ci/install-rust-tools.sh && + bash .gitlab-ci/install-grcov.sh && + rm -rf /root/.cargo /root/.cache # cleanup compilation dirs; binaries are installed now .build fedora: extends: diff --git a/.gitlab-ci/env.sh b/.gitlab-ci/env.sh new file mode 100644 index 000000000..b5761529f --- /dev/null +++ b/.gitlab-ci/env.sh @@ -0,0 +1,2 @@ +export RUSTUP_HOME='/usr/local/rustup' +export PATH=$PATH:/usr/local/cargo/bin diff --git a/.gitlab-ci/install-grcov.sh b/.gitlab-ci/install-grcov.sh new file mode 100644 index 000000000..43edaa73f --- /dev/null +++ b/.gitlab-ci/install-grcov.sh @@ -0,0 +1,8 @@ +source ./.gitlab-ci/env.sh + +set -eu +export CARGO_HOME='/usr/local/cargo' + +# Coverage tools +cargo install grcov +rustup component add llvm-tools-preview diff --git a/.gitlab-ci/install-rust-tools.sh b/.gitlab-ci/install-rust-tools.sh new file mode 100644 index 000000000..23e55f4d9 --- /dev/null +++ b/.gitlab-ci/install-rust-tools.sh @@ -0,0 +1,11 @@ +source ./.gitlab-ci/env.sh + +set -eu +export CARGO_HOME='/usr/local/cargo' + +rustup component add clippy +rustup component add rustfmt +# cargo install --force cargo-c +cargo install --version ^1.0 gitlab_clippy +cargo install --force cargo-deny +# cargo install --force cargo-outdated diff --git a/.gitlab-ci/install-rust.sh b/.gitlab-ci/install-rust.sh new file mode 100644 index 000000000..93cdb4abd --- /dev/null +++ b/.gitlab-ci/install-rust.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +set -o errexit -o pipefail -o noclobber -o nounset + +source ./.gitlab-ci/env.sh + +export CARGO_HOME='/usr/local/cargo' + +PARSED=$(getopt --options '' --longoptions 'rustup-version:,stable:,minimum:,nightly,arch:' --name "$0" -- "$@") +if [ $? -ne 0 ]; then + echo 'Terminating...' >&2 + exit 1 +fi + +eval set -- "$PARSED" +unset PARSED + +RUSTUP_VERSION= +STABLE= +MINIMUM= +NIGHTLY= +ARCH= + +while true; do + case "$1" in + '--rustup-version') + RUSTUP_VERSION=$2 + shift 2 + ;; + + '--stable') + STABLE=$2 + shift 2 + ;; + + '--minimum') + MINIMUM=$2 + shift 2 + ;; + + '--nightly') + NIGHTLY=1 + shift 1 + ;; + + '--arch') + ARCH=$2 + shift 2 + ;; + + '--') + shift + break + ;; + + *) + echo "Programming error" + exit 3 + ;; + esac +done + +if [ -z "$RUSTUP_VERSION" ]; then + echo "missing --rustup-version argument" + exit 1 +fi + +if [ -z "$STABLE" ]; then + echo "missing --stable argument, please pass the stable version of rustc you want" + exit 1 +fi + +if [ -z "$ARCH" ]; then + echo "missing --arch argument, please pass an architecture triple like x86_64-unknown-linux-gnu" + exit 1 +fi + +RUSTUP_URL=https://static.rust-lang.org/rustup/archive/$RUSTUP_VERSION/$ARCH/rustup-init +wget $RUSTUP_URL + +chmod +x rustup-init +./rustup-init -y --no-modify-path --profile minimal --default-toolchain $STABLE +rm rustup-init +chmod -R a+w $RUSTUP_HOME $CARGO_HOME + +if [ -n "$MINIMUM" ]; then + rustup toolchain install $MINIMUM +fi + +if [ -n "$NIGHTLY" ]; then + rustup toolchain install nightly +fi