shadow-rs icon indicating copy to clipboard operation
shadow-rs copied to clipboard

Fast no-op compile for release mode?

Open lgarron opened this issue 6 months ago • 2 comments

I'm looking at options for embedding source tree metadata into Rust binaries, and CLAP_LONG_VERSION from shadow-rs seems to do the job well.

However, the second project I tried it on is https://github.com/cubing/twsearch/ , which is much slower in debug mode and therefore requires developing using release mode. Unfortunately:

Mode without shadow-rs with shadow-rs
debug (incremental) 1.37s 2.15s
debug (no-op) 0.38s 0.38s
release (incremental) 5.45s 6.13s
release (no-op) 0.34s 🚨 6.25s

We do have some situations where we expect the no-op compilation to be fast, and we can't really handle an extra 6 seconds for that.

Is there a simple way to skip the compilation if the following hold?

  • The commit hash is unchanged.
  • The build time is within, say… one hour of the previously used time?

Rounding down to the nearest hour would also work, and perhaps avoid implying extra precision for incremental compiles.

lgarron avatar Jun 19 '25 02:06 lgarron

The possible reason is the time consumption caused by executing the cargo tree or cargo metadata command.

baoyachi avatar Jun 23 '25 00:06 baoyachi

I have similar issue, I have below in my main(), and in release mode, even there is no change, it always rebuild the crate and cause rebuild or downstream crates. I tried BuildPattern::Custom with path, but it still rebuild even point it to build.rs file itself.

    ShadowBuilder::builder()
        .build_pattern(BuildPattern::Lazy)
        .build()
        .expect("Must build shadow-rs");

simon-1M avatar Jul 09 '25 12:07 simon-1M