do we have any examples of main : Str -> Task Str []
working?
I just tried main : Str -> Task Str []
and roc glue
generated:
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RocFunction_84 {
closure_data: roc_std::RocList<u8>,
}
impl RocFunction_84 {
pub fn force_thunk(mut self, arg0: ()) -> roc_std::RocStr {
extern "C" {
fn roc__mainForHost_3_caller(
arg0: *const (),
closure_data: *mut u8,
output: *mut roc_std::RocStr,
);
}
let mut output = std::mem::MaybeUninit::uninit();
let ptr = &mut self.closure_data as *mut _ as *mut u8;
unsafe { roc__mainForHost_3_caller(&arg0, ptr, output.as_mut_ptr()) };
// ownership of the closure is transferred back to roc
core::mem::forget(self.closure_data);
unsafe { output.assume_init() }
}
}
pub fn mainForHost(arg0: roc_std::RocStr) -> RocFunction_84 {
extern "C" {
fn roc__mainForHost_1_exposed_generic(_: *mut RocFunction_84, _: roc_std::RocStr);
}
let mut ret = std::mem::MaybeUninit::uninit();
unsafe { roc__mainForHost_1_exposed_generic(ret.as_mut_ptr(), arg0) };
unsafe { ret.assume_init() }
}
running it gave this output:
Undefined symbols for architecture arm64:
"_roc__mainForHost_3_caller", referenced from:
__ZN4host14RocFunction_8411force_thunk17hb922055437fe1593E in macos-arm64.o
ld: symbol(s) not found for architecture arm64
I tried changing mainForHost3
to mainForHost1
(like it usually is), and then the program segfaulted :sweat_smile:
hm, actually it might be more about main : Str -> Task
:thinking:
if I change basic-cli
to take a Str
, same thing
and basic-cli
already has main : Task {} I32
so it's evidently capable of sending data to the host by way of a Task
I have an idea for a truly heinous workaround for this, but we should definitely fix it :laughing:
Shouldn't roc__mainForHost_1_exposed_generic take the roc string as a pointer?
Also, probably best to look out the llvm ir of a small example and debug from what that generates
Here is an example with main : List U8 -> Task
using zig.
It takes the argument as a pointer
you really need to look at the LLVM IR here
Last updated: Jul 06 2025 at 12:14 UTC