Merge branch 'fix/sccache' into 'next'

Fix CI cargo-cross caching with sccache

See merge request famedly/conduit!264
This commit is contained in:
Jonas Zohren 2022-01-26 18:54:13 +00:00
commit ba8d5abb67
4 changed files with 30 additions and 29 deletions

View file

@ -8,6 +8,10 @@ variables:
GIT_SUBMODULE_STRATEGY: recursive
FF_USE_FASTZIP: 1
CACHE_COMPRESSION_LEVEL: fastest
# Docker in Docker
DOCKER_HOST: tcp://docker:2375/
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
# --------------------------------------------------------------------- #
# Cargo: Compiling for different architectures #
@ -25,18 +29,13 @@ variables:
tags: ["docker"]
services: ["docker:dind"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
SHARED_PATH: $CI_PROJECT_DIR/shared/
SHARED_PATH: $CI_PROJECT_DIR/shared
CARGO_PROFILE_RELEASE_LTO: "true"
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1"
CARGO_INCREMENTAL: "false" # https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
before_script:
- 'echo "Building for target $TARGET"'
- "rustup show && rustc --version && cargo --version" # Print version info for debugging
# If provided, bring in caching through sccache, which uses an external S3 endpoint to store compilation results:
- if [ -n "${SCCACHE_BIN_URL}" ]; then curl $SCCACHE_BIN_URL --output /sccache && chmod +x /sccache && export RUSTC_WRAPPER=/sccache; fi
# install cross-compiling prerequisites
- 'apt-get update && apt-get install -y docker.io && docker version' # install docker
- 'cargo install cross && cross --version' # install cross
@ -45,10 +44,16 @@ variables:
- 'cp -r $CARGO_HOME/bin $SHARED_PATH/cargo'
- 'cp -r $RUSTUP_HOME $SHARED_PATH'
- 'export CARGO_HOME=$SHARED_PATH/cargo RUSTUP_HOME=$SHARED_PATH/rustup'
# If provided, bring in caching through sccache, which uses an external S3 endpoint to store compilation results.
# The sccache binary is stored in the sysroot of the rustc installation since that directory is added to the path of the cross container.
- if [ -n "${SCCACHE_BIN_URL}" ]; then RUSTC_SYSROOT=$(rustc --print sysroot) && curl $SCCACHE_BIN_URL --output $RUSTC_SYSROOT/bin/sccache && chmod +x $RUSTC_SYSROOT/bin/sccache && export RUSTC_WRAPPER=sccache; fi
script:
# cross-compile conduit for target
- 'time ./cross/build.sh --locked --release'
- 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"'
# print information about linking for debugging
- 'file conduit-$TARGET' # print file information
- 'readelf --dynamic conduit-$TARGET | sed -e "/NEEDED/q1"' # ensure statically linked
cache:
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
key: 'cargo-cache-$TARGET'
@ -82,16 +87,6 @@ build:release:cargo:x86_64-unknown-linux-musl:
- "conduit-x86_64-unknown-linux-musl"
expose_as: "Conduit for x86_64-unknown-linux-musl"
build:release:cargo:i686-unknown-linux-musl:
extends: .build-cargo-shared-settings
variables:
TARGET: "i686-unknown-linux-musl"
artifacts:
name: "conduit-i686-unknown-linux-musl"
paths:
- "conduit-i686-unknown-linux-musl"
expose_as: "Conduit for i686-unknown-linux-musl"
build:release:cargo:arm-unknown-linux-musleabihf:
extends: .build-cargo-shared-settings
variables:
@ -132,6 +127,9 @@ build:release:cargo:aarch64-unknown-linux-musl:
# cross-compile conduit for target
- 'time ./cross/build.sh --locked'
- 'mv "target/$TARGET/debug/conduit" "conduit-debug-$TARGET"'
# print information about linking for debugging
- 'file conduit-debug-$TARGET' # print file information
- 'readelf --dynamic conduit-debug-$TARGET | sed -e "/NEEDED/q1"' # ensure statically linked
artifacts:
expire_in: 4 weeks
@ -161,9 +159,6 @@ build:debug:cargo:x86_64-unknown-linux-musl:
- "build:release:cargo:armv7-unknown-linux-musleabihf"
- "build:release:cargo:aarch64-unknown-linux-musl"
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
PLATFORMS: "linux/arm/v6,linux/arm/v7,linux/arm64,linux/amd64"
DOCKER_FILE: "docker/ci-binaries-packaging.Dockerfile"
cache:

View file

@ -1,3 +1,15 @@
[build.env]
# CI uses an S3 endpoint to store sccache artifacts, so their config needs to
# be available in the cross container as well
passthrough = [
"RUSTC_WRAPPER",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"SCCACHE_BUCKET",
"SCCACHE_ENDPOINT",
"SCCACHE_S3_USE_SSL",
]
[target.aarch64-unknown-linux-musl]
image = "rust-cross:aarch64-unknown-linux-musl"
@ -7,8 +19,5 @@ image = "rust-cross:arm-unknown-linux-musleabihf"
[target.armv7-unknown-linux-musleabihf]
image = "rust-cross:armv7-unknown-linux-musleabihf"
[target.i686-unknown-linux-musl]
image = "rust-cross:i686-unknown-linux-musl"
[target.x86_64-unknown-linux-musl]
image = "rust-cross:x86_64-unknown-linux-musl"

View file

@ -17,10 +17,8 @@ ENV TARGET_PREFIX="/usr/local/$(echo "${TARGET:?}" | sed -e 's/armv7/arm/' -e 's
# Make sure that cc-rs links libc/libstdc++ statically when cross-compiling
# See https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables for more information
ENV RUSTFLAGS="-L\$TARGET_PREFIX/lib" CXXSTDLIB="static=stdc++"
# Forcefully linking against libatomic and libgcc is required for arm32, otherwise symbols are missing
$([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-lgcc -Clink-arg=-latomic"')
# Forcefully linking against libc is required for 32-bit, otherwise symbols are missing
$([[ $TARGET =~ arm|i686 ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -lstatic=c"')
# Forcefully linking against libatomic, libc and libgcc is required for arm32, otherwise symbols are missing
$([[ $TARGET =~ arm ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-static-libgcc -Clink-arg=-lgcc -lstatic=atomic -lstatic=c"')
# Strip symbols while compiling in release mode
$([[ $@ =~ -r ]] && echo 'ENV RUSTFLAGS="$RUSTFLAGS -Clink-arg=-s"')

View file

@ -9,6 +9,7 @@
FROM docker.io/alpine:3.15.0 AS runner
# Standard port on which Conduit launches.
# You still need to map the port when using the docker command or docker-compose.
EXPOSE 6167
@ -18,10 +19,8 @@ ENV CONDUIT_CONFIG="/srv/conduit/conduit.toml"
# Conduit needs:
# ca-certificates: for https
# libgcc: Apparently this is needed, even if I (@jfowl) don't know exactly why. But whatever, it's not that big.
RUN apk add --no-cache \
ca-certificates \
libgcc
ca-certificates
ARG CREATED