Open lcheylus opened 8 months ago
Sounds good! Would you like to put up a PR for this?
I'm currently doing some tests (WIP to add CI for OpenBSD :), GH workflow similar to the FreeBSD one).
I will propose a fix/PR to support Rust cache in the FreeBSD workflow and some improvements inspired by the FreeBSD workflow from the rustup project.
After some analysis and (a lot of) tests, I have a working "rework" of the FreeBSD workflow using Swatinem/rust-cache
and mozilla-actions/sccache-action
:)
The workflow have 2 jobs :
cargo fmt
and cargo clippy
cargo nextest
The both jobs are executed with the vmactions/freebsd-vm action : FreeBSD stable (current version 14.0) VM runned in Ubuntu latest
GH runner.
I have reorg the code of the workflow, inspired by the job build-freebsd
from the CI workflow of the rustup project => https://github.com/rust-lang/rustup/blob/master/.github/workflows/ci.yaml#L1025
Both jobs started with prepare
task to install necessary packages (with pkg
FreeBSD command), create a temporary user tester
(via shell) then run a script shell with sudo -E -u ${TEST_USER}
to execute further tasks:
ci/freebsd_style_lint.sh
scriptci/freebsd_tests.sh
scriptWith this separation between jobs defined in workflow (YAML format) and shell scripts, it's easier to modify them if needed.
I have also remove the definition of the jobs matrix (GH runner is always ubuntu-latest
) and define feature = "unix"
in workflow environment.
(The easiest part)
This action is only used in "Tests" job (not used for cargo fmt
and cargo clippy
in "Style and Lint" job).
SCCACHE_GHA_ENABLED: "true"
and RUSTC_WRAPPER: "sccache"
in job env.FEATURES SCCACHE_GHA_ENABLED RUSTC_WRAPPER ACTIONS_CACHE_URL ACTIONS_RUNTIME_TOKEN
variables for FreeBSD VM (variable envs
for this action)sccache
package for the FreeBSD VMci/freebsd_tests.sh
script, exec command sccache --show-stats > "${WORKSPACE}/sccache-stats.txt" 2>&1
to get the sccache stats in a text file => copyback to the Ubuntu host (see the section below for the copyback
enabled option).During the "Tests" job, sccache is correctly used by rustc
and the cached files are read/written using ACTIONS_CACHE_URL/ACTIONS_RUNTIME_TOKEN
parameters.
After some tests, I found that this action is not very useful : cache hits are low => only 3 / 193 compile requests.
I'm waiting your comments to decide if we must keep this action or suppress it.
Action used in the both jobs : "Style and Lint" and "Tests".
In the "Configure" step of this action, a cache key is created using Rust version (get via rust -vV
command). To have a functional cache used in FreeBSD VM, this version must be the same as used on FreeBSD.
I created a shell script to fake the output of rustc -vV
command => ci/fake_rustc_freebsd-stable.sh
, returns rustc version rustc 1.75.0 (82e1608df 2023-12-21)
for FreeBSD (host: x86_64-unknown-freebsd
).
rustc
binary on Ubuntu runner is copied for backupfake_rustc_freebsd-stable.sh
is copied as ~/.cargo/bin/rustc
~/.cargo/bin/rustc -vV
)prefix-key: "v0-rust-freebsd"
is defined for the action to add a specific prefix when creating the cache key.In the FreeBSD VM action, I enabled the copyback
parameter to use the Rust cache:
cargo clean
to keep the created files by rustc/cargo
After some runs, using Rust cache is efficient:
You can check a complete run of this modified workflow on my own repository https://github.com/lcheylus/rust-coreutils/actions/runs/7552906886
You could also check my modified code on it (ugly main
branch without rebase and also my ongoing work to add CI for OpenBSD).
I'm waiting your comments before splitting/rebasing my work in a separate branch and submitting a PR for merge.
@sylvestre @tertsdiepraam Comments welcome.
In FreeBSD GH workflow (defined in
.github/workflows/freebsd.yml
), GH actions are used to cache the Rust build artefacts:Theses actions are useless because the Rust build artefacts are not copied back from FreeBSD guest to Ubuntu GH runner after build:
sync: rsync
copyback: false
.Proposal to remove the 2 actions in FreeBSD workflow or to fix sync of files between guest/host after build to use cache.