Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
459 stars 101 forks source link

Unable to build on Macos with Zig 0.12.0 #98

Closed CeNiEi closed 1 month ago

CeNiEi commented 1 month ago

Here is my build.zig

const std = @import("std");

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

    const raylib_dep = b.dependency("raylib-zig", .{
        .target = target,
        .optimize = optimize,
    });

    const raylib = raylib_dep.module("raylib");

    const raylib_artifact = raylib_dep.artifact("raylib");

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

    exe.linkLibrary(raylib_artifact);
    exe.root_module.addImport("raylib", raylib);

    const run_cmd = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run Temp");
    run_step.dependOn(&run_cmd.step);

    b.installArtifact(exe);
}

and my build.zig.zon

.{
    .name = "Temp",
    .version = "0.0.1",
    .dependencies = .{
        .@"raylib-zig" = .{
            .url = "https://github.com/Not-Nik/raylib-zig/archive/devel.tar.gz",
            .hash = "1220eeefbbdd34a7ae0be29cfc522cf72618e228df84535c96907dc61249c6032adf",
        },
    },
    .paths = .{""},
}

I am getting the following error

install
└─ install Temp
   └─ zig build-exe Temp Debug native
      └─ WriteFile raylib.h failure
error: FileNotFound: /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/raygui.h
install
└─ install Temp
   └─ zig build-exe Temp Debug native
      └─ zig build-lib raylib Debug native 1 errors
/Users/tushar/Meditations/Temp/zig-cache/o/dae9437280ec5408995a766a2d9de39a/raygui.c:2:10: error: 'raygui.h' file not found
#include "raygui.h"
         ^~~~~~~~~~~
error: the following command failed with 1 compilation errors:
/Users/tushar/zig/zig-macos-aarch64-0.12.0/zig build-lib -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -ObjC -- /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rglfw.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rcore.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/utils.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/raudio.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rmodels.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rshapes.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rtext.c /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/rtextures.c -cflags -std=gnu99 -D_GNU_SOURCE -DGL_SILENCE_DEPRECATION=199309L -fno-sanitize=undefined -- /Users/tushar/Meditations/Temp/zig-cache/o/dae9437280ec5408995a766a2d9de39a/raygui.c -ODebug -I /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src/external/glfw/include -I /Users/tushar/.cache/zig/p/12205f45151f556dd41348acc8a93099f19d6a2e830978ace86733ce0bfe52978812/src -DPLATFORM_DESKTOP=1 -Mroot -framework Foundation -framework CoreServices -framework CoreGraphics -framework AppKit -framework IOKit -lc --cache-dir /Users/tushar/Meditations/Temp/zig-cache --global-cache-dir /Users/tushar/.cache/zig --name raylib -static --listen=-
Build Summary: 1/6 steps succeeded; 2 failed (disable with --summary none)
install transitive failure
└─ install Temp transitive failure
   └─ zig build-exe Temp Debug native transitive failure
      ├─ zig build-lib raylib Debug native 1 errors
      └─ WriteFile raylib.h failure
error: the following build command failed with exit code 1:
/Users/tushar/Meditations/Temp/zig-cache/o/87f0c4ce5aa61c5e3adce5c8231d1bef/build /Users/tushar/zig/zig-macos-aarch64-0.12.0/zig /Users/tushar/Meditations/Temp /Users/tushar/Meditations/Temp/zig-cache /Users/tushar/.cache/zig --seed 0xed1d4f74 -Zed8fdc715819bf4c
Not-Nik commented 1 month ago

This seemed to be a mix of ziglang/zig#16679 and wrong assumptions in the raylib build file, both of which are worked around now by putting the raygui build code into the raylib-zig build file

okvik commented 1 month ago

@Not-Nik Hi, I've encountered the same problem myself when trying to build with raygui. Sorry for not cross-reporting earlier my proposed diagnosis and a solution, which I believe is within raylib's own build: https://github.com/raysan5/raylib/pull/4027

okvik commented 1 month ago

Of course, the fix to build.zig.zon hash of raygui dependency from https://github.com/Not-Nik/raylib-zig/commit/533c31321a94e61f11edeba86a3a8fc4e90fd941 is a prerequisite.