Hello,
I am trying to get a simple zig platform running, to understand how platforms work and then develop one.
0.17.0-dev.1786+75044cb04 (also tried with 0.16.0 got same error)nightly-2026-08-18-e9be50acat 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
I have a template you can use or copy from https://github.com/lukewilliamboswell/roc-platform-template-zig
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"] },
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
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)
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
Does roc build hello-world.roc give you anything different?
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]
maybe add some debug prints in your host around the call into Roc
like just before roc_main and just after
// here
const exit_code = roc_main(args_list);
// here
I will try and report back, thanks.
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
}
}
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.
You're on a fairly vanilla linux x64 machine? it seems strange that we have this bug
Have you tried other backends like --opt=interpreter or --opt=dev?
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
Luke Boswell said:
Have you tried other backends like
--opt=interpreteror--opt=dev?
Yes, got same error. But as I said could be me aswell, need to try things out.
Oh Alpine... maybe there is something library wise that is going one, like the C runtime files or libc.a that need modification
My guess is that it is something in crt1.o or libc.a
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
Works, when building native, which is something.
Sounds like you may have isolated the bug to Roc's codegen then
if you build with roc build --debug it will include debug info in the binary -- which helps when using a debugger
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.
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.
Zig wont cross-compile the host?
If I compile with optimization mode Debug everything works, but if I use anything else, it breaks.
@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.
looks ok to me, nothing stands out as an issue or anything
Last updated: Sep 03 2026 at 15:16 UTC