5

Is there a way to set cargo to default add -j 4 to all the calls?

As workaround I've used this script:

cargoj4

#!/bin/bash
cargo "$1" -j 4

but this does not always work (I forget to call it :-\ or I have scripts in the project that use cargo and I cannot modify them).

2 Answers 2

9

You can create a config.toml to define parallel jobs. You need to create .cargo/config.toml. You can define it globally or per project, depending on your needs.

And then you just need to add

[build]
jobs = 4                      # number of parallel jobs, defaults to # of CPUs

You also have the possiblity of creating an alias for your command, which you would put in the same file:

[alias]
j4 = "build -j 4"

And then you can just invoke it as cargo j4

3

You can set this in cargo configuration file. You can create a config file in $HOME/.cargo/config.toml with the configuration you need.

[build]
jobs = 4 # number of parallel jobs, defaults to # of CPUs

Read more about Hierarchical structure, Configuration format and Jobs options here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.