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 compiler uses wrong paths for files #3834

Closed
4 tasks done
hardliner66 opened this issue Feb 25, 2024 · 1 comment
Closed
4 tasks done

[build] Zig compiler uses wrong paths for files #3834

hardliner66 opened this issue Feb 25, 2024 · 1 comment

Comments

@hardliner66
Copy link
Contributor

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

Today I worked the whole day on a game in zig + raylib, when suddenly the compiler complains about not finding one of the raylib headers. This was kinda confusing, because it already worked earlier. I tried restarting my environment and deleting and cloning my repository to make sure everything is clean, but it still has the same error.

I'm not 100% sure if the problem is related to raylib directly or if it's a bug in the zig compiler, but I thought I'd start here and find out.

The problem seems to be, that it want's the file /home/<user>/projects/zig/bug/thirdparty/raylib/src/rcore.c, but somehow adds the project path to the beginning again and now tries to search for /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rcore.c which obviously doesn't exist.

Environment

WSL2 on Windows 11

Issue Log

install
└─ install zig_game
   └─ zig build-exe zig_game Debug native
      └─ zig build-lib raylib Debug native 1 errors
error: unable to check cache: stat file '/home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rcore.c' failed: FileNotFound
error: the following command failed with 1 compilation errors:
/snap/zig/10680/zig build-lib -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rcore.c /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/utils.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/raudio.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rmodels.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rshapes.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rtext.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rtextures.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /home/<user>/projects/zig/bug/home/<user>/projects/zig/bug/thirdparty/raylib/src/rglfw.c -lGL -lX11 -ODebug -I /home/<user>/projects/zig/bug/thirdparty/raylib/src/external/glfw/include -I /usr/include -DPLATFORM_DESKTOP=1 -L /usr/lib -Mroot -lc --cache-dir /home/<user>/projects/zig/bug/zig-cache --global-cache-dir /home/<user>/.cache/zig --name raylib -static --listen=-
Build Summary: 1/5 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install zig_game transitive failure
   └─ zig build-exe zig_game Debug native transitive failure
      └─ zig build-lib raylib Debug native 1 errors
error: the following build command failed with exit code 1:
/home/<user>/projects/zig/bug/zig-cache/o/4fb50086aa92a2d65550f7adf4bffd10/build /snap/zig/10680/zig /home/<user>/projects/zig/bug /home/<user>/projects/zig/bug/zig-cache /home/<user>/.cache/zig --seed 0xdb252460 -Z4f53ef88298f910d

Code Example

I uploaded my reduced code here: https://github.com/hardliner66/bug

The main.zig is just the following:

const std = @import("std");
const rl = @cImport(@cInclude("raylib.h"));

const screen_width = 800;
const screen_height = 450;

pub fn main() anyerror!void {
    rl.InitWindow(screen_width, screen_height, "ZigGame");
    defer rl.CloseWindow();

    rl.SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!rl.WindowShouldClose()) {
        rl.BeginDrawing();
        defer rl.EndDrawing();

        rl.ClearBackground(rl.WHITE);
        rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY);
    }
}

and the build.zig is this:

const std = @import("std");
const raySdk = @import("thirdparty/raylib/src/build.zig");

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) !void {
    // Standard target options allows the person running `zig build` to choose
    // what target to build for. Here we do not override the defaults, which
    // means any target is allowed, and the default is native. Other options
    // for restricting supported target set are available.
    const target = b.standardTargetOptions(.{});

    // Standard optimization options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
    // set a preferred release mode, allowing the user to decide how to optimize.
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "zig_game",
        // In this case the main source file is merely a path, however, in more
        // complicated build scripts, this could be a generated file.
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    exe.subsystem = std.builtin.subsystem;

    // This declares intent for the executable to be installed into the
    // standard location when the user invokes the "install" step (the default
    // step when running `zig build`).
    b.installArtifact(exe);

    const raylib = try raySdk.addRaylib(b, target, optimize, .{});
    exe.addIncludePath(.{ .path = "thirdparty/raylib/src" });
    exe.linkLibrary(raylib);

    // This *creates* a Run step in the build graph, to be executed when another
    // step is evaluated that depends on it. The next line below will establish
    // such a dependency.
    const run_cmd = b.addRunArtifact(exe);

    // By making the run step depend on the install step, it will be run from the
    // installation directory rather than directly from within the cache directory.
    // This is not necessary, however, if the application depends on other installed
    // files, this ensures they will be present and in the expected location.
    run_cmd.step.dependOn(b.getInstallStep());

    // This allows the user to pass arguments to the application in the build
    // command itself, like this: `zig build run -- arg1 arg2 etc`
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    // This creates a build step. It will be visible in the `zig build --help` menu,
    // and can be selected like this: `zig build run`
    // This will evaluate the `run` step rather than the default, which is "install".
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    // Creates a step for unit testing. This only builds the test executable
    // but does not run it.
    const unit_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    const run_unit_tests = b.addRunArtifact(unit_tests);

    // Similar to creating the run step earlier, this exposes a `test` step to
    // the `zig build --help` menu, providing a way for the user to request
    // running the unit tests.
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_unit_tests.step);
}
@hardliner66 hardliner66 changed the title [build] Short description of the issue/bug/feature [build] Zig compiler uses wrong paths for files Feb 26, 2024
@hardliner66
Copy link
Contributor Author

Fixed with #3835

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

No branches or pull requests

1 participant