I'd like to kill the platform-switching example. I don't think we should try and keep it, or move it to the roc-lang/examples repo. I think it has served it's purpose well, but now we have matured beyond this example, and it's only causing issues for us now.
I think it was helpful to show how we could have multiple platforms, all with the same API and different hosts written in different languages under the hood. We now have a number of different platforms which I think demonstrate this, for example all of my platform templates have the same Task based API with a single effect and show this same thing.
Maybe we can find a better way to surface these platform templates and make them more discoverable. At the moment they are just listed on roc-awesome and not that easy to find. I think we could highlight how they have the same API, but different hosts underneath. Maybe a platform-switching "guide" on the website would be helpful here?
The main issue I have with this specific example, is that it is problematic with the changes to remove host rebuilding from roc and give that responsibility to the platform. It's is also being used for cli tests, but effectively this is just to test the platform rebuilding functionality for each type of host (swift, rust, zig, c etc).
If we want to keep any of this functionality, we should instead move it into crates/cli/tests
with the other cli tests.
Hopefully though after the --build-host
PR lands we can instead be removing all the different host rebuilding from roc and we won't need to support that any longer. It would make sense to keep zig
as the sole host type just for internal tests, and still keep the platform from a URL tests to ensure we remain compatible with basic-cli/basic-webserver/basic-ssg.
I'd like to keep very simple implementations for a zig and rust platform in the repo itself for testing/development. the others can live elsewhere I think
I agree that we just don't need it anymore
I'm looking at the CI failures in https://github.com/roc-lang/roc/pull/6859
And we're in a position where I think platform switching is causing us grief. Specifically, because we're doing some crazy hacks in crates/compiler/build/src/link.rs
to have roc cli build the platform host.
I think I'd like to rip out platform switching. I have tried to keep it, but I don't think it's worth doing backflips for. I think it's also a really outdated example of how someone should write a platform for roc -- so potentially does more harm than good at this point.
I'm going to proceed to rip it out... and see if that helps this PR. I'll do it in one commit so it's easy to revert if we decide we really want to keep it.
I'm having another go at trying to keep it -- converting it to a legacy host and an actual crate in the workspace so we can build it using cargo build -p rust-platform
before trying to run tests.
I think I figured it out. I also learnt some neat no_std tricks for linking and getting rust to produce a static library. Hopefully this works on on our CI machines.
If you're still running into issues, then as agreed above, I think it's fine if you rip this out.
I'm taking the current tests failures in the CI to mean that your local fix isn't working in the CI
I was feeling positive... but it's not looking great so far :oh_no:
Positivity has gotten you thus far
It really is up to you, but I'd vote for ripping out at this point
Sunk cost, y'know
I like to use the platform switching rust example for investigating bugs with a minimal platform, is there something I can use instead? I also planned on using it to test the nightlies now that the hello world example is gone.
Yeah, so we want a minimal rust and zig platform in the repo for testing etc. The zig one is in the cli crate which we use for tests. I'd recommend we use that instead. Also I think this is the better location to store these so we dont confuse people who might expect a more complete example.
The minimal rust platform is more difficult to achieve I think. I think I'm pretty close with the platform switching rust on the branch rn, but had to spend time with the fam so didn't quite finish that effort.
Rust does things to stop prevent people from making bad choices... but sometimes it's really hard to workaround. Like getting rust to generate a static library that includes a main
symbol. Thing get interesting when they work one way, but then you go to run cargo another way and it yells at you. It's like workspaces aren't as feature complete or something.
We know how to do it using multiple crates ala basic-cli, but I was trying to go for the minimal thing.
Another option here that unblocks this PR... is to remove it from the cli tests, and use the zig platform for confirming the nightlies in CI. So basically leave it there and defer decision around removing/keeping for another PR but not blocking this any longer.
Hmm, I would guess it would be harder to make the rust platform-switching example work again in the future compared to now when the full picture is in your head
It's working, it's just not playing nicely with cargo workspace and CI.
So it's not working I guess... :upside_down:
Last updated: Jul 06 2025 at 12:14 UTC