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

Synced with raylib latest, and fixed build #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ProIcons
Copy link

@ProIcons ProIcons commented Mar 31, 2024

It relies on: raysan5/raylib#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
Copy link
Author

now it does

@thar0x29a
Copy link

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

@ProIcons
Copy link
Author

ProIcons commented Apr 3, 2024

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
Copy link

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
Copy link

chrisfls commented Apr 15, 2024

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

@mbartelsm
Copy link

Tested with latest zig 0.12.0, working as expected

@wizzymore
Copy link

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
Copy link

ziontee113 commented Jun 8, 2024

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 git@github.com: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.

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.

Error building raylib
7 participants