Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUILD][ZIG]: remove raygui from build options and re add addRaygui as a function #4485

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

kimierik
Copy link
Contributor

  • Removed raygui option from build.zig since it is not working as intended
  • Re add addRaygui function

Function addRaygui is not the idiomatic way of including dependencies in zig, but currently using the raygui flag would give the following error. This would happen because the build system is looking for the raygui dependancy in from raylibs own build.zig.zon file.

thread 27788 panic: no dependency named 'raygui' in '/home/kimi/.cache/zig/p/1220eb09ded36376449dc82f259286d0ad17440081117e36bb41604504a0c0ac19c3/build.zig.zon'. All packages used in build.zig must be declared in this file

Having the addRaygui function saves the user from adding non intuitive code into their own build.zig file.

The following is required for adding raygui to a project as a dependancy (Assuming raylib and raygui are defined dependencies in build.zig.zon)

const std = @import("std");
const rl = @import("raylib");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "example",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const raylib_dep = b.dependency("raylib", .{});
    const raylib = raylib_dep.artifact("raylib");
    rl.addRaygui(b, raylib, b.dependency("raygui", .{}));

    exe.linkLibrary(raylib);
    b.installArtifact(exe);
}

@raysan5 raysan5 merged commit 7053970 into raysan5:master Nov 13, 2024
@raysan5
Copy link
Owner

raysan5 commented Nov 13, 2024

@kimierik thanks for the review. Please note that I'm not testing build.zig changes and next raylib 5.5 is intended to be published in some days. If anything gets broken, it could be broken for many users.

psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Nov 18, 2024
@diwalkerdev
Copy link

diwalkerdev commented Nov 19, 2024

Sharing in case this is useful to anyone in the future. Probably user error, but I couldn't find anything else that I was doing wrong.

When using addRaygui, raygui.c fails to compile, as it cannot find raylib.h.

This seems to be the case for master fde3779, but it was also happening for a slightly older version of raylib before I updated to the latest master (I'm not sure of the hash number, but I remember seeing the min zig version supported was 0.12 in build.zig).

For my testing, I used the example build.zig provided by @kimierik in the first comment and a minimal raylib window example.

The solution was to add:

rl.addRaygui(b, raylib, b.dependency("raygui", .{}));
raylib.addIncludePath(raylib.getEmittedIncludeTree()); // <== Line to add

I doubt this is the most idiomatic way of solving this problem, but it seems to work. It seems that raylib is not aware of its own include path during compilation, and since raygui.h depends on raylib.h, the compilation fails.

Unrelated to raylib, but I also found that I needed to force zig to download the latest master, by breaking the hash number in the zon file. This causes zig to redownload of the zip file. I then needed to fix the hash once zig complained the hash number was wrong. This is possibly the expected behaviour, but was not what I expected, as I thought it would track the latest master.

@kimierik
Copy link
Contributor Author

kimierik commented Nov 19, 2024

I doubt this is the most idiomatic way of solving this problem, but it seems to work. It seems that raylib is not aware of its own include path during compilation, and since raygui.h depends on raylib.h, the compilation fails.

This was an oversight on my part and as far as i know this only happens in windows builds. I have tried to fix this in #4489.

EDIT 1:

Unrelated to raylib, but I also found that I needed to force zig to download the latest master, by breaking the hash number in the zon file. This causes zig to redownload of the zip file. I then needed to fix the hash once zig complained the hash number was wrong. This is possibly the expected behaviour, but was not what I expected, as I thought it would track the latest master.

This is intended behavior on zig's part. If you do not want the build to break whenever the master is updated you must choose a commit or a tag to fetch from. This can be done with having the url field in build.zig.zon as "https://github.com/raysan5/raylib/archive/{commit}.zip". (exhange {commit} with whatever commit hash you want) alternatively you can use .tar.gz instead of .zip if you want to.

as far as i know there is no way of tracking latest versions from a repo without the hash breaking, that would be a big security issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants