From 04592b3e4fb3deb0253c8ab708c9465c13694ea8 Mon Sep 17 00:00:00 2001 From: Boshen Date: Mon, 10 Apr 2023 22:13:41 +0800 Subject: [PATCH] feat(cli): add --threads 1 option for rayon to use only 1 threads --- crates/oxc_cli/src/lib.rs | 8 +++++++- crates/oxc_cli/src/main.rs | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/oxc_cli/src/lib.rs b/crates/oxc_cli/src/lib.rs index 7a7e5412f..b704f0889 100644 --- a/crates/oxc_cli/src/lib.rs +++ b/crates/oxc_cli/src/lib.rs @@ -3,7 +3,7 @@ mod lint; mod result; mod walk; -use clap::Command; +use clap::{Arg, Command}; use crate::lint::lint_command; pub use crate::{ @@ -22,4 +22,10 @@ pub fn command() -> Command { .subcommand_required(true) .arg_required_else_help(true) .subcommand(lint_command()) + .arg( + Arg::new("threads") + .long("threads") + .value_parser(clap::value_parser!(usize)) + .help("Number of threads to use. Set to 1 for using only 1 CPU core."), + ) } diff --git a/crates/oxc_cli/src/main.rs b/crates/oxc_cli/src/main.rs index bdfd9bacc..35e37e19c 100644 --- a/crates/oxc_cli/src/main.rs +++ b/crates/oxc_cli/src/main.rs @@ -12,6 +12,11 @@ use oxc_cli::{command, CliRunResult, LintOptions, LintRunner}; fn main() -> CliRunResult { let matches = command().get_matches(); + + if let Some(threads) = matches.get_one::("threads") { + rayon::ThreadPoolBuilder::new().num_threads(*threads).build_global().unwrap(); + } + let Some((subcommand, matches)) = matches.subcommand() else { return CliRunResult::None };