eupn / macrotest

Test harness for declarative and procedural macros expansion via `cargo-expand`
47 stars 9 forks source link

macrotest and trybuild together keep doing rebuilds #83

Closed ijackson closed 5 months ago

ijackson commented 1 year ago

Steps to reproduce:

(install nightly Rust and cargo-expand)
git clone https://github.com/taiki-e/pin-project
cd pin-project
cargo +nightly --locked --offline test --workspace -- ui # 1
cargo +nightly --locked --offline test --workspace -- ui # 2
cargo +nightly --locked --offline test --workspace -- expandtest # 3
cargo +nightly --locked --offline test --workspace -- expandtest # 4
cargo +nightly --locked --offline test --workspace -- ui # 5
cargo +nightly --locked --offline test --workspace -- expandtest #6

Expected behaviour: In steps 1 and 3, some actual compilation work takes place. In steps 2,4,5,6, nothing much is compiled and the tests run quickly.

Actual behaviour: In steps 5 and 6, many things are rebuilt including proc-macro2, syn, ...

I don't know what is going on here, and the root cause is almost certainly a bug in cargo. But I think it would be good if both macrotest and trybuild could work around it. Probably, the best workaround is for them each to use a separate target directory. That would involve rebuilding extra things on the first iteration, but thereeafter the previously built things would be reused.

This happened to me with an unpublished version of a package of mine. When investigating I thought this seemed to be a bug elsewhere, so I looked through the rdependencies of macrotest for a package which used both. pin-project was the obvious candidate, and indeed it is affected. I looked at the test driver code in pin-project and there doesn't seem to be anything unexpected there that might cause this problem.

Since github doesn't support a single issue affecting multiple projects, and anyway I think probably it would be nice if both packages were changed to incorporate a workaround (even though I think one package doing so would suffice), I am filing an identical ticket against trybuild too.