How can I get the load to automatically recompile modified files?

I heard that the load has the ability to automatically recompile the modified source files, but it is difficult for me to understand how to do this.

Currently, I manually run cargo build or cargo run every time I want to enter a verification code. Instead, I would rather just save the file and see the results in an adjacent terminal window.

If you still don't know what I'm talking about, I'm looking for the cargo equivalent of sbt ~compile or sbt ~run .

It seems oddly hard to find, so I'm starting to wonder if this is really supported. Perhaps someone said that the load can detect modified files and recompile them when he wanted to say that the load can detect immutable files and not recompile them, for example make .

+6
source share
3 answers

If you are working on a server project (such as hardware) that continues to work, and you need to restart it when changing files, cargo watch doesn’t work with writing this .

In the meantime, you can install watchexec as follows:

 cargo install watchexec 

And then use it like this:

 watchexec --restart "cargo run" 
+4
source

It seems that no built-in support exists, but there is an extension ( cargo-watch ) for detecting changes using inotify .

When I found it, it will not work with stable (or current) rust, but since then I fixed it. It may still use some work, but it certainly speeds up the compilation / bug fix cycle.

+3
source

I believe that the difference is that running cargo run twice will not generate code twice, unless the input files have changed. As far as I know, Cargo does not have the functionality you want to embed. You can submit a function request. In the meantime, I suggest you just use watch . You can also use something like guard . Using watch simpler, but will run your code every N seconds. guard will require more settings, but will be slightly more efficient.

+2
source

Source: https://habr.com/ru/post/984713/


All Articles