I'm attempting to make a barebones platform to help me better understand the roc building and linking process. I used basic-cli as a starting point (removing all platform functions). I can think of two key differences that I'm trying to do different from basic-cli:
Link to the project: https://github.com/jared-cone/roctris2
I'm running build-app.sh
Here's the output:
jared@jared-laptop:~/Home/roctris2$ ./build-app.sh
0 errors and 0 warnings found in 183 ms
while successfully building:
platform/libapp.so
Compiling libc v0.2.155
Compiling backtrace v0.3.69
Compiling host v0.0.1 (/home/jared/Home/roctris2/platform/crates/host)
Finished `release` profile [optimized] target(s) in 2.21s
🔨 Rebuilding platform...
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
failed to open file "app/../platform/dynhost": No such file or directory (os error 2)
Location: crates/linker/src/lib.rs:552:29
and if I try the legacy linker:
jared@jared-laptop:~/Home/roctris2$ roc build --linker=legacy app/test.roc
🔨 Rebuilding platform...
ld: /usr/lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
thread 'main' panicked at crates/compiler/build/src/program.rs:1031:17:
not yet implemented: gracefully handle `ld` (or `zig` in the case of wasm with --optimize) returning exit code Some(1)
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: roc_build::program::build_loaded_file
3: roc_build::program::build_file
4: roc_cli::build
5: roc::main
so where did I mess up? :)
This is complicated to answer I think. Anton and I spent a lot of time finding the right incantation to get the rust compiler to play nicely.
I think if you remove the bin and just have a lib you will have a much nicer time getting this to work, but then you will be limited to the legacy linker (this may be ok for your purposes).
Yep I'm fine with legacy linker. Currently when I build it produces a bin and a lib. I don't know rust: is that lib the same that would be produced as a lib that's in its own crate?
I think the issues stem from the way we do linking currently and unique things with the rust compiler. I've seen it work this way though, if you checkout the examples/platform-switching/rust-platform
in the repo, there is an example. Though this uses a host.c
to do something intermediate.
Jared Cone said:
Yep I'm fine with legacy linker. Currently when I build it produces a bin and a lib. I don't know rust: is that lin the same that would be produced as a lib that's in its own crate?
If you're fine with just the legacy linker, it get's much easier.
Also, https://github.com/lukewilliamboswell/basic-ssg is another Rust platform that is much simpler and supports cross-compilation to build for all the supported roc targets.
Thanks Luke! We got it sorted using the legacy linker.
Jared Cone has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC