mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Merge pull request #1532 from rtfeldman/roc-run-without-run
`roc run [FILE]` is now `roc [FILE]`
This commit is contained in:
commit
afcfe773b6
8 changed files with 68 additions and 29 deletions
|
@ -25,7 +25,7 @@ Run examples as follows:
|
||||||
1. Navigate to `/examples`
|
1. Navigate to `/examples`
|
||||||
2. Run with:
|
2. Run with:
|
||||||
```
|
```
|
||||||
cargo run run hello-world/Hello.roc
|
cargo run hello-world/Hello.roc
|
||||||
```
|
```
|
||||||
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
|
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
|
||||||
For NQueens, input 10 in the terminal and press enter.
|
For NQueens, input 10 in the terminal and press enter.
|
||||||
|
|
|
@ -57,7 +57,7 @@ roc_reporting = { path = "../compiler/reporting" }
|
||||||
roc_editor = { path = "../editor", optional = true }
|
roc_editor = { path = "../editor", optional = true }
|
||||||
# TODO switch to clap 3.0.0 once it's out. Tried adding clap = "~3.0.0-beta.1" and cargo wouldn't accept it
|
# TODO switch to clap 3.0.0 once it's out. Tried adding clap = "~3.0.0-beta.1" and cargo wouldn't accept it
|
||||||
clap = { git = "https://github.com/rtfeldman/clap", branch = "master" }
|
clap = { git = "https://github.com/rtfeldman/clap", branch = "master" }
|
||||||
const_format = "0.2.8"
|
const_format = "0.2"
|
||||||
rustyline = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" }
|
rustyline = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" }
|
||||||
rustyline-derive = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" }
|
rustyline-derive = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" }
|
||||||
im = "14" # im and im-rc should always have the same version!
|
im = "14" # im and im-rc should always have the same version!
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate const_format;
|
||||||
|
|
||||||
use build::{BuildOutcome, BuiltFile};
|
use build::{BuildOutcome, BuiltFile};
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use clap::{App, AppSettings, Arg, ArgMatches};
|
use clap::{App, AppSettings, Arg, ArgMatches};
|
||||||
|
@ -32,9 +35,10 @@ pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";
|
||||||
|
|
||||||
pub fn build_app<'a>() -> App<'a> {
|
pub fn build_app<'a>() -> App<'a> {
|
||||||
let app = App::new("roc")
|
let app = App::new("roc")
|
||||||
.version(crate_version!())
|
.version(concatcp!(crate_version!(), "\n"))
|
||||||
|
.about("Runs the given .roc file. Use one of the SUBCOMMANDS below to do something else!")
|
||||||
.subcommand(App::new(CMD_BUILD)
|
.subcommand(App::new(CMD_BUILD)
|
||||||
.about("Build a program")
|
.about("Build a binary from the given .roc file, but don't run it")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(ROC_FILE)
|
Arg::with_name(ROC_FILE)
|
||||||
.help("The .roc file to build")
|
.help("The .roc file to build")
|
||||||
|
@ -43,7 +47,7 @@ pub fn build_app<'a>() -> App<'a> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(FLAG_OPTIMIZE)
|
Arg::with_name(FLAG_OPTIMIZE)
|
||||||
.long(FLAG_OPTIMIZE)
|
.long(FLAG_OPTIMIZE)
|
||||||
.help("Optimize the compiled program to run faster. (Optimization takes time to complete.)")
|
.help("Optimize your compiled Roc program to run faster. (Optimization takes time to complete.)")
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -60,7 +64,7 @@ pub fn build_app<'a>() -> App<'a> {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.subcommand(App::new(CMD_RUN)
|
.subcommand(App::new(CMD_RUN)
|
||||||
.about("Build and run a program")
|
.about("DEPRECATED - now use `roc [FILE]` instead of `roc run [FILE]`")
|
||||||
.setting(AppSettings::TrailingVarArg)
|
.setting(AppSettings::TrailingVarArg)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(FLAG_OPTIMIZE)
|
Arg::with_name(FLAG_OPTIMIZE)
|
||||||
|
@ -76,7 +80,7 @@ pub fn build_app<'a>() -> App<'a> {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(ROC_FILE)
|
Arg::with_name(ROC_FILE)
|
||||||
.help("The .roc file of an app to build and run")
|
.help("The .roc file of an app to run")
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -98,6 +102,32 @@ pub fn build_app<'a>() -> App<'a> {
|
||||||
.help("The directory or files to build documentation for")
|
.help("The directory or files to build documentation for")
|
||||||
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
.setting(AppSettings::TrailingVarArg)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(FLAG_OPTIMIZE)
|
||||||
|
.long(FLAG_OPTIMIZE)
|
||||||
|
.help("Optimize the compiled program to run faster. (Optimization takes time to complete.)")
|
||||||
|
.requires(ROC_FILE)
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(FLAG_DEBUG)
|
||||||
|
.long(FLAG_DEBUG)
|
||||||
|
.help("Store LLVM debug information in the generated program")
|
||||||
|
.requires(ROC_FILE)
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(ROC_FILE)
|
||||||
|
.help("The .roc file of an app to build and run")
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(ARGS_FOR_APP)
|
||||||
|
.help("Arguments to pass into the app being run")
|
||||||
|
.requires(ROC_FILE)
|
||||||
|
.multiple(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
if cfg!(feature = "editor") {
|
if cfg!(feature = "editor") {
|
||||||
|
@ -215,7 +245,7 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io::
|
||||||
// Forward all the arguments after the .roc file argument
|
// Forward all the arguments after the .roc file argument
|
||||||
// to the new process. This way, you can do things like:
|
// to the new process. This way, you can do things like:
|
||||||
//
|
//
|
||||||
// roc run app.roc foo bar baz
|
// roc app.roc foo bar baz
|
||||||
//
|
//
|
||||||
// ...and have it so that app.roc will receive only `foo`,
|
// ...and have it so that app.roc will receive only `foo`,
|
||||||
// `bar`, and `baz` as its arguments.
|
// `bar`, and `baz` as its arguments.
|
||||||
|
@ -263,16 +293,16 @@ fn roc_run(cmd: &mut Command) -> io::Result<i32> {
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap_or_else(|err| panic!("Failed to run app after building it: {:?}", err))
|
.unwrap_or_else(|err| panic!("Failed to run app after building it: {:?}", err))
|
||||||
.wait()
|
.wait()
|
||||||
.expect("TODO gracefully handle block_on failing when roc run spawns a subprocess for the compiled app");
|
.expect("TODO gracefully handle block_on failing when `roc` spawns a subprocess for the compiled app");
|
||||||
|
|
||||||
// `roc run` exits with the same status code as the app it ran.
|
// `roc [FILE]` exits with the same status code as the app it ran.
|
||||||
//
|
//
|
||||||
// If you want to know whether there were compilation problems
|
// If you want to know whether there were compilation problems
|
||||||
// via status code, use either `roc build` or `roc check` instead!
|
// via status code, use either `roc build` or `roc check` instead!
|
||||||
match exit_status.code() {
|
match exit_status.code() {
|
||||||
Some(code) => Ok(code),
|
Some(code) => Ok(code),
|
||||||
None => {
|
None => {
|
||||||
todo!("TODO gracefully handle the roc run subprocess terminating with a signal.");
|
todo!("TODO gracefully handle the `roc [FILE]` subprocess terminating with a signal.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,24 @@ fn main() -> io::Result<()> {
|
||||||
let matches = build_app().get_matches();
|
let matches = build_app().get_matches();
|
||||||
|
|
||||||
let exit_code = match matches.subcommand_name() {
|
let exit_code = match matches.subcommand_name() {
|
||||||
|
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!
|
||||||
|
|
||||||
|
build(
|
||||||
|
&Triple::host(),
|
||||||
|
&matches,
|
||||||
|
BuildConfig::BuildAndRun { roc_file_arg_index },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
launch_editor(&[])?;
|
launch_editor(&[])?;
|
||||||
|
|
||||||
// rustc couldn't infer the error type here
|
Ok(0)
|
||||||
Result::<i32, io::Error>::Ok(0)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(CMD_BUILD) => Ok(build(
|
Some(CMD_BUILD) => Ok(build(
|
||||||
&Triple::host(),
|
&Triple::host(),
|
||||||
|
@ -32,14 +45,10 @@ fn main() -> io::Result<()> {
|
||||||
BuildConfig::BuildOnly,
|
BuildConfig::BuildOnly,
|
||||||
)?),
|
)?),
|
||||||
Some(CMD_RUN) => {
|
Some(CMD_RUN) => {
|
||||||
let subcmd_matches = matches.subcommand_matches(CMD_RUN).unwrap();
|
// TODO remove CMD_RUN altogether if it is currently September 2021 or later.
|
||||||
let roc_file_arg_index = subcmd_matches.index_of(ROC_FILE).unwrap() + 1; // Not sure why this +1 is necessary, but it is!
|
println!("`roc run` is deprecated! (You no longer need the `run` - just do `roc [FILE]` instead of `roc run [FILE]` like before.");
|
||||||
|
|
||||||
Ok(build(
|
Ok(1)
|
||||||
&Triple::host(),
|
|
||||||
subcmd_matches,
|
|
||||||
BuildConfig::BuildAndRun { roc_file_arg_index },
|
|
||||||
)?)
|
|
||||||
}
|
}
|
||||||
Some(CMD_REPL) => {
|
Some(CMD_REPL) => {
|
||||||
repl::main()?;
|
repl::main()?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ Run examples as follows:
|
||||||
1. Navigate to `/examples`
|
1. Navigate to `/examples`
|
||||||
2. Run with:
|
2. Run with:
|
||||||
```
|
```
|
||||||
cargo run run hello-world/Hello.roc
|
cargo run hello-world/Hello.roc
|
||||||
```
|
```
|
||||||
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
|
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
|
||||||
For NQueens, input 10 in the terminal and press enter.
|
For NQueens, input 10 in the terminal and press enter.
|
|
@ -3,13 +3,13 @@
|
||||||
To run, `cd` into this directory and run:
|
To run, `cd` into this directory and run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run run Hello.roc
|
$ cargo run Hello.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
To run in release mode instead, do:
|
To run in release mode instead, do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run --release run Hello.roc
|
$ cargo run --release Hello.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
To run, `cd` into this directory and run:
|
To run, `cd` into this directory and run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run run Hello.roc
|
$ cargo run Hello.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
To run in release mode instead, do:
|
To run in release mode instead, do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run --release run Hello.roc
|
$ cargo run --release Hello.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
To run:
|
To run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run run Quicksort.roc
|
$ cargo run Quicksort.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
To run in release mode instead, do:
|
To run in release mode instead, do:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo run --release run Quicksort.roc
|
$ cargo run --release Quicksort.roc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue