akubera / bigdecimal-rs

Arbitrary precision decimal crate for Rust
Other
275 stars 71 forks source link

bigdecimal `0.4.0` always forces a rebuild (on mac) #105

Closed alamb closed 1 year ago

alamb commented 1 year ago

After we updated to bigdecimal 0.4.0 in https://github.com/apache/arrow-datafusion/pull/6848 our project now always rebuilds even when we make no code change

Reproducer

run this in this repository:

cargo test
cargo test

I expect the second invocation of cargo test not to recompile, it should just rerun the test

In DataFusion, when I run cargo test -v

the following is output in the following line

       Dirty bigdecimal v0.4.0: the file `/Users/alamb/Software/target-df2/debug/build/bigdecimal-b4aed73795116eae/out/default_precision.rs` has changed (1688920018.458734757s, 202831743ns after last build at 1688920018.255903014s)
   Compiling bigdecimal v0.4.0

It appears to me that the issue is that build.rs always rewrites default_precision.rs even when there are no changes:

https://github.com/akubera/bigdecimal-rs/blob/b80509a8be4d77149388311a486c754cb4bb1a76/build.rs#L16

I think this could be fixed by checking if the contents of default_precision.rs would be changed prior to rewriting them

akubera commented 1 year ago

I can reproduce this on my macbook, but running multiple builds on my Linux machine does not trigger a recompile. I'm not sure why there will be a difference.

It's been merged and will be in v0.4.1, soon.

alamb commented 1 year ago

It's been merged and will be in v0.4.1, soon.

Thank you @akubera -- I was also seeing this on Mac

Do you have any idea when yo plan to release 0.4.1? There is no rust from my perspective, but if it will be more than a day or so I plan to downgrade back to 0.3.0 until it is ready

rukai commented 1 year ago

I think some cases have been fixed, but I still see bigdecimal get rebuilt sometimes and im not sure what the pattern is yet.

rukai commented 1 year ago

Oh I've figured it out. It always triggers a rebuild on the second compile, after that it settles down and stops recompiling.

I ran with cargo build --verbose and saw the reason for rebuild listed as: image

rukai commented 1 year ago

I think you could use this macro https://docs.rs/const-str/latest/const_str/macro.parse.html and println!("cargo:rustc-env=DEFAULT_PRECISION={default_precision}"); to avoid having to generate a .rs file

I've used rustc-env without rebuilding issues like this https://github.com/shotover/shotover-proxy/blob/468cea8afab29a2c5eb9798b73971337b04d89ce/shotover-proxy/build.rs#L5

akubera commented 1 year ago

Unfortunately its minimum Rust version is 1.64.0, and this project supports older versions.

But that is a good crate to know, thanks!