Skip to content

ci: fix Rust caching and follow rust-toolchain.toml - #207

Merged
Xuanwo merged 10 commits into
mainfrom
xuanwo/ci-cmake-rust-cache
Nov 25, 2026
Merged

Xuanwo merged 10 commits into
mainfrom
xuanwo/ci-cmake-rust-cache

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Advances #195 (caching) and #197. Two partials are called out below.

Caching (#195)

  • CMakeLists.txt resolves the Cargo target directory once into LANCEDB_CARGO_TARGET_DIR (default unchanged: <build>/target). A relative value is resolved against the build directory, so Cargo, Ninja, the install rules and the exported package all name one absolute path. CI points it at $GITHUB_WORKSPACE/target, the directory the rust cache action restores by default; cargo clippy already used the repository-root target, so the cache covers the lint step too. On Windows hosts the resolved value is also converted to CMake slash form, because cmake_install.cmake reads a native D:\a\... path as an escape sequence and installs the wrong file or fails.
  • Each build matrix leg gets its own cache key. Previously the static leg saved a cache under the shared job key and the later shared leg found it up to date and skipped saving, so cargo clippy --all-targets recompiled on every run.
  • build_almalinux now caches the container workspace target under its own key: the container mounts the checkout at /__w/... while github.workspace is the host path, so the build previously wrote a directory the cache never saw, and the old full-match entry would otherwise make the action skip saving the corrected tree.
  • cbindgen 0.29.4 is downloaded from the official mozilla/cbindgen release at the exact version already required by .github/scripts/check_abi.py, with the asset checksum verified, instead of compiling it from source on every cold run.
  • external-provider-lib now passes the same LANCEDB_BUILD_VERSION as rust-lib, so an environment change no longer reruns the lancedb-c build script.

Redundant rebuilds: what is and is not fixed

An earlier revision shared one Cargo unit between rust-lib and external-provider-lib by selecting the export wrapper through Cargo's target linker configuration. Review found two problems, so it was reverted:

  • That configuration replaces a caller's own linker (config file, target env or CARGO_TARGET_<triple>_LINKER). The final-target wrapper preserves it: build.rs forwards RUSTC_LINKER and the wrapper uses it.
  • The shared unit's SONAME identity came from an environment variable Cargo does not fingerprint, so whichever command ran first owned liblancedb.so. With the final-target wrapper the provider never uplifts the library, and the rust-lib command owns it in both invocation orders.

Remaining: ninja plus ninja check-install still compiles lancedb-c three times (rust-lib, provider, check-install's rust-lib) because the two commands produce different Cargo units. Making it once needs either a structural split of the provider's type dependency or a global linker takeover; both are outside this change. The rebuilds no longer repeat for environment or version changes, and the cached target directory keeps the dependency crates from recompiling.

Rust toolchain setup (#197)

Every rustup-based CI and packaging job runs rustup toolchain install, taking channel, profile and components (rustfmt, clippy) from rust-toolchain.toml. The cross job adds its Windows target and the packaging jobs add their matrix target with rustup target add. No workflow hardcodes a Rust version or @stable. CARGO_INCREMENTAL: 0 is set at the workflow level to preserve what the removed action exported.

The mechanism proposed in #197 (dtolnay/rust-toolchain@master without the toolchain input) does not work: the action requires that input and exits before rustup runs. #197 stays partial pending the #198 compatibility-matrix decision.

AlmaLinux conflict

build_almalinux keeps the AlmaLinux system Rust to preserve distro-provided toolchain coverage from #109; #197's "every job compiles with the pinned Rust" criterion is intentionally not met for this job. Retiring that coverage is a direction decision, not made here.

Validation

  • Linker/rebuild fixture: with the final-target wrapper a caller-configured linker is still invoked (traced, version script present); rust-lib produces the SONAME and export-filtered library; a provider-first build uplifts no library and the following rust-lib build produces the correct artifact. Rebuild counts on a fresh target are 1/1/1 for rust-lib/provider/rust-lib.
  • Configuration matrix: typed and untyped relative values, a relative value with an explicit target triple, an absolute path with spaces, and the default all resolve to one absolute path, stable across reconfigure, with matching Ninja rpath and install paths.
  • Hosted: native CI run 45611803357 on this head; the AlmaLinux job runs cold on its new cache key (the old AlmaLinux cache entry was not accessed by the new run) and must build and save it. The package path (packages.yml and package.py) is unchanged by this workflow-only AlmaLinux fix, so the earlier five-platform build-only evidence remains valid and no new package dispatch is needed.

The rust-lib edge passed the export wrapper and the SONAME through
`cargo rustc --` arguments. Those arguments change the unit profile, so
the external-provider build that pulls lancedb-c in as a dependency
rebuilt it with a plain profile, and the rust-lib run behind
check-install rebuilt it back. Select the wrapper through Cargo's target
linker configuration instead, which every invocation that compiles
lancedb-c presents identically, and hand the SONAME to the wrapper from
the rust-lib command environment so it reaches the lancedb cdylib alone.

The Cargo target directory moves into LANCEDB_CARGO_TARGET_DIR with the
same default, so a build can point Cargo at the directory CI caches.
Point CMake at the repository-root target directory that the cache action
restores, give each build matrix leg its own cache key, cache the
AlmaLinux job, and start a new cache generation because the linker
configuration is a Cargo fingerprint input the action's key cannot see.
Install cbindgen from the pinned official release asset instead of
compiling it on every cold run.

Every rustup-based CI and packaging job now installs its toolchain from
rust-toolchain.toml, so the pinned channel, profile and components come
from one file. The AlmaLinux job keeps the distro toolchain to preserve
the distro compatibility coverage from #109.
/usr/local/bin belongs to root on the runner image, so the download is
verified in the workspace and only the checked file is copied with
privileges.
LANCEDB_CARGO_TARGET_DIR could be typed as a relative path. CMake retyped
an untyped -D value against its invocation directory, Cargo passed the
string to --target-dir under the source directory, Ninja used it relative
to the build directory and the install rules resolved it against the
configure directory. All of them now use one absolute path resolved
against the build directory.
Selecting the export wrapper through Cargo's target linker configuration
replaced a caller's configured linker for every unit and made the
provider and rust-lib commands share one Cargo unit whose SONAME identity
came from an environment variable the fingerprint ignores. Pass the
wrapper and SONAME as `cargo rustc --` arguments for the lancedb target
only: build.rs forwards the caller's configured linker through
RUSTC_LINKER, the provider never uplifts a library, and the rust-lib
command owns the artifact.

The provider keeps the CMake-resolved LANCEDB_BUILD_VERSION so its build
no longer reruns the lancedb-c build script for a changed environment.
The build no longer selects a linker through Cargo's target
configuration, so the restored target directories keep valid
fingerprints and the cache keys do not need a new generation.
@Xuanwo Xuanwo changed the title ci: fix Rust caching, redundant lancedb-c rebuilds and toolchain pinning ci: fix Rust caching and follow rust-toolchain.toml Nov 25, 2026
CI passes ${{ github.workspace }}/target, which is a native Windows path
such as D:\a\lancedb-c\lancedb-c/target. CMake wrote that value into
cmake_install.cmake unchanged, where file(INSTALL ...) read the
backslash as an escape and either rejected the path or resolved a
different file.

Normalize the resolved target directory to CMake slash form on Windows
hosts. Other hosts keep their native characters, and the documented
relative resolution, spaces and cross-compile behavior are unchanged.
The AlmaLinux job runs in a container where github.workspace is the host
path (/home/runner/work/...) while the checkout is mounted at /__w/....
CMake built into the host path while the Rust cache cleaned and saved
the container path, so this job never restored its target artifacts.

Use the step shell's GITHUB_WORKSPACE so CMake, Cargo and the cache name
the same container path. The previous full-match cache entry would
otherwise make the action skip saving the corrected target tree, so the
job gets its own cache key.
@Xuanwo
Xuanwo merged commit 2319227 into main Nov 25, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant