Skip to content
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

Output cargo:rerun-if-changed #41

Closed
segevfiner opened this issue Feb 10, 2022 · 6 comments
Closed

Output cargo:rerun-if-changed #41

segevfiner opened this issue Feb 10, 2022 · 6 comments
Labels

Comments

@segevfiner
Copy link

In order for cargo to correctly rebuild when the manifest or resources change, you need to output cargo:rerun-if-changed. This needs to be output for both the resource script and the resources it embeds. Getting the list of resources might be a bit more tricky as it requires cooperation from the resource compiler similar to how you can request Makefile dependencies from gcc or parse cl output for includes.

@nabijaczleweli
Copy link
Owner

nabijaczleweli commented Feb 10, 2022

Well, getting the dependencies is impossible, but cargo rebuilds if I change the .rc, too, despite the lack of rerun-if-changed, which I didn't expect and is a good point, so hm.

@segevfiner
Copy link
Author

segevfiner commented Feb 10, 2022

"Hmm" indeed. Perhaps it implicitly adds a dependency from some other emitted property.

@LPGhatguy
Copy link

LPGhatguy commented Dec 9, 2022

If a build script doesn't not output ANY rerun-if-changed directives, the build script will be rerun if any file in the project changes. That is to say, using embed-resource without any other build script functionality will work, but it will stop functioning if new code is added that uses this feature.

Importantly, emitting no rerun-if-changed directives will cause Cargo to scan the entire project file for changes. In my project, that made Cargo access several gigabytes of asset files needed at runtime but unrelated to the build. This was bad for our build times.

I worked around this by manually emitting our own rerun-if-changed lines:

println!("cargo:rerun-if-changed=build/windows/manifest.rc");
println!("cargo:rerun-if-changed=build/windows/cyrtanthus.manifest");
embed_resource::compile("build/windows/manifest.rc");

@nabijaczleweli
Copy link
Owner

That explains it, but unfortunately there's still the issue that the default behaviour is better in the general case than speccing just the .rc, since that starts with an unspecified pre-processing step with no possibility to spec an equivalent of cc -MD – it either runs over-zealously or not enough, and the latter is much worse. Unless you have a suggestion for extracting that dependency data, then the best I can do is put it in an erratum in the top-level doc, I think?

@LPGhatguy
Copy link

Unless you have a suggestion for extracting that dependency data, then the best I can do is put it in an erratum in the top-level doc, I think?

Yeah, sounds like the best bet. Having the user write things out isn't too bad and documenting this is a good idea.

@nabijaczleweli
Copy link
Owner

Erratum added for v1.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants