sagiegurari / cargo-make

Rust task runner and build tool.
https://sagiegurari.github.io/cargo-make/
Apache License 2.0
2.47k stars 123 forks source link

Run dependencies in parallel #483

Open sffc opened 3 years ago

sffc commented 3 years ago

Feature Description

If my task has multiple dependencies, and those dependencies are independent from one another, cargo make should be able to run them in parallel.

Describe The Solution You'd Like

If I write the following, I expect each of the subtasks to be run in parallel, or at least be allowed to be run in parallel if I pass a -j option to cargo make.

[tasks.wasm]
dependencies = [
    "wasm-wasm",
    "wasm-wat",
    "wasm-opt",
    "wasm-twiggy-dominators",
]

I can use parallel = true in run_task, like this:

[[tasks.wasm.run_task]]
name = [
    "wasm-wasm",
    "wasm-wat",
    "wasm-opt",
    "wasm-twiggy-dominators",
]
parallel = true

However, this causes duplicate work. Each of the subtasks depends on a task that runs "cargo build", so "cargo build" gets executed four times.

sagiegurari commented 3 years ago

@sffc there is a workaround for the issue you stated, but i agree that this is a limitation and a complex one to resolve. it would also break things like task specific env vars i have, but i guess thats not an issue. I'll see if i can get to it at some point, but probably not in the near future due to the complexity and my limited free time.

cortopy commented 3 years ago

I'm trying to have several microservices in a workspace running at the same time with a cargo run for each.

I've tried the following:

[tasks.dev-service1]
env = { CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["service1"] }
run_task = { name = "dev-service1", fork = true }

[tasks.dev-service2]
env = { CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["service2"] }
run_task = { name = "dev-service2", fork = true }

[tasks.watch-flow]
workspace = false
clear = true
run_task = { name = [
    "dev-service1",
    "dev-service2"
], parallel = true }

But this causes each task to run twice for each service. All servers crash because the address and port has already been taken by the previous run in each

@sagiegurari what is the workaround you've mentioned?

sagiegurari commented 3 years ago

you should not run dev-service1, instead you should run a flow of 2 tasks

  1. kill previous run
  2. start a new run via cargo run its not that related to cargo-make, more like how you would logically define the action you want to take when a code change happens. so in this case -> kill old && start new
cortopy commented 3 years ago

But I thought the watch option already killed previous task https://github.com/sagiegurari/cargo-make#watch? I'm a bit confused

sagiegurari commented 3 years ago

no. i don't think i wrote such a comment in the documentation either. the watch flag on a task is very simple. something changes -> task is called. a simple example would be, you change a file -> cargo build is called. for server like processes, i think you need to model it based on that.