From abbe8ecd247fa9894eded683b6e742a0df53be90 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 7 May 2022 14:32:38 +0200 Subject: [PATCH] hook max-threads up for `roc check` --- cli/src/build.rs | 3 ++- cli/src/lib.rs | 3 ++- cli/src/main.rs | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cli/src/build.rs b/cli/src/build.rs index 0f5241e4c3..72f9a53c05 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -350,6 +350,7 @@ pub fn check_file( src_dir: PathBuf, roc_file_path: PathBuf, emit_timings: bool, + threading: Threading, ) -> Result<(program::Problems, Duration), LoadingProblem> { let compilation_start = SystemTime::now(); @@ -368,7 +369,7 @@ pub fn check_file( target_info, // TODO: expose this from CLI? RenderTarget::ColorTerminal, - Threading::AllAvailable, + threading, )?; let buf = &mut String::with_capacity(1024); diff --git a/cli/src/lib.rs b/cli/src/lib.rs index d260866e17..79a4828e5e 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -62,8 +62,8 @@ pub fn build_app<'a>() -> Command<'a> { let flag_max_threads = Arg::new(FLAG_MAX_THREADS) .long(FLAG_MAX_THREADS) .help("Limit the number of threads (and hence cores) used during compilation.") - .takes_value(true) .requires(ROC_FILE) + .takes_value(true) .validator(|s| s.parse::()) .required(false); @@ -185,6 +185,7 @@ pub fn build_app<'a>() -> Command<'a> { .subcommand(Command::new(CMD_CHECK) .about("Check the code for problems, but doesn’t build or run it") .arg(flag_time.clone()) + .arg(flag_max_threads.clone()) .arg( Arg::new(ROC_FILE) .help("The .roc file of an app to check") diff --git a/cli/src/main.rs b/cli/src/main.rs index 0a21c66ed5..41f7868c9f 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,7 +6,7 @@ use roc_cli::{ FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME, ROC_FILE, }; use roc_error_macros::user_error; -use roc_load::LoadingProblem; +use roc_load::{LoadingProblem, Threading}; use std::fs::{self, FileType}; use std::io; use std::path::{Path, PathBuf}; @@ -94,7 +94,17 @@ fn main() -> io::Result<()> { let roc_file_path = PathBuf::from(filename); let src_dir = roc_file_path.parent().unwrap().to_owned(); - match check_file(&arena, src_dir, roc_file_path, emit_timings) { + let threading = match matches + .value_of(roc_cli::FLAG_MAX_THREADS) + .and_then(|s| s.parse::().ok()) + { + None => Threading::AllAvailable, + Some(0) => user_error!("cannot build with at most 0 threads"), + Some(1) => Threading::Single, + Some(n) => Threading::AtMost(n), + }; + + match check_file(&arena, src_dir, roc_file_path, emit_timings, threading) { Ok((problems, total_time)) => { println!( "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.",