70
build.zig
70
build.zig
@@ -1,30 +1,25 @@
|
||||
const std = @import("std");
|
||||
const vkgen = @import("vulkan-zig");
|
||||
const glfw_util = @import("glfw");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const glfw_dep = b.dependency("glfw", .{});
|
||||
glfw_util.install(glfw_dep, b);
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const vk = b.dependency("vulkan-zig", .{
|
||||
.registry = @as([]const u8, b.pathFromRoot("reg/vk.xml")),
|
||||
});
|
||||
const vkmod = vk.module("vulkan-zig");
|
||||
|
||||
const cimgui = b.dependency("cimgui", .{});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "zig-glfw-vulkan",
|
||||
.name = "scratchzig",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe.root_module.addImport("vk", vk.module("vulkan-zig"));
|
||||
exe.root_module.addImport("cimgui", cimgui.module("cimgui"));
|
||||
glfw_util.link(glfw_dep, exe);
|
||||
b.installArtifact(exe);
|
||||
|
||||
const shaders = vkgen.ShaderCompileStep.create(
|
||||
b,
|
||||
@@ -35,6 +30,18 @@ pub fn build(b: *std.Build) void {
|
||||
shaders.add("triangle_frag", "src/shaders/triangle.frag", .{});
|
||||
exe.root_module.addImport("shaders", shaders.getModule());
|
||||
|
||||
// this requires PKG_CONFIG_PATH to be set. something like:
|
||||
// ~/.local/lib/pkgconfig/
|
||||
exe.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe.linkLibC();
|
||||
exe.root_module.addImport("vk", vkmod);
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
@@ -44,4 +51,51 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
const exe_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe_unit_tests.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe_unit_tests.linkLibC();
|
||||
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||
|
||||
const dsa_unit_tests = b.addTest(.{
|
||||
.name = "dsa.zig tests",
|
||||
.root_source_file = b.path("src/dsa.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const run_dsa_unit_tests = b.addRunArtifact(dsa_unit_tests);
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_exe_unit_tests.step);
|
||||
test_step.dependOn(&run_dsa_unit_tests.step);
|
||||
|
||||
const inspect = b.addExecutable(.{
|
||||
.name = "vkinspect",
|
||||
.root_source_file = b.path("src/inspect.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
inspect.linkSystemLibrary2("vulkan", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .dynamic,
|
||||
});
|
||||
inspect.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
exe_unit_tests.linkLibC();
|
||||
inspect.root_module.addImport("vk", vkmod);
|
||||
inspect.linkLibC();
|
||||
const run_inspect = b.addRunArtifact(inspect);
|
||||
const inspect_step = b.step("vki", "Vulkan Inspect");
|
||||
inspect_step.dependOn(&run_inspect.step);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
.{
|
||||
.name = "zig-glfw-vulkan",
|
||||
.name = "scratchzig",
|
||||
.version = "0.0.0",
|
||||
|
||||
.dependencies = .{
|
||||
@@ -7,11 +7,8 @@
|
||||
.url = "https://github.com/Snektron/vulkan-zig/archive/f2c2e0ff80374563357cc4fe72bf7d8a2c956824.tar.gz",
|
||||
.hash = "1220cf0972c6fe05437c1a8689b955084385eb7ca1f8c14010d49ca5a89570a5d90d",
|
||||
},
|
||||
.glfw = .{
|
||||
.path = "glfw",
|
||||
},
|
||||
.cimgui = .{
|
||||
.path = "cimgui",
|
||||
.path="cimgui",
|
||||
},
|
||||
},
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vkgen = @import("vulkan-zig");
|
||||
const glfw_util = @import("glfw");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
@@ -8,7 +7,6 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
const imgui_dep = b.dependency("imgui", .{});
|
||||
const cimgui_dep = b.dependency("cimgui", .{});
|
||||
const glfw_dep = b.dependency("glfw", .{});
|
||||
|
||||
const luajit = try b.findProgram(&.{"luajit"}, &.{});
|
||||
|
||||
@@ -76,7 +74,13 @@ pub fn build(b: *std.Build) !void {
|
||||
});
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui.h"), "cimgui.h");
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui_impl.h"), "cimgui_impl.h");
|
||||
glfw_util.link(glfw_dep, cimgui);
|
||||
|
||||
// todo separate impls into different shared libraries for easier linkage
|
||||
cimgui.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
|
||||
b.installArtifact(cimgui);
|
||||
|
||||
|
@@ -11,9 +11,6 @@
|
||||
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.8-docking.tar.gz",
|
||||
.hash = "122065151b97161e25abb71c9df2fd9fba42aaca8c33d689a480b883d82411c8fabe",
|
||||
},
|
||||
.glfw = .{
|
||||
.path = "../glfw",
|
||||
}
|
||||
},
|
||||
|
||||
.paths = .{
|
||||
|
@@ -1,82 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn link(dep: *std.Build.Dependency, compile: *std.Build.Step.Compile) void {
|
||||
compile.step.dependOn(dep.builder.getInstallStep());
|
||||
compile.linkLibC();
|
||||
compile.root_module.addLibraryPath(.{ .cwd_relative = dep.builder.getInstallPath(.lib, "") });
|
||||
compile.root_module.addIncludePath(.{ .cwd_relative = dep.builder.getInstallPath(.header, "") });
|
||||
compile.root_module.addRPathSpecial("$ORIGIN/../lib");
|
||||
|
||||
compile.root_module.linkSystemLibrary("glfw", .{});
|
||||
compile.root_module.linkSystemLibrary("rt", .{});
|
||||
compile.root_module.linkSystemLibrary("m", .{});
|
||||
compile.root_module.linkSystemLibrary("dl", .{});
|
||||
}
|
||||
|
||||
pub fn install(dep: *std.Build.Dependency, owner: *std.Build) void {
|
||||
const install_libs = owner.addInstallDirectory(.{
|
||||
.include_extensions = &.{ ".so", ".dll" },
|
||||
.install_subdir = "",
|
||||
.install_dir = .lib,
|
||||
.source_dir = .{
|
||||
.cwd_relative = dep.builder.getInstallPath(.lib, ""),
|
||||
},
|
||||
});
|
||||
install_libs.step.dependOn(dep.builder.getInstallStep());
|
||||
owner.getInstallStep().dependOn(&install_libs.step);
|
||||
}
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
// todo target into toolchain file
|
||||
// const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const cmake = b.findProgram(&.{"cmake"}, &.{}) catch @panic("missing cmake");
|
||||
|
||||
const cmake_build_type = switch (optimize) {
|
||||
.ReleaseFast => "Release",
|
||||
.ReleaseSafe => "RelWithDebInfo",
|
||||
.ReleaseSmall => "MinSizeRel",
|
||||
.Debug => "Debug",
|
||||
};
|
||||
|
||||
const config_step = b.addSystemCommand(&.{
|
||||
cmake,
|
||||
"-DBUILD_SHARED_LIBS=ON",
|
||||
b.fmt("-DCMAKE_BUILD_TYPE={s}", .{cmake_build_type}),
|
||||
b.fmt("-DCMAKE_INSTALL_PREFIX={s}", .{b.getInstallPath(.prefix, "")}),
|
||||
"-DGLFW_BUILD_DOCS=OFF",
|
||||
"-DGLFW_BUILD_EXAMPLES=OFF",
|
||||
"-DGLFW_BUILD_TESTS=OFF",
|
||||
"-DGLFW_BUILD_X11=ON", // todo arg
|
||||
"-DGLFW_BUILD_WAYLAND=OFF", // todo arg
|
||||
"-DGLFW_INSTALL=ON",
|
||||
});
|
||||
// config_step.setEnvironmentVariable("CC", b.fmt("{s} cc", .{b.graph.zig_exe}));
|
||||
// config_step.setEnvironmentVariable("CXX", b.fmt("{s} c++", .{b.graph.zig_exe}));
|
||||
config_step.addArg("-S");
|
||||
config_step.addDirectoryArg(b.dependency("glfw_real", .{}).path(""));
|
||||
config_step.addArg("-B");
|
||||
const build_dir = config_step.addOutputDirectoryArg("glfw_build");
|
||||
|
||||
_ = config_step.captureStdOut();
|
||||
config_step.has_side_effects = true;
|
||||
|
||||
const build_step = b.addSystemCommand(&.{cmake});
|
||||
build_step.step.dependOn(&config_step.step);
|
||||
build_step.addArg("--build");
|
||||
build_step.addDirectoryArg(build_dir);
|
||||
|
||||
_ = build_step.captureStdOut();
|
||||
build_step.has_side_effects = true;
|
||||
|
||||
const install_step = b.addSystemCommand(&.{cmake});
|
||||
install_step.step.dependOn(&build_step.step);
|
||||
install_step.addArg("--install");
|
||||
install_step.addDirectoryArg(build_dir);
|
||||
|
||||
_ = install_step.captureStdOut();
|
||||
install_step.has_side_effects = true;
|
||||
|
||||
b.getInstallStep().dependOn(&install_step.step);
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
.{
|
||||
.name = "glfw",
|
||||
.version = "3.4.0",
|
||||
.dependencies = .{
|
||||
.glfw_real = .{
|
||||
.url = "https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.zip",
|
||||
.hash = "1220625fa7ce79733c6889844cb02ea1f6e4b81b46a3fabacec181714879947f4abd",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user