-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
If you want your machine to remain usable during a compile session usually you want to set the number of jobs
lower than your maximum number of cores. But this varies heavily from machine to machine, and makes it
annoying to automate in bigger build scripts.
I would suggest extending the --jobs
(or -j
) parameter to negative numbers, where -j -1
would be 'all but one core',
-j -2
would be 'all but two cores', etc. This makes it really easy for scripts to maintain a usable machine and scale
to the number of cores available without having to look up the actual number of cores.
For sanity and convenience of automatic build scripts I would suggest that if -j
was sufficiently negative to specify no or a negative amount of cores, to clamp the number of cores to at least 1, instead of giving an error.
So to be precise I would suggest changing jobs
to i32
instead of u32
in BuildConfig::new
(and wherever necessary to make that work) and replace this line with
let jobs = match jobs.or(cfg.jobs) {
None => ::num_cpus::get() as u32,
Some(j) if j < 0 => (::num_cpus::get() as i32 + j).max(1) as u32,
Some(j) => j as u32,
};
I'm neutral on whether 0
should still not be allowed or whether that should be mapped to ::num_cpus::get()
.