Error linking Raylib via raylib-zig

Hello everyone,
this is my first post and it is a request for help.
I’m trying to use Raylib in my program, via raylib-zig, on zig 0.12.0-dev.3033+031f23117.
I already did this in the past, so I followed the now usual procedure: git cloned raylib-zig, patched raylib-zig’s build code to have it compile (breaking changes to type names and builder API), added raylib to build.zig.zon, added the relevant parts to my build.zig.
Unfortunately, I keep getting slapped in the face with the following error:

/home/zencypher/cache/zig/p/1220c28847ca8e8756734ae84355802b764c9d9cf4de057dbc6fc2b15c56e726f27b/src/build.zig:5:126: error: root struct of file 'Build' has no member named 'CompileStep'
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep {
                                                                                                                    ~~~~~~~~~^~~~~~~~~~~~
/home/zencypher/.config/Code/User/globalStorage/ziglang.vscode-zig/zig_install/lib/std/Build.zig:1:1: note: struct declared here
const std = @import("std.zig");
^~~~~

This looked like another misalignment in type names, but unfortunately this code seems to actually come out of nowhere!
It is not part or raylib-zig and apparently is not generated by it!
I’m baffled, where does the code come from? Is there a way to make it compile??

Thx

Hi @zencypher, welcome to the forum.

It imports non existing "std.zig" instead of "std".

1 Like

Thay is my local installation of Zig, I don’t think it is that code causing the issue.
It looks more like the problem is that a fantomatic addRaylib function is generated somewhere, but its parameters and return type do not exist in Zig 0.12.0-dev.3033+031f23117

Clearing the zig cache might work: rm -r /home/zencypher/cache/zig

Unfortunately it doesn’t work :frowning:
The file is still there at next build

The addRaylib function is part of raylib/src/build.zig at master · raysan5/raylib · GitHub the function is part of raylib and is used by some people to add raylib to their projects. (It seems Not-Nik/raylib-zig doesn’t use that function and instead writes its own function however it seems that code gets loaded and run together with the main build.zig causing the error message)

The problem is that Not-Nik/raylib-zig uses https://github.com/raysan5/raylib/archive/5.0.tar.gz if you download that and look into it, you can see that that uses std.Build.CompileStep in src/build.zig however you are trying to compile it with a version of zig that is too new where it needs to be updated to std.Build.Step.Compile.

You have 3 options:

  1. you downgrade to an older version of zig somewhere between your current version and the one specified in Not-Nik/raylib-zig’s readme:

    Bindings tested on raylib version 5.0 and Zig 0.11.0/0.12.0-dev.1849+bb0f7d55e

    (I don’t know the exact versions that work besides what the readme states, there could be other incompatibilities.)

  2. you update Not-Nik/raylib-zig build.zig.zon’s url+hash to point to a newer raylib commit and update Not-Nik/raylib-zig’s build.zig if necessary.

  3. Alternatively you could try using raylib directly without the bindings (that is what I am doing, one indirection less to worry about), here is an example project: Raylib example using the package manager

Either way let us know what you have tried and if it worked, or presented you with any other errors.

Personally I think 2. is probably your best choice if you are used to using the bindings and should be doable, the difficult thing is just getting used to the whole picking commits and what to do to update stuff.

1 Like

Thank you @Sze I went with 2., simply updating the Raylib dependency in my build.zig.zon to the latest commit.

On a side note, I actually didn’t know Raylib had a build.zig file. Do all dependencies need one to be successfully declared in the build.zig.zon? Sorry for going down the rabbit hole, but since we are here…

Also, how did you discover it was Raylib’s build.zig? I tried understanding where the file was coming from for quite some time, but I’m evidently still too inexperienced :smiley:

2 Likes

No, as far as I know dependencies can have a build.zig, but aren’t required to have one. You could have dependencies that are pure data, or aren’t even aware that they are being used with the zig package manager.

However raylib provides a build.zig and it is useful, in the sense that dependent libraries don’t need to know how to build raylib in detail. (However I haven’t tested webassembly yet, whether that actually works or would require patching)

I guess just because I have used the addRaylib function and I already had to tweak raylib’s build.zig a few times to adapt it to changes in zig’s build system (using -freference-trace might help), the nice thing is that now it seems, that there is a new enough raylib commit most of the time when I try to update (but maybe that is because I don’t update my zig version that often).

My experience is also still spotty when it comes to using the package manager, I haven’t used it a whole lot, but this is exactly what I have used it for, so I have already done the head scratching and wondering :thinking:, that over time de-mystifies it. :grin:

Glad it worked!

3 Likes

A post was split to a new topic: Using raygui with raylib