Stream: beginners

Topic: building a zig platform


view this post on Zulip removewingman (Aug 18 2026 at 21:25):

Hello,
I am trying to get a simple zig platform running, to understand how platforms work and then develop one.

cat hello-world.roc

app [main!] {
        pf: platform "./platform/main.roc",
}

import pf.Stdout

main! = |_args| {
        Stdout.line!("Hello, World!")?
        Ok({})
}
rw ~/media/repos/roc/restricted main roc hello-world.roc
[255]

Any ideas on what I could do to fix this: https://codeberg.org/removewingman/restricted-roc

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:03):

I have a template you can use or copy from https://github.com/lukewilliamboswell/roc-platform-template-zig

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:05):

Did you build the zig host files first? are they in your platform/targets/x64musl/ directory along with the C runtime files .. roc will expect these files from your header x64musl: { inputs: ["crt1.o", "libhost.a", app, "libc.a"] },

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:07):

You should have no problem building the host with zig 0.17.0 ... I think you may need to patch the glue generated roc_host_abi.zig though

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:08):

It definitely seems like a Roc bug that we aren't giving a better error here... but maybe this is linking and running ok and the problem is in the platform (I haven't gone digging)

view this post on Zulip removewingman (Aug 18 2026 at 22:26):

Yes, I used your template and tried to remove as much as possible and get it to work with latest zig and roc to understand it.

I did use latest glue roc glue ZigGlue.roc ./src/ ./platform/main.roc (regenerated it: TryType8)

Host files are there:

platform/targets tree
.
├── x64musl
│   ├── crt1.o
│   ├── libc.a
│   └── libhost.a
└── x64v1musl
    ├── crt1.o
    ├── libc.a
    └── libhost.a

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:29):

Does roc build hello-world.roc give you anything different?

view this post on Zulip removewingman (Aug 18 2026 at 22:30):

Builds Successfull, when running the error comes, hmm maybe in the zig code or something, idk.

roc build hello-world.roc
0 errors and 0 warnings found in 188ms while successfully building:

    hello-world
rw ~/media/repos/roc/restricted main ./hello-world
[255]

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:32):

maybe add some debug prints in your host around the call into Roc

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:32):

like just before roc_main and just after

// here
const exit_code = roc_main(args_list);
// here

view this post on Zulip removewingman (Aug 18 2026 at 22:35):

I will try and report back, thanks.

view this post on Zulip removewingman (Aug 18 2026 at 22:50):

The program does what it is supposed to do, but after it the host returns from roc with exit code -1.
So the error is somewhere between here

extern fn roc_main(args: abi.RocList(abi.RocStr)) callconv(.c) i32;

and here

import Stdout
import Host

main_for_host! : List(Str) => I32
main_for_host! = |args| {
    result = main!(args)
    match result {
        Ok({}) => 0
        Err(Exit(code)) => code
        Err(_) => -1
    }
}

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:54):

I would suggest a debugger like gdb could help ... it looks like maybe a bug in the machine code that Roc is generating but hard to say where.

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:56):

You're on a fairly vanilla linux x64 machine? it seems strange that we have this bug

view this post on Zulip Luke Boswell (Aug 18 2026 at 22:56):

Have you tried other backends like --opt=interpreter or --opt=dev?

view this post on Zulip removewingman (Aug 18 2026 at 23:00):

Could be me aswell, idk. Yes: `Linux 6.18.44-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2026-08-10 07:14:17 x86_64 GNU/Linux

view this post on Zulip removewingman (Aug 18 2026 at 23:00):

Luke Boswell said:

Have you tried other backends like --opt=interpreter or --opt=dev?

Yes, got same error. But as I said could be me aswell, need to try things out.

view this post on Zulip Luke Boswell (Aug 18 2026 at 23:00):

Oh Alpine... maybe there is something library wise that is going one, like the C runtime files or libc.a that need modification

view this post on Zulip Luke Boswell (Aug 18 2026 at 23:01):

My guess is that it is something in crt1.o or libc.a

view this post on Zulip Luke Boswell (Aug 18 2026 at 23:02):

One thing you could try is to make a stub for the Roc part in zig and build that using zig build-lib and then manually link all the deps together zig build-exe crt1.o libc.a stub.a libhost.a and see if that works ... i.e. completely remove roc from the equation

view this post on Zulip removewingman (Aug 18 2026 at 23:15):

Works, when building native, which is something.

view this post on Zulip Luke Boswell (Aug 18 2026 at 23:18):

Sounds like you may have isolated the bug to Roc's codegen then

view this post on Zulip Luke Boswell (Aug 18 2026 at 23:19):

if you build with roc build --debug it will include debug info in the binary -- which helps when using a debugger

view this post on Zulip removewingman (Aug 19 2026 at 00:53):

Gonna go to sleep now, I got it at some point working, maybe it was just luck because of cached native build or something, but now it does not work anymore. I do not know what I am doing, so kind of hard to find out what to do.

view this post on Zulip removewingman (Aug 19 2026 at 11:58):

Cross compilation works when using, .debug, maybe they introduced some optimization in new zig version, so this works no more, idk. Can work with that tho.

view this post on Zulip Luke Boswell (Aug 19 2026 at 12:11):

Zig wont cross-compile the host?

view this post on Zulip removewingman (Aug 19 2026 at 12:48):

If I compile with optimization mode Debug everything works, but if I use anything else, it breaks.

view this post on Zulip removewingman (Aug 20 2026 at 01:33):

@Luke Boswell afaik, are you the person who knows much about platforms.
I want to have an idiomatic setup for my platform, can you give feedback/suggestions/anything is welcome, for the following construct:

Example using Platform
Restricted.roc
Host.roc
host.zig: hostedPledge function

If u think anything else is worth changing or have ideas, would love to hear them.

view this post on Zulip Luke Boswell (Aug 20 2026 at 01:37):

looks ok to me, nothing stands out as an issue or anything


Last updated: Sep 03 2026 at 15:16 UTC