From e7ac4dac96c64a5d4a5a6be4acc21aee764b1643 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 23:01:07 -0400 Subject: [PATCH 01/15] Test `roc run` and `roc` in addition to `roc build` Also, use constants instead of hardcoded strings. --- Cargo.lock | 27 +++++ cli/Cargo.toml | 2 + cli/tests/cli_run.rs | 201 ++++++++++++++++++++--------------- cli_utils/src/bench_utils.rs | 12 +-- cli_utils/src/helpers.rs | 17 +-- 5 files changed, 163 insertions(+), 96 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b4691a883..cb430e62a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1759,6 +1759,12 @@ dependencies = [ "ahash 0.7.6", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -3530,6 +3536,8 @@ dependencies = [ "roc_target", "roc_test_utils", "serial_test", + "strum", + "strum_macros", "target-lexicon", "tempfile", "wasmer", @@ -4616,6 +4624,25 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e96acfc1b70604b8b2f1ffa4c57e59176c7dbb05d556c71ecd2f5498a1dee7f8" + +[[package]] +name = "strum_macros" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "syn" version = "1.0.81" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4e019df2c6..976a9d19bc 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -85,6 +85,8 @@ indoc = "1.0.3" serial_test = "0.5.1" criterion = { git = "https://github.com/Anton-4/criterion.rs"} cli_utils = { path = "../cli_utils" } +strum = "0.24.0" +strum_macros = "0.24" # Wasmer singlepass compiler only works on x86_64. [target.'cfg(target_arch = "x86_64")'.dev-dependencies] diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index fae6dd7083..7c979585c5 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -14,10 +14,29 @@ mod cli_run { known_bad_file, run_cmd, run_roc, run_with_valgrind, Out, ValgrindError, ValgrindErrorXWhat, }; + use const_format::concatcp; use indoc::indoc; + use roc_cli::{CMD_BUILD, CMD_RUN}; use roc_test_utils::assert_multiline_str_eq; use serial_test::serial; + use std::iter; use std::path::{Path, PathBuf}; + use strum::IntoEnumIterator; + use strum_macros::EnumIter; + + const OPTIMIZE_FLAG: &str = concatcp!("--", roc_cli::FLAG_OPTIMIZE); + const VALGRIND_FLAG: &str = concatcp!("--", roc_cli::FLAG_VALGRIND); + const LINKER_FLAG: &str = concatcp!("--", roc_cli::FLAG_LINKER); + const CHECK_FLAG: &str = concatcp!("--", roc_cli::FLAG_CHECK); + #[allow(dead_code)] + const TARGET_FLAG: &str = concatcp!("--", roc_cli::FLAG_TARGET); + + #[derive(Debug, EnumIter)] + enum CliMode { + RocBuild, + RocRun, + Roc, + } #[cfg(not(debug_assertions))] use roc_collections::all::MutMap; @@ -65,7 +84,7 @@ mod cli_run { } fn check_compile_error(file: &Path, flags: &[&str], expected: &str) { - let compile_out = run_roc(&[&["check", file.to_str().unwrap()], flags].concat()); + let compile_out = run_roc(["check", file.to_str().unwrap()].iter().chain(flags)); let err = compile_out.stdout.trim(); let err = strip_colors(err); @@ -77,8 +96,7 @@ mod cli_run { } fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) { - let flags = &["--check"]; - let out = run_roc(&[&["format", file.to_str().unwrap()], &flags[..]].concat()); + let out = run_roc(["format", file.to_str().unwrap(), CHECK_FLAG]); if expects_success_exit_code { assert!(out.status.success()); } else { @@ -86,8 +104,8 @@ mod cli_run { } } - fn build_example(file: &Path, flags: &[&str]) -> Out { - let compile_out = run_roc(&[&["build", file.to_str().unwrap()], flags].concat()); + fn run_roc_on<'a, I: IntoIterator>(file: &'a Path, args: I) -> Out { + let compile_out = run_roc(args.into_iter().chain(iter::once(file.to_str().unwrap()))); if !compile_out.stderr.is_empty() { panic!("roc build had stderr: {}", compile_out.stderr); } @@ -106,86 +124,99 @@ mod cli_run { expected_ending: &str, use_valgrind: bool, ) { - let mut all_flags = vec![]; - all_flags.extend_from_slice(flags); + for cli_mode in CliMode::iter() { + let flags = { + let mut vec = flags.to_vec(); - if use_valgrind { - all_flags.extend_from_slice(&["--valgrind"]); - } + if use_valgrind { + vec.push(VALGRIND_FLAG); + } - build_example(file, &all_flags[..]); - - let out = if use_valgrind && ALLOW_VALGRIND { - let (valgrind_out, raw_xml) = if let Some(input_file) = input_file { - run_with_valgrind( - stdin, - &[ - file.with_file_name(executable_filename).to_str().unwrap(), - input_file.to_str().unwrap(), - ], - ) - } else { - run_with_valgrind( - stdin, - &[file.with_file_name(executable_filename).to_str().unwrap()], - ) + vec.into_iter() }; - if valgrind_out.status.success() { - let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { + let out = match cli_mode { + CliMode::RocBuild => { + run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone())); + + if use_valgrind && ALLOW_VALGRIND { + let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { + run_with_valgrind( + stdin.clone().iter().copied(), + &[ + file.with_file_name(executable_filename).to_str().unwrap(), + input_file.to_str().unwrap(), + ], + ) + } else { + run_with_valgrind( + stdin.clone().iter().copied(), + &[file.with_file_name(executable_filename).to_str().unwrap()], + ) + }; + + if valgrind_out.status.success() { + let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nvalgrind xml was: \"{}\"\n\nvalgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", err, raw_xml, valgrind_out.stdout, valgrind_out.stderr); }); - if !memory_errors.is_empty() { - for error in memory_errors { - let ValgrindError { - kind, - what: _, - xwhat, - } = error; - println!("Valgrind Error: {}\n", kind); + if !memory_errors.is_empty() { + for error in memory_errors { + let ValgrindError { + kind, + what: _, + xwhat, + } = error; + println!("Valgrind Error: {}\n", kind); - if let Some(ValgrindErrorXWhat { - text, - leakedbytes: _, - leakedblocks: _, - }) = xwhat - { - println!(" {}", text); + if let Some(ValgrindErrorXWhat { + text, + leakedbytes: _, + leakedblocks: _, + }) = xwhat + { + println!(" {}", text); + } + } + panic!("Valgrind reported memory errors"); + } + } else { + let exit_code = match valgrind_out.status.code() { + Some(code) => format!("exit code {}", code), + None => "no exit code".to_string(), + }; + + panic!("`valgrind` exited with {}. valgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", exit_code, valgrind_out.stdout, valgrind_out.stderr); } - } - panic!("Valgrind reported memory errors"); - } - } else { - let exit_code = match valgrind_out.status.code() { - Some(code) => format!("exit code {}", code), - None => "no exit code".to_string(), - }; - panic!("`valgrind` exited with {}. valgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", exit_code, valgrind_out.stdout, valgrind_out.stderr); + valgrind_out + } else if let Some(ref input_file) = input_file { + run_cmd( + file.with_file_name(executable_filename).to_str().unwrap(), + stdin.iter().copied(), + &[input_file.to_str().unwrap()], + ) + } else { + run_cmd( + file.with_file_name(executable_filename).to_str().unwrap(), + stdin.iter().copied(), + &[], + ) + } + } + CliMode::Roc => run_roc_on(file, flags.clone()), + CliMode::RocRun => run_roc_on(file, iter::once(CMD_RUN).chain(flags.clone())), + }; + + if !&out.stdout.ends_with(expected_ending) { + panic!( + "expected output to end with {:?} but instead got {:#?} - stderr was: {:#?}", + expected_ending, out.stdout, out.stderr + ); } - valgrind_out - } else if let Some(input_file) = input_file { - run_cmd( - file.with_file_name(executable_filename).to_str().unwrap(), - stdin, - &[input_file.to_str().unwrap()], - ) - } else { - run_cmd( - file.with_file_name(executable_filename).to_str().unwrap(), - stdin, - &[], - ) - }; - if !&out.stdout.ends_with(expected_ending) { - panic!( - "expected output to end with {:?} but instead got {:#?} - stderr was: {:#?}", - expected_ending, out.stdout, out.stderr - ); + assert!(out.status.success()); } - assert!(out.status.success()); } #[cfg(feature = "wasm32-cli-run")] @@ -199,9 +230,13 @@ mod cli_run { ) { assert_eq!(input_file, None, "Wasm does not support input files"); let mut flags = flags.to_vec(); - flags.push("--target=wasm32"); + flags.push(concatcp!(TARGET_FLAG, "=wasm32")); - let compile_out = run_roc(&[&["build", file.to_str().unwrap()], flags.as_slice()].concat()); + let compile_out = run_roc( + [CMD_BUILD, file.to_str().unwrap()] + .iter() + .chain(flags.as_slice()), + ); if !compile_out.stderr.is_empty() { panic!("{}", compile_out.stderr); } @@ -258,7 +293,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - build_example(&file_name, &["--optimize"]); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG]); return; } @@ -283,7 +318,7 @@ mod cli_run { &file_name, example.stdin, example.executable_filename, - &["--optimize"], + [OPTIMIZE_FLAG], example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, @@ -296,7 +331,7 @@ mod cli_run { &file_name, example.stdin, example.executable_filename, - &["--linker", "legacy"], + &[LINKER_FLAG, "legacy"], example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, @@ -513,7 +548,7 @@ mod cli_run { &file_name, benchmark.stdin, benchmark.executable_filename, - &["--optimize"], + &[OPTIMIZE_FLAG], benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, benchmark.use_valgrind, @@ -555,7 +590,7 @@ mod cli_run { &file_name, benchmark.stdin, benchmark.executable_filename, - &["--optimize"], + [OPTIMIZE_FLAG], benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, ); @@ -587,7 +622,7 @@ mod cli_run { &file_name, benchmark.stdin, benchmark.executable_filename, - &["--target=x86_32"], + [concatcp!(TARGET_FLAG, "=x86_32")], benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, benchmark.use_valgrind, @@ -597,7 +632,7 @@ mod cli_run { &file_name, benchmark.stdin, benchmark.executable_filename, - &["--target=x86_32", "--optimize"], + [concatcp!(TARGET_FLAG, "=x86_32"), OPTIMIZE_FLAG], benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, benchmark.use_valgrind, @@ -816,7 +851,7 @@ mod cli_run { &fixture_file("multi-dep-str", "Main.roc"), &[], "multi-dep-str", - &["--optimize"], + &[OPTIMIZE_FLAG], None, "I am Dep2.str2\n", true, @@ -844,7 +879,7 @@ mod cli_run { &fixture_file("multi-dep-thunk", "Main.roc"), &[], "multi-dep-thunk", - &["--optimize"], + &[OPTIMIZE_FLAG], None, "I am Dep2.value2\n", true, diff --git a/cli_utils/src/bench_utils.rs b/cli_utils/src/bench_utils.rs index d14de367bd..a7797f010a 100644 --- a/cli_utils/src/bench_utils.rs +++ b/cli_utils/src/bench_utils.rs @@ -11,9 +11,7 @@ fn exec_bench_w_input( expected_ending: &str, bench_group_opt: Option<&mut BenchmarkGroup>, ) { - let flags: &[&str] = &["--optimize"]; - - let compile_out = run_roc(&[&["build", file.to_str().unwrap()], flags].concat()); + let compile_out = run_roc(["build", "--optimize", file.to_str().unwrap()]); if !compile_out.stderr.is_empty() { panic!("{}", compile_out.stderr); @@ -45,12 +43,12 @@ fn check_cmd_output( let out = if cmd_str.contains("cfold") { let child = thread::Builder::new() .stack_size(CFOLD_STACK_SIZE) - .spawn(move || run_cmd(&cmd_str, &[stdin_str], &[])) + .spawn(move || run_cmd(&cmd_str, [stdin_str], &[])) .unwrap(); child.join().unwrap() } else { - run_cmd(&cmd_str, &[stdin_str], &[]) + run_cmd(&cmd_str, [stdin_str], &[]) }; if !&out.stdout.ends_with(expected_ending) { @@ -93,12 +91,12 @@ fn bench_cmd( if let Some(bench_group) = bench_group_opt { bench_group.bench_function(&format!("Benchmarking {:?}", executable_filename), |b| { - b.iter(|| run_cmd(black_box(&cmd_str), black_box(&[stdin_str]), &[])) + b.iter(|| run_cmd(black_box(&cmd_str), black_box([stdin_str]), &[])) }); } else { run_cmd( black_box(file.with_file_name(executable_filename).to_str().unwrap()), - black_box(&[stdin_str]), + black_box([stdin_str]), &[], ); } diff --git a/cli_utils/src/helpers.rs b/cli_utils/src/helpers.rs index e83556176e..0bebe620ba 100644 --- a/cli_utils/src/helpers.rs +++ b/cli_utils/src/helpers.rs @@ -7,6 +7,7 @@ extern crate tempfile; use serde::Deserialize; use serde_xml_rs::from_str; use std::env; +use std::ffi::OsStr; use std::io::Read; use std::io::Write; use std::path::PathBuf; @@ -44,8 +45,7 @@ pub fn path_to_roc_binary() -> PathBuf { path } -#[allow(dead_code)] -pub fn run_roc(args: &[&str]) -> Out { +pub fn run_roc, S: AsRef>(args: I) -> Out { let mut cmd = Command::new(path_to_roc_binary()); for arg in args { @@ -63,8 +63,11 @@ pub fn run_roc(args: &[&str]) -> Out { } } -#[allow(dead_code)] -pub fn run_cmd(cmd_name: &str, stdin_vals: &[&str], args: &[&str]) -> Out { +pub fn run_cmd<'a, I: IntoIterator>( + cmd_name: &str, + stdin_vals: I, + args: &[&str], +) -> Out { let mut cmd = Command::new(cmd_name); for arg in args { @@ -99,8 +102,10 @@ pub fn run_cmd(cmd_name: &str, stdin_vals: &[&str], args: &[&str]) -> Out { } } -#[allow(dead_code)] -pub fn run_with_valgrind(stdin_vals: &[&str], args: &[&str]) -> (Out, String) { +pub fn run_with_valgrind<'a, I: IntoIterator>( + stdin_vals: I, + args: &[&str], +) -> (Out, String) { //TODO: figure out if there is a better way to get the valgrind executable. let mut cmd = Command::new("valgrind"); let named_tempfile = From 6f35d1891a51d2a6a4bb2d7e3a3a44ccafe14bdc Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 May 2022 23:30:40 -0400 Subject: [PATCH 02/15] Capture stdin for `roc` and `roc run` tests --- Cargo.lock | 1 + cli/tests/cli_run.rs | 42 ++++++++++++++++++++++++------------ cli_utils/Cargo.toml | 1 + cli_utils/src/bench_utils.rs | 9 +++++++- cli_utils/src/helpers.rs | 23 +++++++++++++++++--- 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb430e62a5..2c2b495e41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -507,6 +507,7 @@ name = "cli_utils" version = "0.1.0" dependencies = [ "bumpalo", + "const_format", "criterion 0.3.5 (git+https://github.com/Anton-4/criterion.rs)", "rlimit", "roc_cli", diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 7c979585c5..350ed157ab 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -84,7 +84,7 @@ mod cli_run { } fn check_compile_error(file: &Path, flags: &[&str], expected: &str) { - let compile_out = run_roc(["check", file.to_str().unwrap()].iter().chain(flags)); + let compile_out = run_roc(["check", file.to_str().unwrap()].iter().chain(flags), &[]); let err = compile_out.stdout.trim(); let err = strip_colors(err); @@ -96,7 +96,7 @@ mod cli_run { } fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) { - let out = run_roc(["format", file.to_str().unwrap(), CHECK_FLAG]); + let out = run_roc(["format", file.to_str().unwrap(), CHECK_FLAG], &[]); if expects_success_exit_code { assert!(out.status.success()); } else { @@ -104,10 +104,22 @@ mod cli_run { } } - fn run_roc_on<'a, I: IntoIterator>(file: &'a Path, args: I) -> Out { - let compile_out = run_roc(args.into_iter().chain(iter::once(file.to_str().unwrap()))); - if !compile_out.stderr.is_empty() { - panic!("roc build had stderr: {}", compile_out.stderr); + fn run_roc_on<'a, I: IntoIterator>( + file: &'a Path, + args: I, + stdin: &[&str], + ) -> Out { + let compile_out = run_roc( + args.into_iter().chain(iter::once(file.to_str().unwrap())), + stdin, + ); + + if !compile_out.stderr.is_empty() && + // If there is any stderr, it should be reporting the runtime and that's it! + !(compile_out.stderr.starts_with("runtime: ") + && compile_out.stderr.ends_with("ms\n")) + { + panic!("roc build had unexpected stderr: {}", compile_out.stderr); } assert!(compile_out.status.success(), "bad status {:?}", compile_out); @@ -137,7 +149,7 @@ mod cli_run { let out = match cli_mode { CliMode::RocBuild => { - run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone())); + run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[]); if use_valgrind && ALLOW_VALGRIND { let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { @@ -157,8 +169,8 @@ mod cli_run { if valgrind_out.status.success() { let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { - panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nvalgrind xml was: \"{}\"\n\nvalgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", err, raw_xml, valgrind_out.stdout, valgrind_out.stderr); - }); + panic!("failed to parse the `valgrind` xml output. Error was:\n\n{:?}\n\nvalgrind xml was: \"{}\"\n\nvalgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", err, raw_xml, valgrind_out.stdout, valgrind_out.stderr); + }); if !memory_errors.is_empty() { for error in memory_errors { @@ -204,8 +216,10 @@ mod cli_run { ) } } - CliMode::Roc => run_roc_on(file, flags.clone()), - CliMode::RocRun => run_roc_on(file, iter::once(CMD_RUN).chain(flags.clone())), + CliMode::Roc => run_roc_on(file, flags.clone(), stdin), + CliMode::RocRun => { + run_roc_on(file, iter::once(CMD_RUN).chain(flags.clone()), stdin) + } }; if !&out.stdout.ends_with(expected_ending) { @@ -293,7 +307,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG]); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[]); return; } @@ -318,7 +332,7 @@ mod cli_run { &file_name, example.stdin, example.executable_filename, - [OPTIMIZE_FLAG], + &[OPTIMIZE_FLAG], example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, @@ -590,7 +604,7 @@ mod cli_run { &file_name, benchmark.stdin, benchmark.executable_filename, - [OPTIMIZE_FLAG], + &[OPTIMIZE_FLAG], benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, ); diff --git a/cli_utils/Cargo.toml b/cli_utils/Cargo.toml index 6f90db6737..a309bde670 100644 --- a/cli_utils/Cargo.toml +++ b/cli_utils/Cargo.toml @@ -20,6 +20,7 @@ serde = { version = "1.0.130", features = ["derive"] } serde-xml-rs = "0.5.1" strip-ansi-escapes = "0.1.1" tempfile = "3.2.0" +const_format = "0.2.22" [target.'cfg(unix)'.dependencies] rlimit = "0.6.2" diff --git a/cli_utils/src/bench_utils.rs b/cli_utils/src/bench_utils.rs index a7797f010a..8ba4727efd 100644 --- a/cli_utils/src/bench_utils.rs +++ b/cli_utils/src/bench_utils.rs @@ -1,9 +1,13 @@ use crate::helpers::{example_file, run_cmd, run_roc}; +use const_format::concatcp; use criterion::{black_box, measurement::Measurement, BenchmarkGroup}; +use roc_cli::CMD_BUILD; use std::{path::Path, thread}; const CFOLD_STACK_SIZE: usize = 8192 * 100000; +const OPTIMIZE_FLAG: &str = concatcp!("--", roc_cli::FLAG_OPTIMIZE); + fn exec_bench_w_input( file: &Path, stdin_str: &'static str, @@ -11,7 +15,10 @@ fn exec_bench_w_input( expected_ending: &str, bench_group_opt: Option<&mut BenchmarkGroup>, ) { - let compile_out = run_roc(["build", "--optimize", file.to_str().unwrap()]); + let compile_out = run_roc( + [CMD_BUILD, OPTIMIZE_FLAG, file.to_str().unwrap()], + &[stdin_str], + ); if !compile_out.stderr.is_empty() { panic!("{}", compile_out.stderr); diff --git a/cli_utils/src/helpers.rs b/cli_utils/src/helpers.rs index 0bebe620ba..96d330a8b6 100644 --- a/cli_utils/src/helpers.rs +++ b/cli_utils/src/helpers.rs @@ -45,17 +45,34 @@ pub fn path_to_roc_binary() -> PathBuf { path } -pub fn run_roc, S: AsRef>(args: I) -> Out { +pub fn run_roc, S: AsRef>(args: I, stdin_vals: &[&str]) -> Out { let mut cmd = Command::new(path_to_roc_binary()); for arg in args { cmd.arg(arg); } - let output = cmd - .output() + let mut child = cmd + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() .expect("failed to execute compiled `roc` binary in CLI test"); + { + let stdin = child.stdin.as_mut().expect("Failed to open stdin"); + + for stdin_str in stdin_vals.iter() { + stdin + .write_all(stdin_str.as_bytes()) + .expect("Failed to write to stdin"); + } + } + + let output = child + .wait_with_output() + .expect("failed to get output for compiled `roc` binary in CLI test"); + Out { stdout: String::from_utf8(output.stdout).unwrap(), stderr: String::from_utf8(output.stderr).unwrap(), From 8849e5cdd151319d5ceaaae6e17b009d67fd9982 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 12:22:09 -0400 Subject: [PATCH 03/15] Improve false interpreter missing CLI arg message --- cli/src/lib.rs | 2 +- examples/false-interpreter/platform/src/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 18d4e4de53..03d106730f 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -489,7 +489,7 @@ fn roc_run( ) -> io::Result { use std::os::unix::process::CommandExt; - let mut cmd = match triple.architecture { + match triple.architecture { Architecture::Wasm32 => { // If possible, report the generated executable name relative to the current dir. let generated_filename = binary_path diff --git a/examples/false-interpreter/platform/src/lib.rs b/examples/false-interpreter/platform/src/lib.rs index 0b60869fa7..7efee7307c 100644 --- a/examples/false-interpreter/platform/src/lib.rs +++ b/examples/false-interpreter/platform/src/lib.rs @@ -74,7 +74,9 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut #[no_mangle] pub extern "C" fn rust_main() -> i32 { - let arg = env::args().nth(1).unwrap(); + let arg = env::args() + .nth(1) + .expect("Please pass a .false file as a command-line argument to the false interpreter!"); let arg = RocStr::from(arg.as_str()); let size = unsafe { roc_main_size() } as usize; From 39ba0aca29e1f1dfff36298b5d1790330eb96407 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 12:24:27 -0400 Subject: [PATCH 04/15] Reorganize parsing of extra CLI args --- cli/src/main.rs | 61 +++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 0a21c66ed5..585ea4003b 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -26,46 +26,37 @@ fn main() -> io::Result<()> { let matches = build_app().get_matches(); let exit_code = match matches.subcommand() { - None => { - match matches.index_of(ROC_FILE) { - Some(arg_index) => { - let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! + None => match matches.index_of(ROC_FILE) { + Some(arg_index) => build( + &matches, + BuildConfig::BuildAndRunIfNoErrors { + roc_file_arg_index: arg_index + 1, + }, + Triple::host(), + LinkType::Executable, + ), - build( - &matches, - BuildConfig::BuildAndRunIfNoErrors { roc_file_arg_index }, - Triple::host(), - LinkType::Executable, - ) - } + None => { + launch_editor(None)?; - None => { - launch_editor(None)?; - - Ok(0) - } + Ok(0) } - } - Some((CMD_RUN, matches)) => { - match matches.index_of(ROC_FILE) { - Some(arg_index) => { - let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! + }, + Some((CMD_RUN, matches)) => match matches.index_of(ROC_FILE) { + Some(arg_index) => build( + matches, + BuildConfig::BuildAndRun { + roc_file_arg_index: arg_index + 1, + }, + Triple::host(), + LinkType::Executable, + ), + None => { + eprintln!("What .roc file do you want to run? Specify it at the end of the `roc run` command."); - build( - matches, - BuildConfig::BuildAndRun { roc_file_arg_index }, - Triple::host(), - LinkType::Executable, - ) - } - - None => { - eprintln!("What .roc file do you want to run? Specify it at the end of the `roc run` command."); - - Ok(1) - } + Ok(1) } - } + }, Some((CMD_BUILD, matches)) => { let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default(); From 71fa8c6ee2589a4b8e3943f40a274ded093bf04b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 16:23:19 -0400 Subject: [PATCH 05/15] Allow args to pass through `roc run` to application --- cli/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 03d106730f..97afbb0cc3 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -153,6 +153,12 @@ pub fn build_app<'a>() -> Command<'a> { .help("The .roc file of an app to run") .required(true), ) + .arg( + Arg::new(ARGS_FOR_APP) + .help("Arguments to pass into the app being run") + .requires(ROC_FILE) + .multiple_values(true), + ) ) .subcommand(Command::new(CMD_FORMAT) .about("Format a .roc file using standard Roc formatting") From e3865a36792e039aff709d62f1c1a9eee41c8b39 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:01:38 -0400 Subject: [PATCH 06/15] Use matches_of_os for file paths --- cli/src/lib.rs | 50 ++++++++++++++++++++++--------------------------- cli/src/main.rs | 2 +- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 97afbb0cc3..a17f9d07d1 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3,16 +3,15 @@ extern crate const_format; use build::BuiltFile; use bumpalo::Bump; -use clap::Command; -use clap::{Arg, ArgMatches}; +use clap::{Arg, ArgMatches, Command}; use roc_build::link::LinkType; use roc_error_macros::user_error; use roc_load::{LoadingProblem, Threading}; use roc_mono::ir::OptLevel; use std::env; +use std::ffi::OsStr; use std::io; -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process; use target_lexicon::BinaryFormat; use target_lexicon::{ @@ -96,6 +95,17 @@ pub fn build_app<'a>() -> Command<'a> { .possible_values(["true", "false"]) .required(false); + let roc_file_to_run = Arg::new(ROC_FILE) + .help("The .roc file of an app to run") + .allow_invalid_utf8(true) + .required(true); + + let args_for_app = Arg::new(ARGS_FOR_APP) + .help("Arguments to pass into the app being run") + .requires(ROC_FILE) + .allow_invalid_utf8(true) + .multiple_values(true); + let app = Command::new("roc") .version(concatcp!(VERSION, "\n")) .about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!") @@ -132,6 +142,7 @@ pub fn build_app<'a>() -> Command<'a> { .arg( Arg::new(ROC_FILE) .help("The .roc file to build") + .allow_invalid_utf8(true) .required(true), ) ) @@ -148,17 +159,8 @@ pub fn build_app<'a>() -> Command<'a> { .arg(flag_linker.clone()) .arg(flag_precompiled.clone()) .arg(flag_valgrind.clone()) - .arg( - Arg::new(ROC_FILE) - .help("The .roc file of an app to run") - .required(true), - ) - .arg( - Arg::new(ARGS_FOR_APP) - .help("Arguments to pass into the app being run") - .requires(ROC_FILE) - .multiple_values(true), - ) + .arg(roc_file_to_run.clone()) + .arg(args_for_app.clone()) ) .subcommand(Command::new(CMD_FORMAT) .about("Format a .roc file using standard Roc formatting") @@ -183,6 +185,7 @@ pub fn build_app<'a>() -> Command<'a> { .arg( Arg::new(ROC_FILE) .help("The .roc file of an app to check") + .allow_invalid_utf8(true) .required(true), ) ) @@ -206,17 +209,8 @@ pub fn build_app<'a>() -> Command<'a> { .arg(flag_linker) .arg(flag_precompiled) .arg(flag_valgrind) - .arg( - Arg::new(ROC_FILE) - .help("The .roc file of an app to build and run") - .required(false), - ) - .arg( - Arg::new(ARGS_FOR_APP) - .help("Arguments to pass into the app being run") - .requires(ROC_FILE) - .multiple_values(true), - ); + .arg(roc_file_to_run) + .arg(args_for_app); if cfg!(feature = "editor") { app.subcommand( @@ -261,7 +255,7 @@ pub fn build( use BuildConfig::*; let arena = Bump::new(); - let filename = matches.value_of(ROC_FILE).unwrap(); + let filename = matches.value_of_os(ROC_FILE).unwrap(); let original_cwd = std::env::current_dir()?; let opt_level = match ( @@ -466,7 +460,7 @@ pub fn build( "warnings" }, total_time.as_millis(), - filename + filename.to_string_lossy() ); Ok(problems.exit_code()) diff --git a/cli/src/main.rs b/cli/src/main.rs index 585ea4003b..c07054a624 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -81,7 +81,7 @@ fn main() -> io::Result<()> { let arena = bumpalo::Bump::new(); let emit_timings = matches.is_present(FLAG_TIME); - let filename = matches.value_of(ROC_FILE).unwrap(); + let filename = matches.value_of_os(ROC_FILE).unwrap(); let roc_file_path = PathBuf::from(filename); let src_dir = roc_file_path.parent().unwrap().to_owned(); From 81bdc507f5019123769c99a25c202a1a774367d1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:06:47 -0400 Subject: [PATCH 07/15] Pass args from clap to `roc`/`roc run` child processes This works much better than the previous "arg index" approach, especially with subcommands like `roc run` --- cli/src/lib.rs | 142 +++++++++++++++++++++++++++--------------------- cli/src/main.rs | 43 +++++++-------- 2 files changed, 100 insertions(+), 85 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index a17f9d07d1..abc782292a 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -97,8 +97,7 @@ pub fn build_app<'a>() -> Command<'a> { let roc_file_to_run = Arg::new(ROC_FILE) .help("The .roc file of an app to run") - .allow_invalid_utf8(true) - .required(true); + .allow_invalid_utf8(true); let args_for_app = Arg::new(ARGS_FOR_APP) .help("Arguments to pass into the app being run") @@ -159,7 +158,7 @@ pub fn build_app<'a>() -> Command<'a> { .arg(flag_linker.clone()) .arg(flag_precompiled.clone()) .arg(flag_valgrind.clone()) - .arg(roc_file_to_run.clone()) + .arg(roc_file_to_run.clone().required(true)) .arg(args_for_app.clone()) ) .subcommand(Command::new(CMD_FORMAT) @@ -209,7 +208,7 @@ pub fn build_app<'a>() -> Command<'a> { .arg(flag_linker) .arg(flag_precompiled) .arg(flag_valgrind) - .arg(roc_file_to_run) + .arg(roc_file_to_run.required(false)) .arg(args_for_app); if cfg!(feature = "editor") { @@ -236,8 +235,8 @@ pub fn docs(files: Vec) { #[derive(Debug, PartialEq, Eq)] pub enum BuildConfig { BuildOnly, - BuildAndRun { roc_file_arg_index: usize }, - BuildAndRunIfNoErrors { roc_file_arg_index: usize }, + BuildAndRun, + BuildAndRunIfNoErrors, } pub enum FormatMode { @@ -372,7 +371,7 @@ pub fn build( // Return a nonzero exit code if there were problems Ok(problems.exit_code()) } - BuildAndRun { roc_file_arg_index } => { + BuildAndRun => { if problems.errors > 0 || problems.warnings > 0 { println!( "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.\n\nRunning program anyway…\n\n\x1B[36m{}\x1B[39m", @@ -403,15 +402,11 @@ pub fn build( ); } - roc_run( - arena, - &original_cwd, - triple, - roc_file_arg_index, - &binary_path, - ) + let args = matches.values_of_os(ARGS_FOR_APP).unwrap_or_default(); + + roc_run(arena, &original_cwd, triple, args, &binary_path) } - BuildAndRunIfNoErrors { roc_file_arg_index } => { + BuildAndRunIfNoErrors => { if problems.errors == 0 { if problems.warnings > 0 { println!( @@ -427,13 +422,9 @@ pub fn build( ); } - roc_run( - arena, - &original_cwd, - triple, - roc_file_arg_index, - &binary_path, - ) + let args = matches.values_of_os(ARGS_FOR_APP).unwrap_or_default(); + + roc_run(arena, &original_cwd, triple, args, &binary_path) } else { println!( "\x1B[{}m{}\x1B[39m {} and \x1B[{}m{}\x1B[39m {} found in {} ms.\n\nYou can run the program anyway with: \x1B[32mroc run {}\x1B[39m", @@ -479,16 +470,13 @@ pub fn build( } } -#[cfg(target_family = "unix")] -fn roc_run( +fn roc_run<'a, I: IntoIterator>( arena: Bump, // This should be passed an owned value, not a reference, so we can usefully mem::forget it! cwd: &Path, triple: Triple, - roc_file_arg_index: usize, + args: I, binary_path: &Path, ) -> io::Result { - use std::os::unix::process::CommandExt; - match triple.architecture { Architecture::Wasm32 => { // If possible, report the generated executable name relative to the current dir. @@ -500,19 +488,44 @@ fn roc_run( // since the process is about to exit anyway. std::mem::forget(arena); - let args = std::env::args() - .skip(roc_file_arg_index) - .collect::>(); + if cfg!(target_family = "unix") { + use std::os::unix::ffi::OsStrExt; - run_with_wasmer(generated_filename, &args); - return Ok(0); + run_with_wasmer( + generated_filename, + args.into_iter().map(|os_str| os_str.as_bytes()), + ); + } else { + run_with_wasmer( + generated_filename, + args.into_iter().map(|os_str| { + os_str.to_str().expect( + "Roc does not currently support passing non-UTF8 arguments to Wasmer.", + ) + }), + ); + } + + Ok(0) + } + _ => { + if cfg!(target_family = "unix") { + roc_run_unix(cwd, args, binary_path) + } else { + roc_run_non_unix(arena, cwd, args, binary_path) + } } - _ => std::process::Command::new(&binary_path), - }; - - if let Architecture::Wasm32 = triple.architecture { - cmd.arg(binary_path); } +} + +fn roc_run_unix, S: AsRef>( + cwd: &Path, + args: I, + binary_path: &Path, +) -> io::Result { + use std::os::unix::process::CommandExt; + + let mut cmd = std::process::Command::new(&binary_path); // Forward all the arguments after the .roc file argument // to the new process. This way, you can do things like: @@ -521,10 +534,8 @@ fn roc_run( // // ...and have it so that app.roc will receive only `foo`, // `bar`, and `baz` as its arguments. - for (index, arg) in std::env::args().enumerate() { - if index > roc_file_arg_index { - cmd.arg(arg); - } + for arg in args { + cmd.arg(arg); } // This is much faster than spawning a subprocess if we're on a UNIX system! @@ -536,29 +547,36 @@ fn roc_run( Err(err) } -#[cfg(not(target_family = "unix"))] -fn roc_run(cmd: &mut Command) -> io::Result { - // Run the compiled app - let exit_status = cmd - .spawn() - .unwrap_or_else(|err| panic!("Failed to run app after building it: {:?}", err)) - .wait() - .expect("TODO gracefully handle block_on failing when `roc` spawns a subprocess for the compiled app"); +fn roc_run_non_unix, S: AsRef>( + _arena: Bump, // This should be passed an owned value, not a reference, so we can usefully mem::forget it! + _cwd: &Path, + _args: I, + _binary_path: &Path, +) -> io::Result { + todo!("TODO support running roc programs on non-UNIX targets"); + // let mut cmd = std::process::Command::new(&binary_path); - // `roc [FILE]` exits with the same status code as the app it ran. - // - // If you want to know whether there were compilation problems - // via status code, use either `roc build` or `roc check` instead! - match exit_status.code() { - Some(code) => Ok(code), - None => { - todo!("TODO gracefully handle the `roc [FILE]` subprocess terminating with a signal."); - } - } + // // Run the compiled app + // let exit_status = cmd + // .spawn() + // .unwrap_or_else(|err| panic!("Failed to run app after building it: {:?}", err)) + // .wait() + // .expect("TODO gracefully handle block_on failing when `roc` spawns a subprocess for the compiled app"); + + // // `roc [FILE]` exits with the same status code as the app it ran. + // // + // // If you want to know whether there were compilation problems + // // via status code, use either `roc build` or `roc check` instead! + // match exit_status.code() { + // Some(code) => Ok(code), + // None => { + // todo!("TODO gracefully handle the `roc [FILE]` subprocess terminating with a signal."); + // } + // } } #[cfg(feature = "run-wasm32")] -fn run_with_wasmer(wasm_path: &std::path::Path, args: &[String]) { +fn run_with_wasmer, S: AsRef<[u8]>>(wasm_path: &std::path::Path, args: I) { use wasmer::{Instance, Module, Store}; let store = Store::default(); @@ -589,8 +607,8 @@ fn run_with_wasmer(wasm_path: &std::path::Path, args: &[String]) { } #[cfg(not(feature = "run-wasm32"))] -fn run_with_wasmer(_wasm_path: &std::path::Path, _args: &[String]) { - println!("Running wasm files not support"); +fn run_with_wasmer, S: AsRef<[u8]>>(_wasm_path: &std::path::Path, _args: I) { + println!("Running wasm files is not supported on this target."); } #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/cli/src/main.rs b/cli/src/main.rs index c07054a624..97d1031894 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -26,37 +26,34 @@ fn main() -> io::Result<()> { let matches = build_app().get_matches(); let exit_code = match matches.subcommand() { - None => match matches.index_of(ROC_FILE) { - Some(arg_index) => build( - &matches, - BuildConfig::BuildAndRunIfNoErrors { - roc_file_arg_index: arg_index + 1, - }, - Triple::host(), - LinkType::Executable, - ), - - None => { + None => { + if matches.is_present(ROC_FILE) { + build( + &matches, + BuildConfig::BuildAndRunIfNoErrors, + Triple::host(), + LinkType::Executable, + ) + } else { launch_editor(None)?; Ok(0) } - }, - Some((CMD_RUN, matches)) => match matches.index_of(ROC_FILE) { - Some(arg_index) => build( - matches, - BuildConfig::BuildAndRun { - roc_file_arg_index: arg_index + 1, - }, - Triple::host(), - LinkType::Executable, - ), - None => { + } + Some((CMD_RUN, matches)) => { + if matches.is_present(ROC_FILE) { + build( + matches, + BuildConfig::BuildAndRun, + Triple::host(), + LinkType::Executable, + ) + } else { eprintln!("What .roc file do you want to run? Specify it at the end of the `roc run` command."); Ok(1) } - }, + } Some((CMD_BUILD, matches)) => { let target: Target = matches.value_of_t(FLAG_TARGET).unwrap_or_default(); From 7cbde410e543943f67c61761d9e9b423eff34c74 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:50:47 -0400 Subject: [PATCH 08/15] Simplify some error reporting --- cli/tests/cli_run.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 350ed157ab..9ecad60427 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -97,11 +97,8 @@ mod cli_run { fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) { let out = run_roc(["format", file.to_str().unwrap(), CHECK_FLAG], &[]); - if expects_success_exit_code { - assert!(out.status.success()); - } else { - assert!(!out.status.success()); - } + + assert_eq!(out.status.success(), expects_success_exit_code); } fn run_roc_on<'a, I: IntoIterator>( @@ -119,7 +116,10 @@ mod cli_run { !(compile_out.stderr.starts_with("runtime: ") && compile_out.stderr.ends_with("ms\n")) { - panic!("roc build had unexpected stderr: {}", compile_out.stderr); + panic!( + "`roc` command had unexpected stderr: {}", + compile_out.stderr + ); } assert!(compile_out.status.success(), "bad status {:?}", compile_out); From b64e0b3ce4c32b9dbf93cc7a553379bdae4abaaf Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:50:58 -0400 Subject: [PATCH 09/15] Pass input files to `roc` and `roc run` in CLI tests --- cli/tests/cli_run.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 9ecad60427..7b4024ce0a 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -105,11 +105,19 @@ mod cli_run { file: &'a Path, args: I, stdin: &[&str], + input_file: Option, ) -> Out { - let compile_out = run_roc( - args.into_iter().chain(iter::once(file.to_str().unwrap())), - stdin, - ); + let compile_out = match input_file { + Some(input_file) => run_roc( + args.into_iter() + .chain([file.to_str().unwrap(), input_file.to_str().unwrap()]), + stdin, + ), + None => run_roc( + args.into_iter().chain(iter::once(file.to_str().unwrap())), + stdin, + ), + }; if !compile_out.stderr.is_empty() && // If there is any stderr, it should be reporting the runtime and that's it! @@ -149,7 +157,7 @@ mod cli_run { let out = match cli_mode { CliMode::RocBuild => { - run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[]); + run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None); if use_valgrind && ALLOW_VALGRIND { let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { @@ -157,7 +165,7 @@ mod cli_run { stdin.clone().iter().copied(), &[ file.with_file_name(executable_filename).to_str().unwrap(), - input_file.to_str().unwrap(), + input_file.clone().to_str().unwrap(), ], ) } else { @@ -216,10 +224,13 @@ mod cli_run { ) } } - CliMode::Roc => run_roc_on(file, flags.clone(), stdin), - CliMode::RocRun => { - run_roc_on(file, iter::once(CMD_RUN).chain(flags.clone()), stdin) - } + CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_file.clone()), + CliMode::RocRun => run_roc_on( + file, + iter::once(CMD_RUN).chain(flags.clone()), + stdin, + input_file.clone(), + ), }; if !&out.stdout.ends_with(expected_ending) { @@ -307,7 +318,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[]); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], None); return; } From f07ffb58f204e45ae080ac76c18e7540b209b138 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:51:14 -0400 Subject: [PATCH 10/15] Experiment with multiple input files in CLI tests --- cli/tests/cli_run.rs | 89 +++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 7b4024ce0a..92a326e2f1 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -20,7 +20,7 @@ mod cli_run { use roc_test_utils::assert_multiline_str_eq; use serial_test::serial; use std::iter; - use std::path::{Path, PathBuf}; + use std::path::Path; use strum::IntoEnumIterator; use strum_macros::EnumIter; @@ -101,23 +101,17 @@ mod cli_run { assert_eq!(out.status.success(), expects_success_exit_code); } - fn run_roc_on<'a, I: IntoIterator>( + fn run_roc_on<'a, IA: IntoIterator, IF: IntoIterator>( file: &'a Path, - args: I, + args: IA, stdin: &[&str], - input_file: Option, + input_files: IF, ) -> Out { - let compile_out = match input_file { - Some(input_file) => run_roc( - args.into_iter() - .chain([file.to_str().unwrap(), input_file.to_str().unwrap()]), - stdin, - ), - None => run_roc( - args.into_iter().chain(iter::once(file.to_str().unwrap())), - stdin, - ), - }; + let compile_out = run_roc( + args.into_iter() + .chain(iter::once(file.to_str().unwrap()).chain(input_files)), + stdin, + ); if !compile_out.stderr.is_empty() && // If there is any stderr, it should be reporting the runtime and that's it! @@ -135,12 +129,12 @@ mod cli_run { compile_out } - fn check_output_with_stdin( - file: &Path, + fn check_output_with_stdin<'a, I: IntoIterator>( + file: &'a Path, stdin: &[&str], executable_filename: &str, - flags: &[&str], - input_file: Option, + flags: &[&'a str], + input_files: I, expected_ending: &str, use_valgrind: bool, ) { @@ -160,20 +154,21 @@ mod cli_run { run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None); if use_valgrind && ALLOW_VALGRIND { - let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { - run_with_valgrind( - stdin.clone().iter().copied(), - &[ - file.with_file_name(executable_filename).to_str().unwrap(), - input_file.clone().to_str().unwrap(), - ], - ) - } else { - run_with_valgrind( - stdin.clone().iter().copied(), - &[file.with_file_name(executable_filename).to_str().unwrap()], - ) - }; + let (valgrind_out, raw_xml) = + if let Some(ref input_file) = input_files.into_iter().next() { + run_with_valgrind( + stdin.clone().iter().copied(), + &[ + file.with_file_name(executable_filename).to_str().unwrap(), + input_file.clone(), + ], + ) + } else { + run_with_valgrind( + stdin.clone().iter().copied(), + &[file.with_file_name(executable_filename).to_str().unwrap()], + ) + }; if valgrind_out.status.success() { let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { @@ -210,11 +205,11 @@ mod cli_run { } valgrind_out - } else if let Some(ref input_file) = input_file { + } else if let Some(ref input_file) = input_files.into_iter().next() { run_cmd( file.with_file_name(executable_filename).to_str().unwrap(), stdin.iter().copied(), - &[input_file.to_str().unwrap()], + &[input_file], ) } else { run_cmd( @@ -224,12 +219,12 @@ mod cli_run { ) } } - CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_file.clone()), + CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_files), CliMode::RocRun => run_roc_on( file, iter::once(CMD_RUN).chain(flags.clone()), stdin, - input_file.clone(), + input_files, ), }; @@ -318,7 +313,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], None); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], iter::empty()); return; } @@ -331,7 +326,7 @@ mod cli_run { example.stdin, example.executable_filename, &[], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -344,7 +339,7 @@ mod cli_run { example.stdin, example.executable_filename, &[OPTIMIZE_FLAG], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -357,7 +352,7 @@ mod cli_run { example.stdin, example.executable_filename, &[LINKER_FLAG, "legacy"], - example.input_file.and_then(|file| Some(example_file(dir_name, file))), + example.input_file.and_then(|file| example_file(dir_name, file).to_str()), example.expected_ending, example.use_valgrind, ); @@ -564,7 +559,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[], - benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), + benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -574,7 +569,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[OPTIMIZE_FLAG], - benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), + benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -863,7 +858,7 @@ mod cli_run { &[], "multi-dep-str", &[], - None, + iter::empty(), "I am Dep2.str2\n", true, ); @@ -877,7 +872,7 @@ mod cli_run { &[], "multi-dep-str", &[OPTIMIZE_FLAG], - None, + iter::empty(), "I am Dep2.str2\n", true, ); @@ -891,7 +886,7 @@ mod cli_run { &[], "multi-dep-thunk", &[], - None, + iter::empty(), "I am Dep2.value2\n", true, ); @@ -905,7 +900,7 @@ mod cli_run { &[], "multi-dep-thunk", &[OPTIMIZE_FLAG], - None, + iter::empty(), "I am Dep2.value2\n", true, ); From 4a98f7ff0ba7022b9b8522542f88f587832856a7 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 17:51:25 -0400 Subject: [PATCH 11/15] Revert "Experiment with multiple input files in CLI tests" This reverts commit f07ffb58f204e45ae080ac76c18e7540b209b138. --- cli/tests/cli_run.rs | 89 +++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 92a326e2f1..7b4024ce0a 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -20,7 +20,7 @@ mod cli_run { use roc_test_utils::assert_multiline_str_eq; use serial_test::serial; use std::iter; - use std::path::Path; + use std::path::{Path, PathBuf}; use strum::IntoEnumIterator; use strum_macros::EnumIter; @@ -101,17 +101,23 @@ mod cli_run { assert_eq!(out.status.success(), expects_success_exit_code); } - fn run_roc_on<'a, IA: IntoIterator, IF: IntoIterator>( + fn run_roc_on<'a, I: IntoIterator>( file: &'a Path, - args: IA, + args: I, stdin: &[&str], - input_files: IF, + input_file: Option, ) -> Out { - let compile_out = run_roc( - args.into_iter() - .chain(iter::once(file.to_str().unwrap()).chain(input_files)), - stdin, - ); + let compile_out = match input_file { + Some(input_file) => run_roc( + args.into_iter() + .chain([file.to_str().unwrap(), input_file.to_str().unwrap()]), + stdin, + ), + None => run_roc( + args.into_iter().chain(iter::once(file.to_str().unwrap())), + stdin, + ), + }; if !compile_out.stderr.is_empty() && // If there is any stderr, it should be reporting the runtime and that's it! @@ -129,12 +135,12 @@ mod cli_run { compile_out } - fn check_output_with_stdin<'a, I: IntoIterator>( - file: &'a Path, + fn check_output_with_stdin( + file: &Path, stdin: &[&str], executable_filename: &str, - flags: &[&'a str], - input_files: I, + flags: &[&str], + input_file: Option, expected_ending: &str, use_valgrind: bool, ) { @@ -154,21 +160,20 @@ mod cli_run { run_roc_on(file, iter::once(CMD_BUILD).chain(flags.clone()), &[], None); if use_valgrind && ALLOW_VALGRIND { - let (valgrind_out, raw_xml) = - if let Some(ref input_file) = input_files.into_iter().next() { - run_with_valgrind( - stdin.clone().iter().copied(), - &[ - file.with_file_name(executable_filename).to_str().unwrap(), - input_file.clone(), - ], - ) - } else { - run_with_valgrind( - stdin.clone().iter().copied(), - &[file.with_file_name(executable_filename).to_str().unwrap()], - ) - }; + let (valgrind_out, raw_xml) = if let Some(ref input_file) = input_file { + run_with_valgrind( + stdin.clone().iter().copied(), + &[ + file.with_file_name(executable_filename).to_str().unwrap(), + input_file.clone().to_str().unwrap(), + ], + ) + } else { + run_with_valgrind( + stdin.clone().iter().copied(), + &[file.with_file_name(executable_filename).to_str().unwrap()], + ) + }; if valgrind_out.status.success() { let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| { @@ -205,11 +210,11 @@ mod cli_run { } valgrind_out - } else if let Some(ref input_file) = input_files.into_iter().next() { + } else if let Some(ref input_file) = input_file { run_cmd( file.with_file_name(executable_filename).to_str().unwrap(), stdin.iter().copied(), - &[input_file], + &[input_file.to_str().unwrap()], ) } else { run_cmd( @@ -219,12 +224,12 @@ mod cli_run { ) } } - CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_files), + CliMode::Roc => run_roc_on(file, flags.clone(), stdin, input_file.clone()), CliMode::RocRun => run_roc_on( file, iter::once(CMD_RUN).chain(flags.clone()), stdin, - input_files, + input_file.clone(), ), }; @@ -313,7 +318,7 @@ mod cli_run { } "hello-gui" | "breakout" => { // Since these require opening a window, we do `roc build` on them but don't run them. - run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], iter::empty()); + run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], None); return; } @@ -326,7 +331,7 @@ mod cli_run { example.stdin, example.executable_filename, &[], - example.input_file.and_then(|file| example_file(dir_name, file).to_str()), + example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, ); @@ -339,7 +344,7 @@ mod cli_run { example.stdin, example.executable_filename, &[OPTIMIZE_FLAG], - example.input_file.and_then(|file| example_file(dir_name, file).to_str()), + example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, ); @@ -352,7 +357,7 @@ mod cli_run { example.stdin, example.executable_filename, &[LINKER_FLAG, "legacy"], - example.input_file.and_then(|file| example_file(dir_name, file).to_str()), + example.input_file.and_then(|file| Some(example_file(dir_name, file))), example.expected_ending, example.use_valgrind, ); @@ -559,7 +564,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[], - benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), + benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -569,7 +574,7 @@ mod cli_run { benchmark.stdin, benchmark.executable_filename, &[OPTIMIZE_FLAG], - benchmark.input_file.and_then(|file| examples_dir("benchmarks").join(file).to_str()), + benchmark.input_file.and_then(|file| Some(examples_dir("benchmarks").join(file))), benchmark.expected_ending, benchmark.use_valgrind, ); @@ -858,7 +863,7 @@ mod cli_run { &[], "multi-dep-str", &[], - iter::empty(), + None, "I am Dep2.str2\n", true, ); @@ -872,7 +877,7 @@ mod cli_run { &[], "multi-dep-str", &[OPTIMIZE_FLAG], - iter::empty(), + None, "I am Dep2.str2\n", true, ); @@ -886,7 +891,7 @@ mod cli_run { &[], "multi-dep-thunk", &[], - iter::empty(), + None, "I am Dep2.value2\n", true, ); @@ -900,7 +905,7 @@ mod cli_run { &[], "multi-dep-thunk", &[OPTIMIZE_FLAG], - iter::empty(), + None, "I am Dep2.value2\n", true, ); From 1bae95574ed606391afabff5dba0111f243bd031 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 18:03:01 -0400 Subject: [PATCH 12/15] Use more CMD_ constants in cli_run test --- cli/tests/cli_run.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 7b4024ce0a..4732ca86ad 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -16,7 +16,7 @@ mod cli_run { }; use const_format::concatcp; use indoc::indoc; - use roc_cli::{CMD_BUILD, CMD_RUN}; + use roc_cli::{CMD_BUILD, CMD_CHECK, CMD_FORMAT, CMD_RUN}; use roc_test_utils::assert_multiline_str_eq; use serial_test::serial; use std::iter; @@ -84,7 +84,7 @@ mod cli_run { } fn check_compile_error(file: &Path, flags: &[&str], expected: &str) { - let compile_out = run_roc(["check", file.to_str().unwrap()].iter().chain(flags), &[]); + let compile_out = run_roc([CMD_CHECK, file.to_str().unwrap()].iter().chain(flags), &[]); let err = compile_out.stdout.trim(); let err = strip_colors(err); @@ -96,7 +96,7 @@ mod cli_run { } fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) { - let out = run_roc(["format", file.to_str().unwrap(), CHECK_FLAG], &[]); + let out = run_roc([CMD_FORMAT, file.to_str().unwrap(), CHECK_FLAG], &[]); assert_eq!(out.status.success(), expects_success_exit_code); } From f8100d1ec6d8b81a5ff7a8d343457b8b3c7b6bd2 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 6 May 2022 18:03:22 -0400 Subject: [PATCH 13/15] Fix lifetime issue in cli_run --- cli/tests/cli_run.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/tests/cli_run.rs b/cli/tests/cli_run.rs index 4732ca86ad..f76a613f68 100644 --- a/cli/tests/cli_run.rs +++ b/cli/tests/cli_run.rs @@ -109,8 +109,11 @@ mod cli_run { ) -> Out { let compile_out = match input_file { Some(input_file) => run_roc( - args.into_iter() - .chain([file.to_str().unwrap(), input_file.to_str().unwrap()]), + // converting these all to String avoids lifetime issues + args.into_iter().map(|arg| arg.to_string()).chain([ + file.to_str().unwrap().to_string(), + input_file.to_str().unwrap().to_string(), + ]), stdin, ), None => run_roc( From 0626433a145de24b2ae3a1032322a562316c8f72 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Fri, 6 May 2022 22:54:42 -0400 Subject: [PATCH 14/15] Sweep unused deps `cargo +nightly udeps` told me what's good --- Cargo.lock | 16 ---------------- compiler/can/Cargo.toml | 2 -- compiler/ident/Cargo.toml | 3 --- compiler/load_internal/Cargo.toml | 2 -- compiler/module/Cargo.toml | 1 - compiler/mono/Cargo.toml | 1 - compiler/test_mono/Cargo.toml | 1 - docs/Cargo.toml | 3 --- repl_test/Cargo.toml | 8 -------- reporting/Cargo.toml | 1 - 10 files changed, 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b4691a883..b0d67a9d93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3356,8 +3356,6 @@ dependencies = [ "roc_repl_cli", "roc_test_utils", "strip-ansi-escapes", - "wasmer", - "wasmer-wasi", ] [[package]] @@ -3486,7 +3484,6 @@ dependencies = [ "bumpalo", "indoc", "pretty_assertions", - "roc_builtins", "roc_collections", "roc_error_macros", "roc_exhaustive", @@ -3496,7 +3493,6 @@ dependencies = [ "roc_region", "roc_types", "static_assertions 1.1.0", - "ven_graph", ] [[package]] @@ -3585,7 +3581,6 @@ name = "roc_docs" version = "0.1.0" dependencies = [ "bumpalo", - "indoc", "peg", "pretty_assertions", "pulldown-cmark", @@ -3603,8 +3598,6 @@ dependencies = [ "roc_target", "roc_types", "snafu", - "tempfile", - "uuid", ] [[package]] @@ -3753,9 +3746,6 @@ dependencies = [ [[package]] name = "roc_ident" version = "0.1.0" -dependencies = [ - "arrayvec 0.7.2", -] [[package]] name = "roc_linker" @@ -3798,7 +3788,6 @@ dependencies = [ "crossbeam", "indoc", "maplit", - "morphic_lib", "num_cpus", "parking_lot 0.12.0", "pretty_assertions", @@ -3819,7 +3808,6 @@ dependencies = [ "roc_test_utils", "roc_types", "roc_unify", - "tempfile", "ven_pretty", ] @@ -3827,7 +3815,6 @@ dependencies = [ name = "roc_module" version = "0.1.0" dependencies = [ - "arrayvec 0.7.2", "bumpalo", "lazy_static", "roc_collections", @@ -3844,7 +3831,6 @@ version = "0.1.0" dependencies = [ "bumpalo", "hashbrown 0.11.2", - "morphic_lib", "roc_builtins", "roc_can", "roc_collections", @@ -3987,7 +3973,6 @@ dependencies = [ "roc_target", "roc_test_utils", "roc_types", - "tempfile", "ven_pretty", ] @@ -4704,7 +4689,6 @@ version = "0.1.0" dependencies = [ "bumpalo", "indoc", - "pretty_assertions", "roc_builtins", "roc_can", "roc_collections", diff --git a/compiler/can/Cargo.toml b/compiler/can/Cargo.toml index b7b1851465..b57aba90ad 100644 --- a/compiler/can/Cargo.toml +++ b/compiler/can/Cargo.toml @@ -14,8 +14,6 @@ roc_module = { path = "../module" } roc_parse = { path = "../parse" } roc_problem = { path = "../problem" } roc_types = { path = "../types" } -roc_builtins = { path = "../builtins" } -ven_graph = { path = "../../vendor/pathfinding" } bumpalo = { version = "3.8.0", features = ["collections"] } static_assertions = "1.1.0" bitvec = "1" diff --git a/compiler/ident/Cargo.toml b/compiler/ident/Cargo.toml index 14edceaab5..d272f4818f 100644 --- a/compiler/ident/Cargo.toml +++ b/compiler/ident/Cargo.toml @@ -4,6 +4,3 @@ version = "0.1.0" authors = ["The Roc Contributors"] license = "UPL-1.0" edition = "2018" - -[dependencies] -arrayvec = "0.7.2" diff --git a/compiler/load_internal/Cargo.toml b/compiler/load_internal/Cargo.toml index df3ffe4ffb..230b807b5c 100644 --- a/compiler/load_internal/Cargo.toml +++ b/compiler/load_internal/Cargo.toml @@ -22,7 +22,6 @@ roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } roc_reporting = { path = "../../reporting" } roc_debug_flags = { path = "../debug_flags" } -morphic_lib = { path = "../../vendor/morphic_lib" } ven_pretty = { path = "../../vendor/pretty" } bumpalo = { version = "3.8.0", features = ["collections"] } parking_lot = "0.12" @@ -30,7 +29,6 @@ crossbeam = "0.8.1" num_cpus = "1.13.0" [dev-dependencies] -tempfile = "3.2.0" pretty_assertions = "1.0.0" maplit = "1.0.2" indoc = "1.0.3" diff --git a/compiler/module/Cargo.toml b/compiler/module/Cargo.toml index 50dc2e3eb2..9b8c272d54 100644 --- a/compiler/module/Cargo.toml +++ b/compiler/module/Cargo.toml @@ -14,4 +14,3 @@ bumpalo = { version = "3.8.0", features = ["collections"] } lazy_static = "1.4.0" static_assertions = "1.1.0" snafu = { version = "0.6.10", features = ["backtraces"] } -arrayvec = "0.7.2" diff --git a/compiler/mono/Cargo.toml b/compiler/mono/Cargo.toml index 79b1ea060c..f1ba6e9ff4 100644 --- a/compiler/mono/Cargo.toml +++ b/compiler/mono/Cargo.toml @@ -21,7 +21,6 @@ roc_target = { path = "../roc_target" } roc_error_macros = {path="../../error_macros"} roc_debug_flags = {path="../debug_flags"} ven_pretty = { path = "../../vendor/pretty" } -morphic_lib = { path = "../../vendor/morphic_lib" } bumpalo = { version = "3.8.0", features = ["collections"] } hashbrown = { version = "0.11.2", features = [ "bumpalo" ] } ven_graph = { path = "../../vendor/pathfinding" } diff --git a/compiler/test_mono/Cargo.toml b/compiler/test_mono/Cargo.toml index 9f336dbe73..fb06a403be 100644 --- a/compiler/test_mono/Cargo.toml +++ b/compiler/test_mono/Cargo.toml @@ -19,6 +19,5 @@ roc_mono = { path = "../mono" } roc_target = { path = "../roc_target" } roc_reporting = { path = "../../reporting" } test_mono_macros = { path = "../test_mono_macros" } -pretty_assertions = "1.0.0" bumpalo = { version = "3.8.0", features = ["collections"] } indoc = "1.0.3" diff --git a/docs/Cargo.toml b/docs/Cargo.toml index 1fe3c231e2..bea8b94242 100644 --- a/docs/Cargo.toml +++ b/docs/Cargo.toml @@ -28,6 +28,3 @@ peg = "0.8.0" [dev-dependencies] pretty_assertions = "1.0.0" -tempfile = "3.2.0" -uuid = { version = "0.8.2", features = ["v4"] } -indoc = "1.0.3" diff --git a/repl_test/Cargo.toml b/repl_test/Cargo.toml index 4ab8c31292..5eaed7c55b 100644 --- a/repl_test/Cargo.toml +++ b/repl_test/Cargo.toml @@ -12,17 +12,9 @@ lazy_static = "1.4.0" [dev-dependencies] indoc = "1.0.3" strip-ansi-escapes = "0.1.1" -wasmer-wasi = "2.2.1" roc_repl_cli = {path = "../repl_cli"} roc_test_utils = {path = "../test_utils"} -# Wasmer singlepass compiler only works on x86_64. -[target.'cfg(target_arch = "x86_64")'.dev-dependencies] -wasmer = { version = "2.2.1", default-features = false, features = ["singlepass", "universal"] } - -[target.'cfg(not(target_arch = "x86_64"))'.dev-dependencies] -wasmer = { version = "2.2.1", default-features = false, features = ["cranelift", "universal"] } - [features] wasm = [] diff --git a/reporting/Cargo.toml b/reporting/Cargo.toml index 1c107cf580..9ca5360dc6 100644 --- a/reporting/Cargo.toml +++ b/reporting/Cargo.toml @@ -29,4 +29,3 @@ roc_target = { path = "../compiler/roc_target" } roc_test_utils = { path = "../test_utils" } pretty_assertions = "1.0.0" indoc = "1.0.3" -tempfile = "3.2.0" From 7619216d8407cf9afe547d93263e53602c302578 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 7 May 2022 15:46:42 +0200 Subject: [PATCH 15/15] add wasmer dependency again in the repl_test crate --- Cargo.lock | 2 ++ repl_test/Cargo.toml | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b0d67a9d93..898f865f8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3356,6 +3356,8 @@ dependencies = [ "roc_repl_cli", "roc_test_utils", "strip-ansi-escapes", + "wasmer", + "wasmer-wasi", ] [[package]] diff --git a/repl_test/Cargo.toml b/repl_test/Cargo.toml index 5eaed7c55b..4ab8c31292 100644 --- a/repl_test/Cargo.toml +++ b/repl_test/Cargo.toml @@ -12,9 +12,17 @@ lazy_static = "1.4.0" [dev-dependencies] indoc = "1.0.3" strip-ansi-escapes = "0.1.1" +wasmer-wasi = "2.2.1" roc_repl_cli = {path = "../repl_cli"} roc_test_utils = {path = "../test_utils"} +# Wasmer singlepass compiler only works on x86_64. +[target.'cfg(target_arch = "x86_64")'.dev-dependencies] +wasmer = { version = "2.2.1", default-features = false, features = ["singlepass", "universal"] } + +[target.'cfg(not(target_arch = "x86_64"))'.dev-dependencies] +wasmer = { version = "2.2.1", default-features = false, features = ["cranelift", "universal"] } + [features] wasm = []