mitnk / cicada

An old-school bash-like Unix shell written in Rust
https://hugo.wang/cicada/
MIT License
981 stars 50 forks source link

Is BUILD_DATE stale without a prior `make clean`, for successive `make` calls? #7

Closed ghost closed 6 years ago

ghost commented 6 years ago

How do you ensure that the BUILD_DATE env var from here: https://github.com/mitnk/cicada/blob/340e8136465863c07832c9a19261c0b75b4034a5/src/build.rs#L15 is being updated upon each successful compilation, without having to manually make clean before make ?

If my understanding is correct(and I tested this a lil bit on my test project), cargo caches the output of build.rs and if you just touch src/main.rs for example, but not also touch build.rs, it will use the cached output and thus BUILD_DATE(and GIT_HASH for that matter) will be the stale one.

mitnk commented 6 years ago

I just tested on Mac with rustc 1.24.0-nightly (cargo 0.25.0-nightly) - if I change (or just touch) main.rs and make, then the env BUILD_DATE changes on each make.

ghost commented 6 years ago

I can confirm the same! And I've also tested it on a new project and even a project within a workspace, both seem to update as expected!

I must be hitting an edge case for my particular project and I wrongly assumed it happens for any project!

Apologies for wasting your time. I will edit this post if I figure out what was that edge case for my project.

Closing, as it's obviously not an issue for cicada!

mitnk commented 6 years ago

Never mind @xftroxgpx, we all learners :)

ghost commented 6 years ago

Thanks @mitnk ! Figured it out. It failed for me because I had this line in my build.rs

  println!("cargo:rerun-if-env-changed=A"); //if the environment variable's value changes the build script should be rerun.  

If I remove the line, it works as intended. Otherwise, sometimes, it just won't recompile build.rs after src/main.rs is touched.

Doc for that is here: http://doc.crates.io/build-script.html#outputs-of-the-build-script

Seems like a cargo bug, or I'm misunderstanding something here.

Simple test project here My convoluted test project is here

PS: was using cargo 0.26.0 (git master) and rustc 1.24.0-dev (687d3d15b 2018-01-02), in this whole thread.