change glue api to enable writing multiple files

This commit is contained in:
Brendan Hansknecht 2022-12-08 12:38:50 -08:00
parent 424931459d
commit 2f9e1ad539
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
5 changed files with 59 additions and 33 deletions

View file

@ -64,7 +64,7 @@ pub const FLAG_CHECK: &str = "check";
pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb";
pub const ROC_FILE: &str = "ROC_FILE";
pub const ROC_DIR: &str = "ROC_DIR";
pub const GLUE_FILE: &str = "GLUE_FILE";
pub const GLUE_DIR: &str = "GLUE_DIR";
pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES";
pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";
@ -285,8 +285,8 @@ pub fn build_app<'a>() -> Command<'a> {
.required(true)
)
.arg(
Arg::new(GLUE_FILE)
.help("The filename for the generated glue code\n(Currently, this must be a .rs file because only Rust glue generation is supported so far.)")
Arg::new(GLUE_DIR)
.help("The directory for the generated glue code.\nNote: The implementation can write to any file in the directory.")
.allow_invalid_utf8(true)
.required(true)
)

View file

@ -5,7 +5,7 @@ use roc_cli::{
build_app, format, test, BuildConfig, FormatMode, Target, CMD_BUILD, CMD_CHECK, CMD_DEV,
CMD_DOCS, CMD_EDIT, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST,
CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_LIB, FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME,
GLUE_FILE, ROC_FILE,
GLUE_DIR, ROC_FILE,
};
use roc_docs::generate_docs_html;
use roc_error_macros::user_error;
@ -88,12 +88,12 @@ fn main() -> io::Result<()> {
}
Some((CMD_GLUE, matches)) => {
let input_path = Path::new(matches.value_of_os(ROC_FILE).unwrap());
let output_path = Path::new(matches.value_of_os(GLUE_FILE).unwrap());
let output_path = Path::new(matches.value_of_os(GLUE_DIR).unwrap());
if Some("rs") == output_path.extension().and_then(OsStr::to_str) {
if !output_path.exists() || output_path.is_dir() {
roc_glue::generate(input_path, output_path)
} else {
eprintln!("Currently, `roc glue` only supports generating Rust glue files (with the .rs extension). In the future, the plan is to decouple `roc glue` from any particular output format, by having it accept a second .roc file which gets executed as a plugin to generate glue code for any desired language. However, this has not yet been implemented, and for now only .rs is supported.");
eprintln!("`roc glue` requries that the output is a directory. The individual implementations might generate multiple files.");
Ok(1)
}