Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2864 - Incremental build caching for Rust in GitHub Actions #3019

Merged
merged 38 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
19aee4a
Temp fie for rust action
rtjd6554 Aug 5, 2024
04cceb1
Update on trigger
rtjd6554 Aug 5, 2024
92359d5
Update to reflect correct storage design
rtjd6554 Aug 15, 2024
a60eba4
Merge branch 'develop' into 2864-incremental-build-caching-for-rust-code
rtjd6554 Aug 22, 2024
8164c86
Update for build actions and file location
rtjd6554 Aug 22, 2024
17c9786
Syntax correction
rtjd6554 Aug 22, 2024
c4c3601
Update inline methods
rtjd6554 Aug 22, 2024
f66a78d
Dead section
rtjd6554 Aug 22, 2024
69edb27
Removal of the pull requset section - not needed
rtjd6554 Aug 22, 2024
08f8bd6
Update for run actions
rtjd6554 Aug 22, 2024
d14bcad
Remove extraneous argument
rtjd6554 Aug 22, 2024
c37bc0c
Location for cache adjustment
rtjd6554 Aug 22, 2024
f896803
Update to set env var
rtjd6554 Aug 22, 2024
1874ad6
Typo correction
rtjd6554 Aug 22, 2024
6e8e870
Rely on sccache-action for GHA caching
patchwork01 Aug 22, 2024
097d2bb
Remove setup-java
patchwork01 Aug 22, 2024
9486cc5
Add sccache to Cross.toml
patchwork01 Aug 22, 2024
be09809
Adjust build triggers
patchwork01 Aug 22, 2024
3ee1b96
Rename Rust build workflow
patchwork01 Aug 22, 2024
8471be2
Set verbose logging for build
patchwork01 Aug 22, 2024
827fc93
Add chunk-rust.yaml
patchwork01 Aug 22, 2024
998ad41
Update trigger paths
patchwork01 Aug 22, 2024
7a0d256
Add sccache to chunk.yaml
patchwork01 Aug 22, 2024
0345773
Set sccache environment variables in chunk.yaml
patchwork01 Aug 22, 2024
f5396f6
Match cross commands from Maven build in nightly workflow
patchwork01 Aug 23, 2024
36108a9
Use x86_64 sccache in aarch64 build
patchwork01 Aug 23, 2024
fe6368b
Merge branch 'develop' into 2864-incremental-build-caching-for-rust-code
patchwork01 Aug 29, 2024
69c458d
Set SCCACHE_DIR to temp directory
patchwork01 Aug 29, 2024
c795076
Disable sccache in cross by default
patchwork01 Aug 29, 2024
2ab3110
Add back default Cross.toml
patchwork01 Aug 29, 2024
a4ec8f0
Add end of file newlines
patchwork01 Aug 29, 2024
f247fb7
Add end of file newlines in Dockerfiles
patchwork01 Aug 29, 2024
c0b76cc
Use separate caches for ARM and x86
patchwork01 Aug 29, 2024
0262a22
Copy RUSTFLAGS from Maven exec
patchwork01 Aug 29, 2024
0c31491
Set SCCACHE_GHA_VERSION in Dockerfiles
patchwork01 Aug 29, 2024
6e629e4
Trigger rebuild
patchwork01 Aug 29, 2024
7dec3e9
Skip Rust in test step, since it's already been built
patchwork01 Aug 29, 2024
4b9c002
Merge branch 'develop' into 2864-incremental-build-caching-for-rust-code
patchwork01 Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/config/chunks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ chunks:
compaction:
name: Compaction
workflow: chunk-compaction.yaml
modules: [ compaction/compaction-job-execution, compaction/compaction-task-creation, compaction/compaction-job-creation, compaction/compaction-job-creation-lambda, compaction/compaction-status-store, compaction/compaction-core, splitter/splitter-core, splitter/splitter-lambda, compaction/compaction-rust ]
modules: [ compaction/compaction-job-execution, compaction/compaction-task-creation, compaction/compaction-job-creation, compaction/compaction-job-creation-lambda, compaction/compaction-status-store, compaction/compaction-core, splitter/splitter-core, splitter/splitter-lambda ]
rust:
name: Rust
workflow: chunk-rust.yaml
modules: [ compaction/compaction-rust ]
data:
name: Data
workflow: chunk-data.yaml
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/chunk-rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build Rust Modules
on:
pull_request:
paths:
- '.github/workflows/chunk-rust.yaml'
- '.github/workflows/chunk.yaml'
- '.github/config/chunks.yaml'
- 'code-style/checkstyle*.xml'
- 'code-style/spotbugs*.xml'
- 'rust/**'
- 'java/pom.xml'
- 'java/compaction/pom.xml'
- 'java/compaction/compaction-rust/**'
- 'java/compaction/compaction-job-creation/**'
- 'java/compaction/compaction-core/**'
- 'java/common/common-job/**'
- 'java/statestore/**'
- 'java/parquet/**'
- 'java/configuration/**'
- 'java/common/dynamodb-tools/**'
- 'java/core/**'

jobs:
chunk-workflow:
uses: ./.github/workflows/chunk.yaml
with:
chunkId: rust
skipRust: false
6 changes: 6 additions & 0 deletions .github/workflows/chunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
required: false
type: boolean

env:
SCCACHE_GHA_ENABLED: "true"
SSCACHE_CACHE_SIZE: "2G"

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,6 +25,8 @@ jobs:
distribution: 'corretto'
- uses: dtolnay/[email protected]
if: ${{ ! inputs.skipRust }}
- uses: mozilla-actions/[email protected]
if: ${{ ! inputs.skipRust }}
- name: Install cargo cross
run: cargo install cross
if: ${{ ! inputs.skipRust }}
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/rust-cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Rust Nightly
on:
workflow_dispatch: # Allow manual running to refresh/check cache
schedule: # Planned execution once per day
- cron: "0 2 * * *"
pull_request:
paths:
- '.github/workflows/rust-cache.yaml'

env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
SSCACHE_CACHE_SIZE: "2G"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: dtolnay/[email protected]
- uses: mozilla-actions/[email protected]
- name: Install cargo cross
run: cargo install cross
- name: Build x86_64
working-directory: ./rust
run: SCCACHE_LOG=trace cross build --release --target x86_64-unknown-linux-gnu --verbose
- name: Build aarch64
working-directory: ./rust
run: SCCACHE_LOG=trace cross build --release --target aarch64-unknown-linux-gnu --verbose
15 changes: 13 additions & 2 deletions rust/Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[build.env]
passthrough = [
"SCCACHE_ERROR_LOG",
"SCCACHE_LOG",
"SSCACHE_CACHE_SIZE",
"SCCACHE_GHA_ENABLED",
"ACTIONS_CACHE_URL",
"ACTIONS_RUNTIME_TOKEN",
]

[target.aarch64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge"
dockerfile = "Dockerfile.aarch64-unknown-linux-gnu"

[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:edge"
dockerfile = "Dockerfile.x86_64-unknown-linux-gnu"

[build]
pre-build = ["apt-get update && apt-get --assume-yes install libssl-dev"]
11 changes: 11 additions & 0 deletions rust/Dockerfile.aarch64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge
ARG DEBIAN_FRONTEND=noninteractive

# COPY sccache-source.sh /sccache.sh
# RUN /sccache.sh aarch64-unknown-linux-gnu

COPY sccache-prebuilt.sh /sccache.sh
RUN /sccache.sh x86_64-unknown-linux-musl

ENV RUSTC_WRAPPER="/usr/bin/sccache"
ENV SCCACHE_DIR="/tmp/sccache"
11 changes: 11 additions & 0 deletions rust/Dockerfile.x86_64-unknown-linux-gnu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ghcr.io/cross-rs/x86_64-unknown-linux-gnu:edge
ARG DEBIAN_FRONTEND=noninteractive

# COPY sccache-source.sh /sccache.sh
# RUN /sccache.sh x86_64-unknown-linux-gnu

COPY sccache-prebuilt.sh /sccache.sh
RUN /sccache.sh x86_64-unknown-linux-musl

ENV RUSTC_WRAPPER="/usr/bin/sccache"
ENV SCCACHE_DIR="/tmp/sccache"
41 changes: 41 additions & 0 deletions rust/sccache-prebuilt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
local triple
local tag
local td
local url="https://github.com/mozilla/sccache"
triple="${1}"

install_packages unzip tar

# Download our package, then install our binary.
td="$(mktemp -d)"
pushd "${td}"
tag=$(git ls-remote --tags --refs --exit-code \
"${url}" \
| cut -d/ -f3 \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort --version-sort \
| tail -n1)
curl -LSfs "${url}/releases/download/${tag}/sccache-${tag}-${triple}.tar.gz" \
-o sccache.tar.gz
tar -xvf sccache.tar.gz
rm sccache.tar.gz
cp "sccache-${tag}-${triple}/sccache" "/usr/bin/sccache"
chmod +x "/usr/bin/sccache"

# clean up our install
purge_packages
popd
rm -rf "${td}"
rm "${0}"
}

main "${@}"
57 changes: 57 additions & 0 deletions rust/sccache-source.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -x
set -euo pipefail

# shellcheck disable=SC1091
. lib.sh

main() {
local triple
local tag
local td
local url="https://github.com/mozilla/sccache"
triple="${1}"

install_packages ca-certificates curl unzip

# install rust and cargo to build sccache
export RUSTUP_HOME=/tmp/rustup
export CARGO_HOME=/tmp/cargo
curl --retry 3 -sSfL https://sh.rustup.rs -o rustup-init.sh
sh rustup-init.sh -y --no-modify-path
rm rustup-init.sh
export PATH="${CARGO_HOME}/bin:${PATH}"
rustup target add "${triple}"

# download the source code from the latest sccache release
td="$(mktemp -d)"
pushd "${td}"
tag=$(git ls-remote --tags --refs --exit-code \
"${url}" \
| cut -d/ -f3 \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort --version-sort \
| tail -n1)
curl -LSfs "${url}/archive/refs/tags/${tag}.zip" \
-o sccache.zip
unzip sccache.zip
mv "sccache-${tag//v/}" sccache
rm sccache.zip

# build from source for the desired architecture
# you can also use additional features here
cd sccache
cargo build --release --target "${triple}" \
--features=all,"openssl/vendored"
cp "target/${triple}/release/sccache" "/usr/bin/sccache"

# clean up our install
rm -r "${RUSTUP_HOME}" "${CARGO_HOME}"
purge_packages
popd
rm -rf "${td}"
rm "${0}"
}

main "${@}"
Loading