deb: add -j/--jobs to control parallel build jobs

By default the number of parallel jobs is detected with nproc inside
the build context. Add a -j/--jobs option so an explicit count can be
honored instead, threading it through build_binary_package and
local::build into DEB_BUILD_OPTIONS=parallel=N.
This commit is contained in:
2026-09-10 15:27:50 +02:00
parent 348abf61b9
commit 182a06ffbe
3 changed files with 35 additions and 15 deletions
+8 -3
View File
@@ -37,6 +37,7 @@ pub async fn build(
inject_packages: Option<&[&str]>,
ctx: Arc<Context>,
ui: Option<Arc<DebUi>>,
jobs: Option<usize>,
) -> Result<(), Box<dyn Error>> {
let sink: Option<Arc<dyn LineSink>> = ui.as_ref().map(|u| u.sink());
@@ -45,8 +46,11 @@ pub async fn build(
env.insert("LANG".to_string(), "C".to_string());
env.insert("DEBIAN_FRONTEND".to_string(), "noninteractive".to_string());
// Parallel building: find local number of cores, and use that
let num_cores = ctx
// Parallel building: honor an explicit -j/--jobs count, otherwise detect
// the number of cores available inside the build context (nproc).
let num_cores = match jobs {
Some(j) => j,
None => ctx
.command("nproc")
.output()
.map(|output| {
@@ -59,7 +63,8 @@ pub async fn build(
1 // Default to 1 if nproc fails
}
})
.unwrap_or(1); // Default to 1 if we can't execute the command
.unwrap_or(1), // Default to 1 if we can't execute the command
};
// Build options: parallel, disable tests by default
env.insert(
+5
View File
@@ -33,6 +33,7 @@ pub async fn build_binary_package(
inject_packages: Option<&[&str]>,
ctx: Option<Arc<Context>>,
ui: Option<Arc<DebUi>>,
jobs: Option<usize>,
) -> Result<Vec<PathBuf>, Box<dyn Error>> {
let result = build_binary_package_impl(
arch,
@@ -45,6 +46,7 @@ pub async fn build_binary_package(
inject_packages,
ctx,
&ui,
jobs,
)
.await;
@@ -68,6 +70,7 @@ async fn build_binary_package_impl(
inject_packages: Option<&[&str]>,
ctx: Option<Arc<Context>>,
ui: &Option<Arc<DebUi>>,
jobs: Option<usize>,
) -> Result<Vec<PathBuf>, Box<dyn Error>> {
let cwd = cwd.unwrap_or_else(|| Path::new("."));
@@ -160,6 +163,7 @@ async fn build_binary_package_impl(
inject_packages,
build_ctx.clone(),
ui.clone(),
jobs,
)
.await?
}
@@ -414,6 +418,7 @@ mod tests {
None,
Some(ctx),
None,
None,
)
.await
.expect("Cannot build binary package (deb)");
+10
View File
@@ -78,6 +78,7 @@ fn main() {
.long_help("Cross-compile for target architecture (instead of using qemu-binfmt)\nNote that most packages cannot be cross-compiled").required(false))
.arg(arg!(--mode <mode> "Change build mode [local]").required(false)
.long_help("Change build mode [local]\nDefault will chose depending on other parameters, don't provide if unsure"))
.arg(arg!(-j --jobs <jobs> "Number of parallel build jobs (default: number of CPUs available in the build context)").required(false))
.arg(arg!(--verbose "Show raw tool output instead of the live build view").required(false)
.long_help("Show raw tool output instead of the live build view.\nAlso implied by RUST_LOG=debug for pkh's own logs.")),
)
@@ -313,6 +314,14 @@ fn main() {
.copied()
.unwrap_or(false);
let jobs = sub_matches.get_one::<String>("jobs").map(|s| s.as_str());
let jobs = jobs.map(|j| {
j.parse::<usize>().unwrap_or_else(|_| {
error!("Invalid --jobs value '{}': expected a positive integer", j);
std::process::exit(1);
})
});
// Live build view: disabled by --verbose or when stdout is not a
// terminal (DebUi handles the non-TTY case itself)
let ui = if verbose {
@@ -333,6 +342,7 @@ fn main() {
inject_packages,
None,
ui.clone(),
jobs,
)
.await
});