Skip to content

Commit

Permalink
Use Cargo.lock from workspace root (if available) (#111)
Browse files Browse the repository at this point in the history
When using macrotest, to make output consistent, it is necessary to
pin to a particular version of Nightly Rust.

But of course usptream Nightly Rust changes, and that means that
dependencies (of the macro package under test) may need to be updated
upstream.  Sometimes those updates aren't compatible with our pinned
Nightly.

Therefore, tests must run with pinned versions of the dependencies,
not just pinned versions of the compiler.  Without this, we can run
into trouble, as seen here, for example:
  https://gitlab.torproject.org/Diziet/rust-derive-deftly/-/issues/60

Borrow a trick from dtolnay's trybuild, which faces the same problem:
copy the outer workspace's Cargo.lock into the synthetic crate.
This influences Cargo's resolver sufficiently; but since we run
without --locked, Cargo can still adjust the file as needed for the
synthetic crate.
  • Loading branch information
ijackson authored Apr 23, 2024
1 parent e4bc0c5 commit 839a03e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ fn prepare(tests: &[ExpandedTest]) -> Result<Project> {
fs::write(path!(project.dir / "Cargo.toml"), manifest_toml)?;
fs::write(path!(project.dir / "main.rs"), b"fn main() {}\n")?;

let source_lockfile = path!(project.workspace / "Cargo.lock");
match fs::copy(source_lockfile, path!(project.dir / "Cargo.lock")) {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(0),
otherwise => otherwise,
}?;

fs::create_dir_all(&project.inner_target_dir)?;

cargo::build_dependencies(&project)?;
Expand Down

0 comments on commit 839a03e

Please sign in to comment.