diff --git a/.cross/Dockerfile b/.cross/Dockerfile index 240830c..34fa06f 100644 --- a/.cross/Dockerfile +++ b/.cross/Dockerfile @@ -3,10 +3,31 @@ ARG DEBIAN_FRONTEND=noninteractive FROM $CROSS_BASE_IMAGE +# Install system deps +COPY .github/sccache.sh / RUN apt-get update && \ - apt-get install -y --no-install-recommends clang llvm && \ + apt-get install -y --no-install-recommends \ + clang llvm curl ca-certificates && \ + chmod +x /sccache.sh && \ + arch=$(uname -m) && \ + case "$arch" in \ + x86_64) triple="x86_64-unknown-linux-musl" ;; \ + aarch64) triple="aarch64-unknown-linux-musl" ;; \ + armv7l|armv7) triple="armv7-unknown-linux-musleabi" ;; \ + i686|i586) triple="i686-unknown-linux-musl" ;; \ + *) echo "FATAL: unsupported architecture for sccache: $arch" && exit 1 ;; \ + esac && \ + echo "Detected arch=$arch, downloading sccache for $triple" && \ + /sccache.sh "$triple" && \ + apt-get purge -y curl && \ + apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* ENV CC=clang \ CXX=clang++ \ - AR=llvm-ar + AR=llvm-ar \ + RUSTC_WRAPPER="/usr/bin/sccache" \ + SCCACHE_DIRECT=true \ + SCCACHE_SERVER_UDS="/tmp/sccache.sock" \ + SCCACHE_DIR="/tmp/sccache" \ + CARGO_BUILD_PIPELINING=false diff --git a/.github/sccache.sh b/.github/sccache.sh new file mode 100755 index 0000000..90f9feb --- /dev/null +++ b/.github/sccache.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Install sccache from GitHub releases. +# Assumes curl is already installed in the image. +# Usage: sccache.sh +# e.g. sccache.sh x86_64-unknown-linux-musl + +set -x +set -euo pipefail + +main() { + local triple="${1}" + local version="v0.14.0" + local url="https://github.com/mozilla/sccache/releases/download/${version}/sccache-${version}-${triple}.tar.gz" + local td + + td="$(mktemp -d)" + pushd "${td}" + + curl -LSfs "${url}" -o sccache.tar.gz + tar -xzf sccache.tar.gz + cp "sccache-${version}-${triple}/sccache" "/usr/bin/sccache" + chmod +x "/usr/bin/sccache" + + popd + rm -rf "${td}" + rm -f "${0}" +} + +main "${@}" diff --git a/Cross.toml b/Cross.toml index 5f16b0f..03a6a69 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,8 +1,8 @@ [build.env] passthrough = ["RUSTFLAGS", "RUSTC_BOOTSTRAP"] +volumes = ["/tmp=/tmp"] # Use clang as the C/C++ compiler to avoid the aws-lc-sys GCC memcmp bug # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189 -# The custom Dockerfile installs clang/llvm and sets CC=clang, CXX=clang++, AR=llvm-ar [build.dockerfile] -file = ".cross/Dockerfile" \ No newline at end of file +file = ".cross/Dockerfile"