diff --git a/Cargo.toml b/Cargo.toml index 730bb385..e87b48a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,16 @@ size-of = { version = "0.1", package = "feldera-size-of", features = ["ordered-f rkyv = { version = "0.7", default-features = false, features = ["std", "size_64", "validation", "uuid"] } dbsp = "0.98" once_cell = "1" +# Resolution constraint only; no code here names this crate. `tinyvec` arrives +# transitively through Bevy's text and font stack, and 1.13.0 imports +# `alloc::vec` as a module and then invokes the `vec!` macro, which the pinned +# nightly rejects with "cannot find macro `vec` in this scope". This workspace +# commits no `Cargo.lock`, so without the bound every build resolves the broken +# release and `make lint` fails. A tilde requirement, permitted by `AGENTS.md` +# for a documented lock to patch-level updates, holds resolution at 1.12. +# Upstream: Lokathor/tinyvec#225 reports it, Lokathor/tinyvec#226 proposes the +# fix. Remove this entry per https://github.com/leynos/lille/issues/340. +tinyvec = "~1.12" [target.'cfg(target_os = "linux")'.dependencies] bevy = { workspace = true, default-features = false, features = ["x11"] } diff --git a/docs/developers-guide.md b/docs/developers-guide.md index 2f0a8456..18c9c371 100644 --- a/docs/developers-guide.md +++ b/docs/developers-guide.md @@ -292,6 +292,42 @@ circuit.step()?; assert_eq!(collect_weighted(&output), vec![(7, 2)]); ``` +## Dependency resolution constraints + +No `Cargo.lock` is committed, so Cargo resolves the graph afresh on every +machine and every CI run. A broken release of a transitive dependency +therefore reaches the build the day it is published, and the only lever is a +direct requirement in `Cargo.toml`. + +`tinyvec = "~1.12"` is such a lever. It is a direct Cargo dependency, but no +source file in this repository names the crate: it arrives through Bevy's text +and font stack, and the requirement exists only to bound what Cargo resolves. + +Version 1.13.0, published on 2026-09-03, imports `alloc::vec` as a module and +then invokes the `vec!` macro, which the pinned nightly rejects with +``cannot find macro `vec` in this scope``. Every `--all-features` build and +`make lint` fail on it. The requirement is a tilde rather than a caret because +it must hold at 1.12 until the breakage is fixed; `AGENTS.md` permits that for +a documented lock to patch-level updates. + +`tests/dependency_resolution.rs` reads what Cargo resolved and fails if 1.13 or +later was selected, naming the version. It is a post-resolution check, not a +pre-build gate: Cargo compiles the graph before an integration test runs, so a +selected 1.13.0 fails the build first with the macro error above. What the test +catches directly is the case that would otherwise pass silently, a widened +requirement whose resolved version still compiles but sits outside the range +this workspace has verified. Diagnose a build that fails this way with +`cargo tree --invert tinyvec`. + +Remove the requirement and the test together once upstream ships a fixed +release or yanks 1.13.0, tracked in +[issue 340](https://github.com/leynos/lille/issues/340). Upstream discussion is +in Lokathor/tinyvec#225 and Lokathor/tinyvec#226. + +A future constraint of this kind belongs here too: a bare version requirement +with no explanation is indistinguishable from a real dependency, and the next +contributor will not know whether removing it is safe. + ## Commit gates Run the deterministic gates before committing (see `AGENTS.md` and the diff --git a/tests/dependency_resolution.rs b/tests/dependency_resolution.rs new file mode 100644 index 00000000..e3910b45 --- /dev/null +++ b/tests/dependency_resolution.rs @@ -0,0 +1,118 @@ +//! Guards the dependency-resolution constraints this workspace relies on. +//! +//! `tinyvec` reaches the build transitively through Bevy's text and font +//! stack, and no `Cargo.lock` is committed, so resolution is decided afresh on +//! every machine. This test reads what Cargo resolved and names the version it +//! chose. +//! +//! It is a post-resolution check, not a pre-build gate. Cargo compiles the +//! dependency graph before an integration test runs, so when a broken release +//! is selected the build fails first, deep inside the crate, with +//! ``cannot find macro `vec` in this scope``. This test then reports the +//! selected version on the next run, once the constraint is back. What it +//! catches directly is the case that would otherwise pass silently: a widened +//! requirement whose resolved version still compiles but is outside the range +//! this workspace has verified. +//! +//! Remove it with the constraint itself, per +//! . + +use std::process::Command; + +use rstest::rstest; + +/// Crate whose resolved version this workspace constrains. +const CONSTRAINED_CRATE: &str = "tinyvec"; + +/// First release of that crate which does not build here, as major and minor. +const FIRST_BROKEN_RELEASE: (u64, u64) = (1, 13); + +/// A resolved semantic version, kept whole so failures can name it. +#[derive(Debug, Clone)] +struct ResolvedVersion { + /// Version exactly as Cargo reported it. + text: String, + /// Major and minor components, for ordering against a known-bad release. + series: (u64, u64), +} + +impl ResolvedVersion { + /// Parses a Cargo version string, keeping the original text. + fn parse(text: &str) -> Result { + let mut parts = text.split(['.', '-', '+']); + let mut component = |name: &str| -> Result { + parts + .next() + .and_then(|part| part.parse::().ok()) + .ok_or_else(|| format!("cannot read the {name} version from `{text}`")) + }; + let major = component("major")?; + let minor = component("minor")?; + Ok(Self { + text: text.to_owned(), + series: (major, minor), + }) + } + + /// Reports whether this release is the broken one or anything later. + const fn is_broken_or_later(&self) -> bool { + self.series.0 > FIRST_BROKEN_RELEASE.0 + || (self.series.0 == FIRST_BROKEN_RELEASE.0 && self.series.1 >= FIRST_BROKEN_RELEASE.1) + } +} + +/// Returns every version of a crate that `cargo metadata` resolved. +/// +/// Returns an error rather than panicking so the test reports a resolution +/// failure and a parse failure differently. +fn resolved_versions(name: &str) -> Result, String> { + let output = Command::new(env!("CARGO")) + .args(["metadata", "--format-version", "1"]) + .current_dir(env!("CARGO_MANIFEST_DIR")) + .output() + .map_err(|err| format!("cannot run `cargo metadata`: {err}"))?; + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + return Err(format!("`cargo metadata` failed: {stderr}")); + } + let metadata: serde_json::Value = serde_json::from_slice(&output.stdout) + .map_err(|err| format!("cannot parse `cargo metadata` output: {err}"))?; + let packages = metadata + .get("packages") + .and_then(serde_json::Value::as_array) + .ok_or_else(|| "`cargo metadata` reported no packages".to_owned())?; + packages + .iter() + .filter(|package| package.get("name").and_then(serde_json::Value::as_str) == Some(name)) + .map(|package| { + let version = package + .get("version") + .and_then(serde_json::Value::as_str) + .ok_or_else(|| format!("`{name}` has no version string"))?; + ResolvedVersion::parse(version) + }) + .collect() +} + +#[rstest] +fn the_constrained_crate_resolves_below_its_broken_release() { + let resolved = resolved_versions(CONSTRAINED_CRATE) + .unwrap_or_else(|err| panic!("dependency resolution must be readable: {err}")); + assert!( + !resolved.is_empty(), + "`{CONSTRAINED_CRATE}` must still be in the dependency graph; if it has gone, drop its \ + constraint from Cargo.toml and delete this test" + ); + let broken: Vec<&str> = resolved + .iter() + .filter(|version| version.is_broken_or_later()) + .map(|version| version.text.as_str()) + .collect(); + let (major, minor) = FIRST_BROKEN_RELEASE; + assert!( + broken.is_empty(), + "`{CONSTRAINED_CRATE}` resolved to {broken:?}, at or beyond {major}.{minor}, which does \ + not build on the pinned nightly; keep the `~1.12` requirement in Cargo.toml until \ + leynos/lille#340 is closed" + ); +}