Stream: platform development

Topic: basic webserver on go...


view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:00):

@Oskar Hahn had a really good point in the meetup today. Instead of building coroutines and a scheduler and async io manually in zig (fun project and still could be awesome long term), we should be able to make a basic webserver equivalent platform today in go. That would give most of the benefits and be much much easier to build.

I do think there are a number of things we could optimize better with a zig platform for basic webserver that deals with coroutines and etc, but just using go would probably be 80% of the gain for 10% the work.

So im the medium term a coroutine based synchronous API with async io under the hood should be possible to stand up in golang. Probably should use fast http over std http, but sounds like a great idea to enable more power.

On top of that assuming we can spawn gorountine from an effect, it would also enable more powerful parallelism and background processing if need.

Long term multithreaded data sharing would still be more complex, but that isn't generally needed for webservers. I may switch into focusing on that.

view this post on Zulip Richard Feldman (Nov 24 2024 at 02:06):

do you have the demo from earlier today pushed anywhere? I'm curious to take a look!

view this post on Zulip Luke Boswell (Nov 24 2024 at 02:18):

Not sure the status, but this is @Brendan Hansknecht impl https://github.com/bhansconnect/roc-coro-webserver

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:45):

Yeah, that is the current impl. Very adhoc currently.

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:46):

The core of coroutines, scheduling, and the event loop are set up reasonably, but not much is built on top yet

view this post on Zulip Richard Feldman (Nov 24 2024 at 02:53):

as in like other I/O operations and such?

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:57):

Yeah, and like robust http parsing, proper mapping to roc types, etc.

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:58):

Though the scheduler still has a solid amount of work to do if we want to make it nice

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:59):

Like it is a solid MVP, but would be a lot of work to make robust and a lot of it will include protocol level work that would just be complete with out languages/libraries. We only have slim os primitives to work with here

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 02:59):

Then of course, it is quite unstable and buggy currently.

view this post on Zulip Richard Feldman (Nov 24 2024 at 03:03):

cool, yeah I was wondering which parts are missing...I shouldn't let myself get sniped, but building those things out sounds like a lot of fun to me :big_smile:

view this post on Zulip Richard Feldman (Nov 24 2024 at 03:03):

but I gotta stay focused on lambda sets

view this post on Zulip Richard Feldman (Nov 24 2024 at 03:03):

we need an emoji for that...maybe :llama: (llambda sets)

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 03:24):

I totally agree that this could be a very fun project full of a lot of depth and learning, but just doing it in ho could be 80% the gain for way less work. That could be way more valuable to the community in the short term.

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 03:25):

Obviously building it out in zig means that even the web framework could be tailored to roc, so lots of potential perf optimizations

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 03:25):

I think this project still could be amazing and hugely valuable to roc, this is more a comment on what might be best to prioritize

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 03:26):

Then there is the side comment about stability and robustness. I think that it could be a long slog to get this platform robust

view this post on Zulip Richard Feldman (Nov 24 2024 at 04:20):

yeah that's fair, and it's separately cool to be like "hey here's a way to get Roc programs running from Go!"

view this post on Zulip Richard Feldman (Nov 24 2024 at 04:29):

:thinking: since Go compiles to static binaries, could a Go host Just Work with like roc run etc?

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 04:30):

I'm not sure, but I assume so. I assume @Luke Boswell or @Oskar Hahn know.

view this post on Zulip Luke Boswell (Nov 24 2024 at 04:35):

Yes, here's an example https://github.com/lukewilliamboswell/roc-platform-template-go

view this post on Zulip Luke Boswell (Nov 24 2024 at 04:36):

Needs a little love for purity inference and builtin Task I think

view this post on Zulip Luke Boswell (Nov 24 2024 at 04:39):

After this mornings meetup, I'm very interested in updating this. Just focussed on basic-cli...

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 04:40):

Does it work with the surgical linker?

view this post on Zulip Luke Boswell (Nov 24 2024 at 04:46):

I think we can make it. The current template doesn't, but I dont think it will be hard. At the time my platform knowledge was much less than now.

view this post on Zulip Luke Boswell (Nov 24 2024 at 04:47):

Why do you ask?

view this post on Zulip Brendan Hansknecht (Nov 24 2024 at 05:35):

Just curious if something about go makes it not work with the surgical linker

view this post on Zulip Luke Boswell (Nov 24 2024 at 07:00):

I think I'm stuck with basic-cli... I might tinker with go for a bit

view this post on Zulip Oskar Hahn (Nov 24 2024 at 07:13):

Yes, works with the surgical linker.

You can use the kingfisher platform as an example.

https://github.com/ostcar/kingfisher/tree/main/host

The main.go has to be different for the surgical linker and the legacy linker. This is why I created two main-files and used build tags to decide which one to use.

This is the build script, that creates all files for both linkers: https://github.com/ostcar/kingfisher/blob/main/build.roc

Also have a look at this PR: https://github.com/ostcar/kingfisher/pull/21

This has the most up to date version of a roc stdlib in go. It specifically has a working implementation of RocList.

view this post on Zulip Luke Boswell (Nov 24 2024 at 07:19):

I've just pushed an upgrade to purity inference for https://github.com/lukewilliamboswell/roc-platform-template-go/tree/main

view this post on Zulip Oskar Hahn (Nov 24 2024 at 07:22):

Also keep in mind, that you have to use zig as a cc compiler to cross compile cgo. But this only works with zig 0.11. here is the zig issues: https://github.com/ziglang/zig/issues/20689

view this post on Zulip Oskar Hahn (Nov 24 2024 at 07:29):

After my experience with the zig allocator, I would not use c malloc with go, but create a simple allocator in pure go. When the inline expect issue is solved, then you don't need libc, which makes linking even easier and you should get a static binary.

view this post on Zulip Luke Boswell (Nov 24 2024 at 07:36):

Nice, for the zig thing we can add a nix flake to help with that

view this post on Zulip Luke Boswell (Nov 24 2024 at 07:37):

How would you like to upgrade the template with the surgical linking things @Oskar Hahn?

view this post on Zulip Oskar Hahn (Nov 24 2024 at 07:44):

Yes, I can have a look. But I have children&friends :wink:. I will probably need some time.


Last updated: Jul 06 2025 at 12:14 UTC