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

Can't build because "generator/vulkan/build_integration.zig" tries to call b.graph.cache.obtain() which doesn't exist #122

Closed
terraquad opened this issue Mar 8, 2024 · 3 comments

Comments

@terraquad
Copy link

terraquad commented Mar 8, 2024

I'm trying to set up a little game, but my build.zig fails:

$ zig build
/home/tq/.cache/zig/p/1220e6c4e31599c25cc7df2b300ee5ece3d89ddf0c566dbb5e4eb8d0d49e32ad5bb6/generator/vulkan/build_integration.zig:80:21: error: no field named 'graph' in struct 'Build'
        var man = b.graph.cache.obtain();
                    ^~~~~
/home/tq/.local/apps/zigup/zig/0.12.0-dev.2063+804cee3b9/files/lib/std/Build.zig:1:1: note: struct declared here
const std = @import("std.zig");
^~~~~
referenced by:
    create: /home/tq/.cache/zig/p/1220e6c4e31599c25cc7df2b300ee5ece3d89ddf0c566dbb5e4eb8d0d49e32ad5bb6/generator/vulkan/build_integration.zig:29:27
    build: /home/tq/.cache/zig/p/1220e6c4e31599c25cc7df2b300ee5ece3d89ddf0c566dbb5e4eb8d0d49e32ad5bb6/build.zig:50:31
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

My build.zig:

const std = @import("std");

pub const Frontend = enum {
    client,
    server,
};

pub const LibType = enum {
    static,
    shared,
};

pub fn build(b: *std.Build) void {
    // Options
    const opt_target = b.standardTargetOptions(.{});
    const opt_optimize = b.standardOptimizeOption(.{});
    const opt_frontend = b.option(Frontend, "frontend", "Whether to produce a client or server executbale") orelse Frontend.client;
    const opt_serverLibType = b.option(LibType, "server_lib_type", "Whether to build the server as a static or a shared library") orelse LibType.static;
    
    // Server library
    const thServer_args = .{
        .name = "thorium_server",
        .root_source_file = .{ .path = "src/server/root.zig" },
        .target = opt_target,
        .optimize = opt_optimize,
    };
    const thServer = switch (opt_serverLibType) {
        .static => b.addStaticLibrary(thServer_args),
        .shared => b.addSharedLibrary(thServer_args),
    };

    // Client/server executable
    const thClient = switch (opt_frontend) {
        .client => b.addExecutable(.{
            .name = "thorium_client",
            .root_source_file = .{ .path = "src/client/main.zig" },
            .target = opt_target,
            .optimize = opt_optimize,
        }),
        .server => b.addExecutable(.{
            .name = "thorium_server_cli",
            .root_source_file = .{ .path = "src/server/main.zig" },
            .target = opt_target,
            .optimize = opt_optimize,
        }),
    };
    b.installArtifact(thClient);

    // Dependencies for server (todo)
    // Dependencies for client
    thClient.linkLibrary(thServer);
    if (opt_frontend == Frontend.client) {
        // GLFW dependency
        const glfw_dep = b.dependency("mach_glfw", .{
            .target = opt_target,
            .optimize = opt_optimize,
        });
        thClient.root_module.addImport("mach-glfw", glfw_dep.module("mach-glfw"));
        // Vulkan dependency
        const vulkan_dep = b.dependency("vulkan_zig", .{
            .registry = @as([] const u8, "deps/Vulkan-Headers/registry/vk.xml"),
        });
        thClient.root_module.addImport("vulkan", vulkan_dep.module("vulkan-zig"));
    }
}

Maybe it's because I'm using zig version 0.12.0-dev.2063+804cee3b9 (2024.1.0-mach to be exact) and the API doesn't exist there yet, but I can't upgrade to master because I'm using mach-glfw.

@Snektron
Copy link
Owner

Snektron commented Mar 8, 2024

Yes, this was changed here: #118. I suggest to just use vulkan-zig from a commit before here, for now. Alternatively, we can check the compiler version and pick the new or the old code.

@Snektron
Copy link
Owner

Snektron commented Mar 9, 2024

This should be fixed with https://machengine.org/about/nominated-zig/#202430-mach

@terraquad
Copy link
Author

Alright, it works with 2024.3.0-mach. Thanks for the help :)

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

2 participants