Pass cli arguments to main required by cli platform

This commit is contained in:
Ayaz Hafiz 2022-09-07 11:48:56 -05:00
parent 6e64bfc513
commit ec628ed5c6
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 15 additions and 12 deletions

View file

@ -20,7 +20,7 @@ use file_glue::WriteErr;
extern "C" {
#[link_name = "roc__mainForHost_1_exposed_generic"]
fn roc_main(output: *mut u8);
fn roc_main(output: *mut u8, args: RocList<RocStr>);
#[link_name = "roc__mainForHost_size"]
fn roc_main_size() -> i64;
@ -84,11 +84,14 @@ pub extern "C" fn rust_main() -> i32 {
let size = unsafe { roc_main_size() } as usize;
let layout = Layout::array::<u8>(size).unwrap();
// TODO: can we be more efficient about reusing the String's memory for RocStr?
let args: RocList<RocStr> = std::env::args().map(|s| RocStr::from(s.as_str())).collect();
unsafe {
// TODO allocate on the stack if it's under a certain size
let buffer = std::alloc::alloc(layout);
roc_main(buffer);
roc_main(buffer, args);
let result = call_the_closure(buffer);