-
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
Need a way to ask cargo if the current package needs to be recompiled. #1989
Comments
I'd totally be down for something like this in terms of a library API, and this would also be a great inclusion as part of a field in some sort of "local package metadata" command. In terms of implementation most of this stuff is tracked in fingerprint.rs but it's definitely not in an "easily usable" state right now in terms of a consumer being able to leverage it. I'd be more than welcome to patches to tweak the API though! |
I would really like a command like this, some kind of |
Of course! :)
Additional pairs of eyes digging around that code and thinking about how to restructure it so that checking modifications are decoupled from performing the action would be welcome. |
If you're just trying to answer the question "why is this rebuilding", could you try out the new support landed in c447e9d? (only available in nightlies). You can test it out via |
Definitely not irrelevant, in one of my projects I'm using |
Yeah, thats an issue. It would probably help if rustc could track what source files it depends on outside of just the rust modules, and emit that info as part of the dep-info output. |
We've discussed wanting something similar for invoking Cargo as part of the Gecko build system. My proposal was for Cargo to accept an argument specifying a GNU Make-style dependency file, similar to how rustc accepts |
@luser just to confirm, but is this a hard constraint for using Cargo in Gecko for now? The approximation of "if any Rust code changes rerun Cargo" is probably what this would amount to for Gecko so it may not buy much in the long term, but it's certainly something we can try to implement soon if needed. (it may also be worth just always invoking Cargo if that's easy as it should be fast) Note that Cargo definitely has all this info on hand, so it won't be too difficult to implement. |
Oh, no, we had chatted about this not long ago and agreed that Gecko can probably live with "always rerun cargo" for now. I was just looking at the issues list to try to avoid filing a dupe and ran into this. |
#2904 covers the
This is the part I don't quite understand. If you had a precise set of paths to watch (that is updated after every successful build), what difference is there between running |
I'm currently trying to write an exact file system watcher for a cargo project, so that any change that would cause a
cargo build
to actually end up recompiling the library can be detected. However, I'm stuck at figuring out just what file path changes to watch and react to:src
, then I'll get false positives by temporary files or source files not part of the crate.*.rs
files insrc
, I'll get false positves by source files not part of the crate, or false negatives for source files that don't have a*.rs
ending (the latter might be irrelevant in practice, but is still technical possible).src
, I miss changed or not yet downloaded dependenciessrc
, I miss changedrustc
orcargo
executables (say a new nightly).So I need a way to ask cargo what paths to listen to, including:
rustc
andcargo
executablesFurthermore I need a high-performance way to actually ask cargo wether a change in any of those paths will cause a recompile. I could just shell out to
cargo build
each time any change is detected, but thats going to be wasteful if its just temporary files of an text editor or harmless other changes that won't trigger a recompilation.If using cargo as a library already supports any of those usecases in a robust way, I've not been able to find it yet.
If its not currently possible to do these things with cargo I'd be willing to add the necessary library features, though I'd need guidance about how cargo is currently structured internally 😄 .
I have limited information about how this could be best implemented, but right now I'm thinking about an API like this:
Using that API, a filesystem watcher could crawl the contents of a package once with
FsWatchList::new()
, setup a filesystem notifcator for all relevant paths, and then callmerge_changes()
andneeds_rebuild()
each time it receives an event, triggering an rebuild only if needed.Ideally there would also be a
trigger_rebuild()
method that does the same ascargo build
without shelling out at all, but thats a different issue.The text was updated successfully, but these errors were encountered: