ryupold / raylib.zig

Idiomatic Zig bindings for raylib utilizing raylib_parser
MIT License
222 stars 36 forks source link

Synced with raylib latest, and fixed build #41

Open ProIcons opened 7 months ago

ProIcons commented 7 months ago

It relies on: https://github.com/raysan5/raylib/pull/3891

Fixes: #40 #39 #37 It doesn't however fix the parsing, which in the end might cause crashes if raylib is changed significantly.

ProIcons commented 7 months ago

now it does

thar0x29a commented 7 months ago

are you sure that #40 is fixed with that? because it seems that I still get it

ProIcons commented 7 months ago

are you sure that #40 is fixed with that? because it seems that I still get it

just do:

raylib.addTo(b, exe, target.query, optimize, .{});
PabloReszczynski commented 6 months ago

are you sure that #40 is fixed with that? because it seems that I still get it

just do:

raylib.addTo(b, exe, target.query, optimize, .{});

I guess this PR should also change the README to avoid confusions then.

Btw, I keep seeing the same error as #40 even when using your fork, zig 0.11.0 and this particular snippet. Maybe I'm doing something wrong.

chrisfls commented 6 months ago

are you sure that #40 is fixed with that? because it seems that I still get it

just do:

raylib.addTo(b, exe, target.query, optimize, .{});

I guess this PR should also change the README to avoid confusions then.

Btw, I keep seeing the same error as #40 even when using your fork, zig 0.11.0 and this particular snippet. Maybe I'm doing something wrong.

Changing:

fixes it for me (I'm using latest zig)

It seems like even the official raylib repo is having to use some workarounds to deal with these API breakages (see the anytype there).

mbartelsm commented 6 months ago

Tested with latest zig 0.12.0, working as expected

wizzymore commented 5 months ago

Tried it and i still get:
file paths added with 'addCSourceFiles' must be relative.

// game/ext/raylib/raylib/src/build.zig:51
    addCSourceFilesVersioned(raylib, &.{
        srcdir ++ "/rcore.c",
        srcdir ++ "/utils.c",
    }, raylib_flags_arr.items);
ziontee113 commented 4 months ago

Thank you @ProIcons so much for the PR. I finally able to build with Zig 0.12! Here's my process:

pub fn main() !void { raylib.SetConfigFlags(raylib.ConfigFlags{ .FLAG_WINDOW_RESIZABLE = true }); raylib.InitWindow(800, 800, "hello world!"); raylib.SetTargetFPS(60);

defer raylib.CloseWindow();

while (!raylib.WindowShouldClose()) {
    raylib.BeginDrawing();
    defer raylib.EndDrawing();

    raylib.ClearBackground(raylib.BLACK);
    raylib.DrawFPS(10, 10);

    raylib.DrawText("hello world!", 100, 100, 20, raylib.YELLOW);
}

}

Edit `build.zig` to:
```zig
const raylib = @import("raylib/build.zig");
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const lib = b.addStaticLibrary(.{
        .name = "rayray",
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = optimize,
    });

    b.installArtifact(lib);

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

    raylib.addTo(b, exe, target.query, optimize, .{});

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const lib_unit_tests = b.addTest(.{
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

    const exe_unit_tests = b.addTest(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_lib_unit_tests.step);
    test_step.dependOn(&run_exe_unit_tests.step);
}

I'm on Arch Linux, Zig 0.12.