-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo sometimes fails to run a build.rs that generates the src/lib.rs #4468
Comments
(My first guess would be that this bug is somewhat related to #2426 but I have not yet confirmed this...) |
Hm I think this may be an unfortunate interaction with assumptions about build scripts today. Right now Cargo assumes that the output of a build script is immutable in the sense that if the inputs haven't changed the output is guaranteed to have not changed either. I believe that means that in this case where You can perhaps fix this though with some |
But if that's the case, why does it rebuild some times and not others? (My money's still on time stamp oddities...) |
Yeah that's a good point. My guess though is the same, having to do basically with the resolution of the clock. |
(For those watching the dialogue...) @alexcrichton wrote:
Indeed, adding the line: println!("cargo:rerun-if-changed=\"src/lib.rs\""); to the (I still do not completely understand the underlying model here, but I just wanted to get that extra data point in there.) |
Having a similar problem using built crate https://docs.rs/built/0.3.0/built/ In my case adding
forced the build script to be run each build. When Alex said ( #4468 (comment))
That assumption is not correct in my case. We need a way for the build script to say that the build script should run whether or not its assumed inputs have changed - or a way to specify the inputs (in my case .git directory) |
@BruceChapmanNec the |
AFAICS,(please correct me if I am wrong) if there is a build.rs-script, but the script does not communicate This default behavior is disabled, if build.rs communicates at least a single I assume the erratic rebuild was caused by this default behavior, probably the timestamp of any other file did change. Also, in larger projects this default behavior will cause kind of monitoring-overhead. Please see the crate https://crates.io/crates/build-deps |
Same error on
|
Same problem here. My project Don't know if this is counted as a hack or not, but the problem is the same: Update: I managed to bypass this problem with macro-generated comments in rustdoc. Thanks @therealbnut! |
I came across this looking into another issue, in the cargo book it says:
If I'm understanding correctly that might be why you're having this issue. If you want to generate files you might need to put them into the |
As @alexcrichton has pointed out, we cannot try to modify anything out of However, starting from Rust 1.54, it's possible to declare a module as: // This won't work...
// #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
// mod generated;
// ... but this will.
mod generated {
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
} (For a complete example, see here.) ... which makes it possible to leverage Thus, I believe this issue has been resolved. |
I had this issue as well. My problem was that |
This is actually not possible. Per rust-lang/rust#83366 (comment):
|
@CobaltCause Thanks a lot for pointing it out! I've changed my (previously misleading) comment accordingly. |
Considering this is running counter to documented practices and there seem to be ways to make those documented practices work in these situations, I lean towards closing this issue. If there is a reason for us to keep it open, let us know! |
This came up in the context of tango, specifically the tango-demo project, which attempts to show off that one can have all checked-files under
src/
be markdown source rather than Rust source.The intention is that the build script will always regenerate the
src/lib.rs
if it is out of date or has been deleted.However, this sometimes does not happen. It is hard for me to tell exactly what the scenario is that is causing it to fail.
Here is a sample project that hopefully captures the essence of what I am trying to do:
Two files (only) at outset:
Cargo.toml:
build.rs:
Here is an example of a troubling interaction. Sometimes
cargo build
seems to know to run the build script, but other times it gives up as soon as it sees that thesrc/lib.rs
does not exist. And I do not see any hints as to why there is a difference in the--verbose
output.The text was updated successfully, but these errors were encountered: