Skip to content

Commit

Permalink
ci: enable 'librocksdb-sys' to be able to be properly cached
Browse files Browse the repository at this point in the history
Today we leverage the 'Swatinem/rust-cache' github action in order to
cache rust third-party dependencies and avoid needing to rebuild them
every time CI is run. Unfortunately it was identified that despite a
cache hit the 'librocksdb-sys' crate was always retriggering a very
costly build.

The crux of the issue is mostly highlighted by this issue
(rust-rocksdb/rust-rocksdb#574) on the
rust-rocksdb repository. The 'librocksdb-sys' crate uses a build script
to be able to build the c++ rocksdb project (tracked via a submodule in
the rust-rocksdb repo) and makes use of of the cargo directive
"cargo:rerun-if-changed=rocksdb/" to ensure that anytime the submodule
is updated that the c++ code should be recompiled. In particular this
cargo directive only uses the filesystem last-modified "mtime" timestamp
to determine if the file has changed
(https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorerun-if-changedpath).

The 'Swatinem/rust-cache' action explicitly avoids caching the
'.cargo/registry/src' directory since its faster for cargo to repopulate
the unpacked crate src from their archives in '.cargo/registry/cache'
(which is cached by the github action). This leads to the unintended
consiquency that when cargo goes to unpack the 'librocksdb-sys' crate
src, the mtime of the "rocksdb/" directory no longer matches the cached
mtime that was restored from a previous build of the 'librocksdb-sys'
dependency resulting in 'librocksdb-sys' being rebuilt.

In order to fix this issue we can additionally cache the
'.cargo/registry/src/*/librocksdb-sys-*' directory (since the github
caching infrastructure preserves mtimes of cached files) and ensure that
the mtime matches what cargo expects, avoiding a rebuild. In order to do
this I've forked the 'Swatinem/rust-cache' action to 'bmwill/rust-cache'
add added the ability to additionally specify other paths that should be
cached and specified the '.cargo/registry/src/*/lib-rocksdb-sys-*'
directory.
  • Loading branch information
bmwill committed Mar 31, 2022
1 parent b1c0b74 commit 4735504
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: Swatinem/rust-cache@v1
# Enable caching of the 'librocksdb-sys' crate by additionally caching the
# 'librocksdb-sys' src directory which is managed by cargo
- uses: bmwill/rust-cache@v1 # Fork of 'Swatinem/rust-cache' which allows caching additional paths
with:
path: ~/.cargo/registry/src/**/librocksdb-sys-*
- name: cargo test
uses: actions-rs/cargo@v1
with:
Expand All @@ -76,7 +80,11 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
components: clippy
- uses: Swatinem/rust-cache@v1
# Enable caching of the 'librocksdb-sys' crate by additionally caching the
# 'librocksdb-sys' src directory which is managed by cargo
- uses: bmwill/rust-cache@v1 # Fork of 'Swatinem/rust-cache' which allows caching additional paths
with:
path: ~/.cargo/registry/src/**/librocksdb-sys-*
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -112,7 +120,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: Swatinem/rust-cache@v1
# Enable caching of the 'librocksdb-sys' crate by additionally caching the
# 'librocksdb-sys' src directory which is managed by cargo
- uses: bmwill/rust-cache@v1 # Fork of 'Swatinem/rust-cache' which allows caching additional paths
with:
path: ~/.cargo/registry/src/**/librocksdb-sys-*
- name: Install cargo-udeps, and cache the binary
uses: baptiste0928/cargo-install@v1
with:
Expand Down

0 comments on commit 4735504

Please sign in to comment.