diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 177f9783cf..0f1c5a8ccb 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -15,11 +15,12 @@ test = false bench = false [features] -default = ["target-x86", "llvm"] +default = ["target-x86", "llvm", "editor"] # This is a separate feature because when we generate docs on Netlify, # it doesn't have LLVM installed. (Also, it doesn't need to do code gen.) llvm = ["inkwell", "roc_gen", "roc_build/llvm"] +editor = ["roc_editor"] target-x86 = [] @@ -53,7 +54,7 @@ roc_gen = { path = "../compiler/gen", optional = true } roc_build = { path = "../compiler/build", default-features = false } roc_fmt = { path = "../compiler/fmt" } roc_reporting = { path = "../compiler/reporting" } -roc_editor = { path = "../editor" } +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 clap = { git = "https://github.com/rtfeldman/clap", branch = "master" } const_format = "0.2.8" diff --git a/cli/src/main.rs b/cli/src/main.rs index bd38a5e56a..80acc15ada 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -19,7 +19,7 @@ fn main() -> io::Result<()> { let exit_code = match matches.subcommand_name() { None => { - roc_editor::launch(&[])?; + launch_editor(&[])?; // rustc couldn't infer the error type here Result::::Ok(0) @@ -52,14 +52,14 @@ fn main() -> io::Result<()> { .values_of_os(DIRECTORY_OR_FILES) { None => { - roc_editor::launch(&[])?; + launch_editor(&[])?; } Some(values) => { let paths = values .map(|os_str| Path::new(os_str)) .collect::>(); - roc_editor::launch(&paths)?; + launch_editor(&paths)?; } } @@ -86,3 +86,13 @@ fn main() -> io::Result<()> { std::process::exit(exit_code); } + +#[cfg(feature = "editor")] +fn launch_editor(filepaths: &[&Path]) -> io::Result<()> { + roc_editor::launch(filepaths) +} + +#[cfg(not(feature = "editor"))] +fn launch_editor(_filepaths: &[&Path]) -> io::Result<()> { + panic!("Cannot launch the editor because this build of roc did not include `feature = \"editor\"`!"); +}