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

Support for workspaces #52

Open
malbarbo opened this issue Jan 30, 2017 · 11 comments
Open

Support for workspaces #52

malbarbo opened this issue Jan 30, 2017 · 11 comments

Comments

@malbarbo
Copy link

malbarbo commented Jan 30, 2017

Consider adding support to use cargo watch in a workspace project.

You can see with cargo +nightly build --help the kind of options for workspace projects.

@passcod
Copy link
Member

passcod commented Jan 30, 2017

Can you explain what we'd need to watch for / execute in this context? At least for quick reference.

@malbarbo
Copy link
Author

malbarbo commented Feb 3, 2017

I think there are two strategies:

  1. Watch rust files in every workspace member, when a file changes execute cargo passing the changed member to --package (-p). For example
cargo watch 'test' # execute 'cargo test -p mypackage' if a file changes in mypackage project
  1. Require that the user specify the members to watch using --package (-p) or -all (similar to cargo build, test, etc), and forward the packages to cargo. For example
cargo watch -p mypackage 'bench' # watch mypackage files and execute `cargo bench -p mypackage`

@passcod
Copy link
Member

passcod commented Feb 7, 2017

Could probably do both, too. I'm not going to pick this up for the moment, but would merge a PR that implements it.

@malbarbo malbarbo changed the title Support for worspaces Support for workspaces Feb 7, 2017
@colin-kiegel
Copy link

colin-kiegel commented Mar 4, 2017

I think there are two aspects to workspace support:
(a) the set of crates being monitored
(b) the set of crates being tested / benched / etc.

What @malbarbo suggested are these two modes:

  1. (a) monitor the full set of crates, but (b) only test the single crate that changed
  2. (a) monitor a fixed set of crates, and (b) test exactly that same set of crates

Strategy (1) would be a good default since workspaces can be big.

On the other hand it is possible that changes have side effects on other crates within the same workspace. So it's definitely interesting to have a way to pass --all and monitor + test the full set of crates. This could be achieved with strategy (2).

.. however

I suggest to adopt this alternative strategy:

cargo watch could always watch the entire workspace. If the user passes a package flag (--package, -p or --all) it would still watch the entire workspace, but only test for side effects in the specified packages.

The difference is this:
Say we call cargo watch -p foo 'test' and then a crate bar is changed within the same workspace. Within this alternative suggestion foo would be recompiled/tested nevertheless, because it can be affected by that change. In @malbarbo s original suggestion the change to bar would be ignored.

@passcod
Copy link
Member

passcod commented Mar 29, 2017

With version 4.0.0, you can now run arbitrary commands and watch a lot more stuff by default. While that's not first-class support for workspaces yet, it's a step towards that. In addition, the -p, --all, and --package CLI flags/options are reserved (but hidden from help messages) for this usage.

@waynr
Copy link
Contributor

waynr commented Oct 24, 2019

I'd like to take a crack at implementing this if no one else is already working on it. @passcod got any suggestions for where to start?

@passcod
Copy link
Member

passcod commented Oct 24, 2019

Absolutely, thanks for offering!

I actually don't have any idea of what this would do! So I guess first step would be figuring out what the action would be. There's a bunch of stuff in the comments but I haven't really thought about this in, uh, two years.

I don't think this needs watchexec support, which simplifies things. There will need to be a flag added to the clap arguments, then whatever logic happens to translate/affect the arguments for watchexec. And that should be all!

@tzemanovic
Copy link

Personally, I find that the current version works well with a workspace project, where you can choose what package/action to run with the --exec argument.

I would however love to see support for [workspace] config when it's specified in Cargo.toml. That is to filter out packages from the exclude key list, similarly as is done for .gitignore.

@Nonius
Copy link

Nonius commented Jun 6, 2021

cargo watch in a workspace root changes the Cargo.lock file, which will trigger an infinite loop. Is this part of this issue?

@passcod
Copy link
Member

passcod commented Jun 6, 2021

I'd prefer that filed as a different issue (possible bug, not part of whatever feature this issue materialises as)

@Nonius
Copy link

Nonius commented Jun 6, 2021

I'd prefer that filed as a different issue (possible bug, not part of whatever feature this issue materialises as)

I've created #175

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

No branches or pull requests

6 participants