#How to add two strings together at compile time zig

1 messages · Page 1 of 1 (latest)

soft topaz
#

I'm trying to use an environment variable and do not know how I can add another path on top of the environment variable in the build.zig

here's what I currently have:

    const vk_path = b.graph.env_map.get("VULKAN_SDK") orelse
        b.graph.env_map.get("VK_SDK_PATH") orelse
        std.debug.panic("Error getting VK_SDK_PATH or VULKAN_SDK environment variable!", .{});
    std.debug.print("{s}", .{vk_path});

    const mod = b.addModule("root", .{
        .root_source_file = b.path("src/root.zig"),
        .target = target,
    });

    const vulkan = b.dependency("vulkan_zig", .{
        .registry = b.pathFromRoot(std.fmt.comptimePrint("{s}/share/vulkan/registry/vk.xml", .{vk_path})),
    }).module("vulkan-zig");
static thorn
soft topaz
static thorn
#

also I think it's supposed to be a LazyPath. so actually you want std.Build.LazyPath{ .cwd_relative = b.fmt("{s}{s}", .{})

#

and in that case you can do (std.Build.LazyPath{ .cwd_relative = vk_root}).path("share/vulkan/registry/vk.xml") and don't need b.fmt at all

soft topaz
#

well I have another problem as well. now it doesn't want to read my actual environment variables which is a problem that I need to figure out.

soft topaz
static thorn
#

because b.dependency is switching on the type of the thing. and it has

[]const u8 => ...,
else => @compileError()
soft topaz
# static thorn and in that case you can do `(std.Build.LazyPath{ .cwd_relative = vk_root}).path...

that does not work. little confused on the error too

build.zig:19:68: error: member function expected 2 argument(s), found 1
        .registry = (std.Build.LazyPath{ .cwd_relative = vk_path }).path("share/vulkan/registry/vk.xml"),
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
C:\Users\\AppData\Roaming\Code\User\globalStorage\ziglang.vscode-zig\zig\x86_64-windows-0.15.0-dev.734+adc4418ba\lib\std\Build.zig:2585:9: note: function declared here
    pub fn path(lazy_path: LazyPath, b: *Build, sub_path: []const u8) LazyPath 
static thorn
#

should be .path(b, "share/...")

soft topaz
#

yeah figured that out

static thorn
#

it says expected 2 arguments even though there's 3 arguments because the first one is getting passed implicitly