WIP Merge remote-tracking branch 'remote/main' into rebuild-platform

This commit is contained in:
Luke Boswell 2024-10-09 09:21:46 +11:00
commit e3afeaa7ff
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
138 changed files with 3544 additions and 4651 deletions

View file

@ -266,20 +266,23 @@ mod tests {
const FORMATTED_ROC: &str = r#"app [main] { pf: platform "platform/main.roc" }
import pf.Stdout
import pf.Task
import pf.Stdin
main =
Stdout.line! "I'm a Roc application!""#;
Stdout.line! "What's your name?"
name = Stdin.line!
Stdout.line! "Hi $(name)!""#;
const UNFORMATTED_ROC: &str = r#"app [main] { pf: platform "platform/main.roc" }
import pf.Stdout
import pf.Task
import pf.Stdin
main =
Stdout.line! "I'm a Roc application!"
Stdout.line! "What's your name?"
name = Stdin.line!
Stdout.line! "Hi $(name)!"
"#;
fn setup_test_file(dir: &Path, file_name: &str, contents: &str) -> PathBuf {

View file

@ -68,6 +68,8 @@ pub const FLAG_NO_LINK: &str = "no-link";
pub const FLAG_TARGET: &str = "target";
pub const FLAG_TIME: &str = "time";
pub const FLAG_VERBOSE: &str = "verbose";
pub const FLAG_NO_COLOR: &str = "no-color";
pub const FLAG_NO_HEADER: &str = "no-header";
pub const FLAG_LINKER: &str = "linker";
pub const FLAG_BUILD_HOST: &str = "build-host";
pub const FLAG_SUPPRESS_BUILD_HOST_WARNING: &str = "suppress-build-host-warning";
@ -88,7 +90,7 @@ pub const FLAG_PP_HOST: &str = "host";
pub const FLAG_PP_PLATFORM: &str = "platform";
pub const FLAG_PP_DYLIB: &str = "lib";
const VERSION: &str = include_str!("../../../version.txt");
pub const VERSION: &str = env!("ROC_VERSION");
const DEFAULT_GENERATED_DOCS_DIR: &str = "generated-docs";
pub fn build_app() -> Command {
@ -186,7 +188,7 @@ pub fn build_app() -> Command {
PossibleValuesParser::new(Target::iter().map(Into::<&'static str>::into));
Command::new("roc")
.version(concatcp!(VERSION, "\n"))
.version(VERSION)
.about("Run the given .roc file, if there are no compilation errors.\nYou can use one of the SUBCOMMANDS below to do something else!")
.args_conflicts_with_subcommands(true)
.subcommand(Command::new(CMD_BUILD)
@ -279,6 +281,20 @@ pub fn build_app() -> Command {
)
.subcommand(Command::new(CMD_REPL)
.about("Launch the interactive Read Eval Print Loop (REPL)")
.arg(
Arg::new(FLAG_NO_COLOR)
.long(FLAG_NO_COLOR)
.help("Do not use any ANSI color codes in the repl output")
.action(ArgAction::SetTrue)
.required(false)
)
.arg(
Arg::new(FLAG_NO_HEADER)
.long(FLAG_NO_HEADER)
.help("Do not print the repl header")
.action(ArgAction::SetTrue)
.required(false)
)
)
.subcommand(Command::new(CMD_RUN)
.about("Run a .roc file even if it has build errors")
@ -542,7 +558,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result<i32> {
arena,
path.to_path_buf(),
opt_main_path.cloned(),
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
load_config,
);
@ -1266,8 +1282,8 @@ fn roc_dev_native(
break if libc::WIFEXITED(status) {
libc::WEXITSTATUS(status)
} else {
// we don't have an exit code, so we probably shouldn't make one up
0
// we don't have an exit code, but something went wrong if we're in this else
1
};
}
ChildProcessMsg::Expect => {

View file

@ -5,9 +5,9 @@ use roc_build::program::{check_file, CodeGenBackend};
use roc_cli::{
build_app, format_files, format_src, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK,
CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL, CMD_RUN, CMD_TEST,
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN, FLAG_NO_LINK,
FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, FLAG_PP_PLATFORM, FLAG_STDIN, FLAG_STDOUT,
FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE,
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN, FLAG_NO_COLOR,
FLAG_NO_HEADER, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, FLAG_PP_PLATFORM,
FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE, VERSION,
};
use roc_docs::generate_docs_html;
use roc_error_macros::user_error;
@ -22,9 +22,6 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use target_lexicon::Triple;
#[macro_use]
extern crate const_format;
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
@ -51,7 +48,7 @@ fn main() -> io::Result<()> {
BuildConfig::BuildAndRunIfNoErrors,
Triple::host().into(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
LinkType::Executable,
)
} else {
@ -66,7 +63,7 @@ fn main() -> io::Result<()> {
BuildConfig::BuildAndRun,
Triple::host().into(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
LinkType::Executable,
)
} else {
@ -92,7 +89,7 @@ fn main() -> io::Result<()> {
BuildConfig::BuildAndRunIfNoErrors,
Triple::host().into(),
None,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
LinkType::Executable,
)
} else {
@ -190,7 +187,7 @@ fn main() -> io::Result<()> {
BuildConfig::BuildOnly,
target,
out_path,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
link_type,
)?)
}
@ -213,7 +210,7 @@ fn main() -> io::Result<()> {
roc_file_path.to_owned(),
opt_main_path.cloned(),
emit_timings,
RocCacheDir::Persistent(cache::roc_cache_dir().as_path()),
RocCacheDir::Persistent(cache::roc_cache_packages_dir().as_path()),
threading,
) {
Ok((problems, total_time)) => {
@ -231,7 +228,12 @@ fn main() -> io::Result<()> {
}
}
}
Some((CMD_REPL, _)) => Ok(roc_repl_cli::main()),
Some((CMD_REPL, matches)) => {
let has_color = !matches.get_one::<bool>(FLAG_NO_COLOR).unwrap();
let has_header = !matches.get_one::<bool>(FLAG_NO_HEADER).unwrap();
Ok(roc_repl_cli::main(has_color, has_header))
}
Some((CMD_DOCS, matches)) => {
let root_path = matches.get_one::<PathBuf>(ROC_FILE).unwrap();
let out_dir = matches.get_one::<OsString>(FLAG_OUTPUT).unwrap();
@ -347,11 +349,7 @@ fn main() -> io::Result<()> {
Ok(format_exit_code)
}
Some((CMD_VERSION, _)) => {
print!(
"{}",
concatcp!("roc ", include_str!("../../../version.txt"))
);
println!("roc {}", VERSION);
Ok(0)
}
_ => unreachable!(),