Stream: beginners

Topic: Platform from src debug


view this post on Zulip Luke Boswell (Jun 19 2023 at 22:00):

Is there a way to instruct roc cli to build a rust platform and use debug instead of release? I am trying to debug some things using dbg! macros and not sure how to do this when using roc dev myapp.roc which rebuilds the platform.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:02):

If you don't pass --optimize it should build a rust platform in debug mode.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:02):

As long as you have a local platform of course that is getting built from source

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:03):

So, packages { pf: "../src/main.roc" } should be building and running in debug then?

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:05):

hmm, I think there is something else going on here. Thanks @Brendan Hansknecht

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:05):

yeah, should be. You should see roc saying rebuilding host.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:06):

also, you should be able to delete target/release and it should still run without recompile. Cause it will use the rust debug build

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:07):

It looks like bdg is working. I think the issue is something about my "glue" types and passing values between Roc and rust

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:07):

dbg*

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:18):

@Brendan Hansknecht can you please have a look at this? Am I missing something obvious here? I feel like maybe I can't just pass a command_glue::Command straight into the roc_fx_commandStatus?

# Effect.roc
commandStatus : InternalCommand.Command -> Effect U8

# InternalCommand.roc
Command : {
    program : Str,
    args : List Str, # [arg0, arg1, arg2, arg3, ...]
    envs : List Str, # [key0, value0, key1, value1, key2, value2, ...]
}
// command_glue.rs
#[derive(Clone, Default, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, )]
#[repr(C)]
pub struct Command {
    pub args: roc_std::RocList<roc_std::RocStr>,
    pub envs: roc_std::RocList<roc_std::RocStr>,
    pub program: roc_std::RocStr,
}
# lib.rs
pub extern "C" fn roc_fx_commandStatus(cmd: &command_glue::Command) -> u8

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:21):

That looks like it should be correct to me

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:21):

I had it working fine just passing in a RocStr but recently changed it to the struct Command

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:22):

One guess, maybe it explicitly needs to be a pointer instead of &

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:22):

Does it work if you remove one of the fields?

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:24):

I've just pushed my WIP to #55

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:24):

I'll try removing all the fields except the RocStr

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:26):

Yeah, it works ok removing the args and envs fields from command_glue::Command

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:26):

My current guess is that is is related to #5544 and since the size is 72 bytes (which is over 64 bytes) it becomes a pointer.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:26):

So it should work with 2 fields, but fail with 3

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:27):

With 3 probably just need to change the input type to a pointer.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:27):

but maybe something more complex is needed

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:28):

Ok, thanks. It doesn't work with two or three fields.

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:28):

To change to a pointer, I need to use a Box type right?

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:31):

Hmm. breaks with 2. Maybe it is something else, not sure. Anyway, I would test with a *const command_glue::Command

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:32):

Works!! :tada:

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:33):

Thank you

view this post on Zulip Luke Boswell (Jun 19 2023 at 22:35):

Pushed to this commit in case anyone finds this thread in future and wants to know how to use Box as a workaround here.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:37):

Hmm. that isn't what I meant, but is a patch I guess. Pretty wasteful to just box for that. Though it is always a workaround to any glue issues.

My suggestion would not use box on the roc side at all. It would just use the pointer on the rust side.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:38):

Not saying my suggestion would work, but this api definitely should work without any box on the roc side.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 22:49):

Hmm. I just tested your code on my m1 mac and I think your original code works just fine. Like without any changes....hmm


Last updated: Jul 05 2025 at 12:14 UTC