Skip to content

Commit

Permalink
enable sccache
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy committed Nov 5, 2024
1 parent 35b6f23 commit 0f5c71e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
RUSTFLAGS: "-Dwarnings"
CARGO_PROFILE_OPT_BUILD_OVERRIDE_DEBUG: true

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -45,6 +37,16 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Configure sccache
uses: actions/github-script@v7
with:
script: |
const url = process.env.ACTIONS_CACHE_URL || '';
const token = process.env.ACTIONS_RUNTIME_TOKEN || '';
core.exportVariable(
'CACHE_ENVS',
`-e CARGO_INCREMENTAL=0 -e SCCACHE_GHA_ENABLED=true -e RUSTC_WRAPPER=sccache -e ACTIONS_CACHE_URL=${url} -e ACTIONS_RUNTIME_TOKEN=${token}`,
);
- name: Set up docker images and permissions
run: |
docker pull $PGRX_IMAGE
Expand All @@ -54,14 +56,14 @@ jobs:
- name: Clippy
run: |
for v in {14..17}; do
docker run --rm -v .:/workspace $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings
done
- name: Build
run: |
for v in {14..17}; do
docker run --rm -v .:/workspace $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v"
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v"
done
- name: Test
run: |
# pg agnostic tests
docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17
docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17
36 changes: 30 additions & 6 deletions docker/pgrx.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@
FROM ubuntu:22.04

ARG PGRX_VERSION=0.12.8
ARG SCCACHE_VERSION=0.8.2

ENV DEBIAN_FRONTEND=noninteractive \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
RUSTFLAGS="-Dwarnings"
RUSTFLAGS="-Dwarnings" \
RUST_BACKTRACE=1 \
CARGO_TERM_COLOR=always

RUN apt update && \
RUN set -eux; \
apt update; \
apt install -y --no-install-recommends \
curl \
ca-certificates \
build-essential \
postgresql-common gnupg \
crossbuild-essential-arm64 \
qemu-user-static \
libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config \
clang && \
rm -rf /var/lib/apt/lists/*
clang

# set up sccache
RUN set -ex; \
curl -fsSL -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz; \
tar -xzf sccache.tar.gz --strip-components=1; \
rm sccache.tar.gz; \
mv sccache /usr/local/bin/

RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
# install all the PostgresQL
RUN set -ex; \
for v in $(seq 14 17); do \
apt install -y --no-install-recommends postgresql-$v postgresql-server-dev-$v; \
done; \
rm -rf /var/lib/apt/lists/*;

# create a non-root user (make it compatible with Ubuntu 24.04)
RUN useradd -u 1000 -U -m ubuntu
Expand All @@ -27,12 +46,17 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --defau

WORKDIR /workspace
COPY rust-toolchain.toml /workspace/rust-toolchain.toml
# ref: https://github.com/pgcentralfoundation/pgrx/blob/develop/docs/src/extension/build/cross-compile.md
RUN set -ex; \
echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml; \
echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml
RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu

RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} && \
cargo pgrx init
RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION}

RUN set -ex; \
for v in $(seq 14 17); do \
cargo pgrx init --pg$v=/usr/lib/postgresql/$v/bin/pg_config; \
done;

ENTRYPOINT [ "cargo" ]

0 comments on commit 0f5c71e

Please sign in to comment.