Stream: beginners

Topic: Zig and runtime deps


view this post on Zulip Luke Boswell (Apr 25 2023 at 08:07):

For #4992 the issue is that find_zig_str_path is looking for the str.zig file.

It first tries the the lib path relative to the executable location, and then looks in crates/compiler/builtins/bitcode/src/str.zig. However if I have a Zig platform and am using roc cli from somewhere else then I am not sure how to provide this zig file. Where should the lib directory be located in this instance?

I.e. I want to run % roc build --target wasm32 examples/echo.roc without having to manually copy and paste the *.zig builtins into the platform or app repository I am working in.

This is the related comment in crates/utils/command/src/lib.rs
// get the path of the lib folder
// runtime dependencies like zig files, Windows dylib builds, are put in the lib folder

view this post on Zulip Luke Boswell (Apr 25 2023 at 08:59):

If I add the following to find_zig_str_path() -> PathBuf then I can use zig platforms outside of the roc repository. However I need to copy most of the .zig files from crates/compiler/builtins/bitcode across to ./platform/*.zig. This seems a bit hacky, how should this work?

// Check 'platform/' folder
    let zig_ztr_platform_path = PathBuf::from("./platform/str.zig");
    if std::path::Path::exists(&zig_ztr_platform_path) {
        return zig_ztr_platform_path;
    }

view this post on Zulip Anton (Apr 25 2023 at 09:20):

We've tried to resolve this issue before, I think @Brendan Hansknecht knows the most about this.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 13:18):

At some point we removed the lib folder that lives next to the roc binary. That is where it should go for portability. So ./roc and ./lib/str.zig.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 13:19):

That said, really this is just s hack and should go away completely. We are basically injecting a dependency into all zig apps.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 13:20):

This should be replaced by glue generating a similar file for zig apps that need it.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 13:51):

Also, i thought we set it up currently such that roc would search relative to its current directory for crates/compiler/builtins/bitcode/str.zig. so where you put the roc binary, just also copy that specific folder. I think nightly does the same.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 14:18):

So turns out, we only check for the lib folder relative to the roc executable and not the crates/compiler/builtins/bitcode/ folder.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 14:19):

Let me push another small hack to keep this functioning.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 14:41):

#5328 should fix this.

view this post on Zulip Brendan Hansknecht (Apr 25 2023 at 21:20):

Ok, a second part to this to enable import things besides the string library, like list and dec: #5332


Last updated: Jul 06 2025 at 12:14 UTC