raylib.zig icon indicating copy to clipboard operation
raylib.zig copied to clipboard

Synced with raylib latest, and fixed build

Open ProIcons opened this issue 1 year ago • 8 comments

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 avatar Mar 31 '24 09:03 ProIcons

now it does

ProIcons avatar Mar 31 '24 10:03 ProIcons

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

thar0x29a avatar Apr 02 '24 14:04 thar0x29a

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, .{});

ProIcons avatar Apr 03 '24 08:04 ProIcons

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.

PabloReszczynski avatar Apr 12 '24 06:04 PabloReszczynski

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:

  • std.Target.Query -> std.Build.ResolvedTarget
  • b.resolveTargetQuery(target), -> target,

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).

chrisfls avatar Apr 15 '24 05:04 chrisfls

Tested with latest zig 0.12.0, working as expected

mbartelsm avatar May 07 '24 17:05 mbartelsm

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);

wizzymore avatar May 17 '24 17:05 wizzymore

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

  • Clone the fork
cd $YOUR_SRC_FOLDER
git submodule add [email protected]:ProIcons/raylib.zig.git raylib
git submodule update --init --recursive
  • zig init
  • Edit main.zig to:
const std = @import("std");
const raylib = @import("raylib");

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:

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);
}
  • zig build run
  • Profit.

I'm on Arch Linux, Zig 0.12.

ziontee113 avatar Jun 08 '24 21:06 ziontee113