-
Notifications
You must be signed in to change notification settings - Fork 81
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
Feature Suggestion: conditional run #75
Comments
Because we delegate almost entirely to watchexec, this would have to be possible there before it can be implemented here. But! This is actually possible with a bit of playing around and two cargo-watch instances. The idea is that one runs the server, and the other runs
and
|
I love this quick approach!! Didn’t come to my mind... |
I'll put a note of it on the Readme, but then close this because direct support is an upstream issue. |
Also: would you be ok if I posted this on the /r/rust subreddit? I think it's a useful pattern |
hey, @passcod; sure -- it's really your pattern 👍
Update: This works! |
Have you tried with |
Aha, that does the trick... Updated my response up there. I would have thought that the explicit |
It doesn't, because you can watch e.g. a folder within your source but still want to have the ignores apply. Also because it makes things simpler, both to code and to understand, when options only do one thing and don't switch the entire mode of the application without warning. It does make it a bit odd in this particular case, though. I'll think on that. |
@passcod Clever solution but how could it be done on Windows? Windows doesn't have And btw, if I have a workspace with a lib and a bin crate, where the bin depends on the lib, how can I use cargo watch to restart the bin when the lib changes? |
I'd say just use redirection to write to the file. And for the lib/bin, same solution, but given #52 is not implemented yet, you might have to use |
How can I target the binary subcrate with Even with a normal
|
Whatever command or commands you usually have to just run the binary subcrate, use those. |
It doesn't work:
Btw, it creates a file named How can I only watch Rust source files? Or exclude the |
It seems the generated command is not parsed correctly on Windows. Windows CMD is very... particular. So what it tries to run it That's a different issue not related to this thread, though. If you pass Also, these last questions are covered in the help, and |
cmd.exe only respects double quotes |
No. |
Why doesn't it run |
To prevent the lag when building stuff, I used (on an actix project): $ cargo watch -i .trigger -x build -s 'touch .trigger' &
$ systemfd --no-pid -s http::3000 -- cargo watch -w .trigger -x run |
Is there a reason not to just eliminate the double process and execute This seems to work for me. |
Your command is equivalent to
The problem in this ticket was that if |
Ah that makes sense, I just didn't happen to interact with my server while it was rebuilding. |
Great solution from @passcod here, but... Is there any plans to develop some native options to do this in a single-line command? |
As a matter of fact, yes! What shape this will take is still nebulous, but I hope to have it for the end of the year. The core capability (running more than one process within an instance) will land upstream next month, and then the 'frontend' work will take a bit more time. |
In my team we used this approach to tackle both the issue of stopping processes before the changes pass Imagine we have multiple binary and library crates as part of a workspace, as shown below in a minimal example: .
├── Cargo.toml
├── lib1
│ ├── Cargo.toml
│ └── src
│ └── lib.rs
├── service1
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── service2
│ ├── Cargo.toml
│ └── src
│ └── main.rs
└── shared_lib
├── Cargo.toml
└── src
└── lib.rs We run multiple workspace services at the same time, but we want to only recompile and restart a service when either its own code or the code of one of the workspace libraries it depends on changes and passes cargo check. To achieve this, we will need mprocs configuration for the simple workspace shown above looks like this: procs:
shared_lib-check:
cmd: [cargo, watch, -w, "shared_lib", -x, "check -p shared_lib", -s, "touch .trigger-shared_lib"]
lib1-check:
cmd: [cargo, watch, -w, "lib1", -x, "check -p lib1", -s, "touch .trigger-lib1"]
service1-check:
cmd: [cargo, watch, -w, "service1", -x, "check -p service1", -s, "touch .trigger-service1"]
service2-check:
cmd: [cargo, watch, -w, "service2", -x, "check -p service2", -s, "touch .trigger-service2"]
service1-run:
cmd: [cargo, watch,
-w, ".trigger-shared_lib",
-w, ".trigger-lib1",
-w, ".trigger-service1",
-x, "run -p service1"]
service2-run:
cmd: [cargo, watch,
-w, ".trigger-shared_lib",
-w, ".trigger-service2",
-x, "run -p service2"] This will start 4 PS: There is no need to use |
I really like the practice of keeping
cargo check
running continuously in the background thanks to this awesome tool. But recently I really wish the following would be possible: Do something likecargo watch -x check -x run
with a twist:check
without terminating the application (in my case a rocket application)check
succeeds, then terminate the application and do therun
...This would be really nice, as it would only restart the server if it's actually safe to do so. Hence I can keep hacking around and trying the current (running) version safely until the code compiles again. Maybe that's something that only seems useful to me, but I really believe this would be super-handy...
The text was updated successfully, but these errors were encountered: