build: reduce checkout-specific inputs for cache reuse (#9198)

* test(mito2): cover regex inverted index pruning

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* build: keep build inputs checkout-relative for cross-worktree cache reuse

Two small changes so compilations are byte-identical across worktrees
of the same commit and can share a build cache (mbx, sccache):

- src/common/version/build.rs: derive the workspace root relative to
  CARGO_MANIFEST_DIR instead of the CARGO_WORKSPACE_DIR injected by
  .cargo/config.toml (an absolute path). The env var remains as an
  explicit override for the submodule case; the [env] injection in
  .cargo/config.toml is removed so the relative derivation is used by
  default.
- Replace three env!("CARGO_MANIFEST_DIR") uses in test/bench code
  (servers prom_decode bench + decode test, common-meta test_util)
  with a runtime std::env::var lookup, so the compiled artifact no
  longer embeds the checkout path.

No behavior change: same files are read, same version info emitted.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* build: address cross-worktree cache review feedback

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
discord9
2026-10-12 08:08:21 +00:00
committed by GitHub
parent 29d5854e6a
commit f50f42140a
7 changed files with 46 additions and 13 deletions
+3 -2
View File
@@ -21,5 +21,6 @@ checkout = true
list_files = true
internal_use_git2 = false
[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
# Avoid globally injecting a checkout-specific workspace path. The version build script
# resolves the absolute workspace path from layout at build time; set CARGO_WORKSPACE_DIR
# explicitly when this repo is built as a submodule.
+9
View File
@@ -41,3 +41,12 @@ cargo nextest run -p common-meta
```
Backend-specific coverage may also need `pg_kvbackend` or `mysql_kvbackend`.
`test_util::etcd_certs_dir` and `test_util::test_certs_dir` resolve fixture
certificates using `CARGO_MANIFEST_DIR` at **run time** (`std::env::var`, not `env!`).
`cargo nextest run` sets it; direct test-binary execution requires setting the
variable to the crate directory. Run this example from the repository root:
```bash
CARGO_MANIFEST_DIR="$PWD/src/common/meta" ./target/debug/deps/<test_binary>
```
+4 -4
View File
@@ -322,8 +322,8 @@ macro_rules! maybe_skip_etcd_tls_integration_test {
/// Returns the directory of the etcd TLS certs.
pub fn etcd_certs_dir() -> PathBuf {
let project_path = env!("CARGO_MANIFEST_DIR");
let project_path = PathBuf::from(project_path);
let project_path =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
let base = project_path.ancestors().nth(3).unwrap();
base.join("tests-integration")
.join("fixtures")
@@ -332,8 +332,8 @@ pub fn etcd_certs_dir() -> PathBuf {
/// Returns the directory of the test certs.
pub fn test_certs_dir() -> PathBuf {
let project_path = env!("CARGO_MANIFEST_DIR");
let project_path = PathBuf::from(project_path);
let project_path =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
let base = project_path.ancestors().nth(3).unwrap();
base.join("tests-integration")
.join("fixtures")
+14 -5
View File
@@ -30,12 +30,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-env-changed=RUSTC");
println!("cargo:rerun-if-env-changed=GREPTIME_PRODUCT_NAME");
println!("cargo:rerun-if-env-changed=CARGO_WORKSPACE_DIR");
// The "CARGO_WORKSPACE_DIR" is set manually (not by Rust itself) in Cargo config file, to
// solve the problem where the "CARGO_MANIFEST_DIR" is not what we want when this repo is
// made as a submodule in another repo.
let workspace_dir =
env::var("CARGO_WORKSPACE_DIR").or_else(|_| env::var("CARGO_MANIFEST_DIR"))?;
// Resolve the workspace root from CARGO_MANIFEST_DIR (this crate is
// src/common/version, three levels below the root). The path remains absolute
// and is used at build time. CARGO_WORKSPACE_DIR remains an explicit override
// for submodule builds; see https://github.com/rust-lang/cargo/issues/3946.
let workspace_dir = match env::var("CARGO_WORKSPACE_DIR") {
Ok(dir) if !dir.is_empty() => dir,
_ => env::var("CARGO_MANIFEST_DIR").map(|dir| {
PathBuf::from(dir)
.join("../../..")
.to_string_lossy()
.into_owned()
})?,
};
let workspace_root = PathBuf::from(&workspace_dir);
println!(
"cargo:rerun-if-changed={}",
+10
View File
@@ -43,3 +43,13 @@ cargo nextest run -p servers
Keep protocol translation here and permissions/database behavior in frontend.
Async table batching returns storage-completion futures with its early
acknowledgements. Keep completion reporting independent of the caller's lifetime.
`prom_remote_write/decode.rs` and `benches/prom_decode.rs` resolve
`benches/write_request.pb.data` using `CARGO_MANIFEST_DIR` at **run time**
(`std::env::var`, not `env!`). `cargo nextest run` and `cargo bench` set it;
direct test/benchmark-binary execution requires setting it to the crate directory.
Run this example from the repository root:
```bash
CARGO_MANIFEST_DIR="$PWD/src/servers" ./target/debug/deps/<test_or_bench_binary>
```
+3 -1
View File
@@ -27,7 +27,9 @@ use servers::prom_remote_write::validation::{PromValidationMode, validate_label_
use servers::prom_store::to_grpc_row_insert_requests;
fn load_fixture_v1_bytes() -> Vec<u8> {
let mut d = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut d = std::path::PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"),
);
d.push("benches");
d.push("write_request.pb.data");
std::fs::read(d).expect("read write_request.pb.data fixture")
+3 -1
View File
@@ -448,7 +448,9 @@ mod tests {
#[test]
fn test_decode_write_request() {
let mut d = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut d = std::path::PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"),
);
d.push("benches");
d.push("write_request.pb.data");
let data = std::fs::read(d).unwrap();