How do you know what the exposed function signature will be for e.g. mainForHost : Str -> Str
? I have been having a hard time trying to make a very basic platform using zig than the platform switching example which is just mainForHost : Str
. Is there a way to generate the LLVM for example which might provide a clue as to the expected signature?
For reference I have been trying to get https://github.com/lukewilliamboswell/roc-serverless working.. but even without the wasm part I'm not confident I have the signature correct
Would it be possible fore something like roc glue
to generate this signature in future?
--debug
That will get you the llvm ir
I think I answered part of my question above. Build it using a debug version of the compiler and I get a .bc
file
And yeah, all of this can be generated by roc glue.
The roc webserver that Richard is working on in rust had these functions generated (though currently with a bug)
Also, debug should get you a .ll
file
'I could not find the debugir tool on the PATH
do you have to build that from source? Is there a distribution for macos?
You actually don't need it. The .ll
file should exist now.
This will help me investigate further
The glue from Richard's webserver generates identically to what I expect, two pointers return and argument of RocStr.
The llvm though gives, which looks like it takes a single pointer.
define void @roc__mainForHost_1_exposed_generic(ptr %0) {
entry:
%call = call fastcc {} @_mainForHost_f03bf86f79d121cbfd774dec4a65912e99f5f17c33852bbc45e81916e62b53b()
store {} %call, ptr %0, align 1
ret void
}
The issue I have is that zig is generating different wasm type signature from roc I think. How is this possible?
$ roc build --target=wasm32 examples/echo.roc
🔨 Rebuilding platform...
LLD Link... warning(link): unexpected LLD stderr:
wasm-ld: warning: function signature mismatch: roc__mainForHost_1_exposed_generic
>>> defined as (i32, i32) -> void in lto.tmp
>>> defined as (i32) -> void in /Users/luke/.cache/zig/o/21804a4778e09cb059cc1335d2b95b55/roc_appxhNgOx.o
0 errors and 0 warnings found in 420 ms while successfully building:
examples/echo.wasm
I suspect there is some kind of optimization going on maybe?
I figured it out!! :tada: I had to change the platform from mainForHost = main
to mainForHost = \str -> main str
and then it works. I have no idea why.
sorry, just saw this. it's because of lambda sets :upside_down:
I think there's an issue to make it so that's automatically suggested in these cases
Can we automatically just wrap/add that on the compiler side so users don't have to?
in theory, yes
Last updated: Jul 06 2025 at 12:14 UTC