From 48eb64403f6c6cb567e3595e0a911ceb582e0f9d Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 13 Oct 2023 14:57:09 +0800 Subject: [PATCH] standalone: Treat -T0 as using all available threads --- nac3standalone/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index a88be7e35..5ba1436df 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -38,7 +38,8 @@ struct CommandLineArgs { /// The name of the input file. file_name: String, - /// The number of threads allocated to processing the source file. + /// The number of threads allocated to processing the source file. If 0 is passed to this + /// parameter, all available threads will be used for compilation. #[arg(short = 'T', default_value_t = 1)] threads: u32, @@ -207,6 +208,13 @@ fn main() { .map(|arg| if arg == "native" { host_target_machine.cpu.clone() } else { arg }) .unwrap_or_default(); let target_features = target_features.unwrap_or_default(); + let threads = if threads == 0 { + std::thread::available_parallelism() + .map(|threads| threads.get() as u32) + .unwrap_or(1u32) + } else { + threads + }; let opt_level = match opt_level { 0 => OptimizationLevel::None, 1 => OptimizationLevel::Less,