diff --git a/.gitignore b/.gitignore index e73c965..3389c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -zig-cache/ +.zig-cache/ zig-out/ diff --git a/build.zig b/build.zig index 14cbe37..f7e4061 100644 --- a/build.zig +++ b/build.zig @@ -2,7 +2,7 @@ const std = @import("std"); const slimy_version = std.SemanticVersion.parse("0.1.0-dev") catch @panic("Parse error"); -pub fn build(b: *std.build.Builder) !void { +pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const singlethread = b.option(bool, "singlethread", "Build in single-threaded mode") orelse false; @@ -11,16 +11,15 @@ pub fn build(b: *std.build.Builder) !void { const timestamp = b.option(bool, "timestamp", "Include build timestamp in version information") orelse false; const glslc = b.option([]const u8, "glslc", "Specify the path to the glslc binary") orelse "glslc"; - const shaders = b.addSystemCommand(&.{ - glslc, "-o", "search.spv", "search.comp", - }); - shaders.cwd = b.build_root.join(b.allocator, &.{ "src", "shader" }) catch @panic("OOM"); + const shader_compile = b.addSystemCommand(&.{ glslc, "-o" }); + const shader_spv = shader_compile.addOutputFileArg("search.spv"); + shader_compile.addFileArg(b.path("src/shader/search.comp")); var version = slimy_version; if (version.pre != null) { // Find git commit hash var code: u8 = undefined; - if (b.execAllowFail( + if (b.runAllowFail( &.{ "git", "rev-parse", "--short", "HEAD" }, &code, .Inherit, @@ -28,7 +27,7 @@ pub fn build(b: *std.build.Builder) !void { version.build = std.mem.trimRight(u8, commit, "\n"); // Add -dirty if we have uncommitted changes - _ = b.execAllowFail( + _ = b.runAllowFail( &.{ "git", "diff-index", "--quiet", "HEAD" }, &code, .Inherit, @@ -47,27 +46,26 @@ pub fn build(b: *std.build.Builder) !void { consts.addOption(?i64, "timestamp", if (timestamp) std.time.timestamp() else null); const exe_name = if (suffix) - b.fmt("slimy-{}-{s}", .{ version, target.zigTriple(b.allocator) catch @panic("OOM") }) + b.fmt("slimy-{}-{s}", .{ version, target.query.zigTriple(b.allocator) catch @panic("OOM") }) else "slimy"; const exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, + .single_threaded = singlethread, + .strip = strip, + .linkage = .dynamic, }); - - exe.addModule("build_consts", consts.createModule()); - exe.addModule("optz", b.dependency("optz", .{}).module("optz")); - exe.addModule("cpuinfo", b.dependency("cpuinfo", .{}).module("cpuinfo")); - exe.addModule("zcompute", b.dependency("zcompute", .{}).module("zcompute")); + exe.root_module.addImport("build_consts", consts.createModule()); + exe.root_module.addImport("optz", b.dependency("optz", .{}).module("optz")); + exe.root_module.addImport("cpuinfo", b.dependency("cpuinfo", .{}).module("cpuinfo")); + exe.root_module.addImport("zcompute", b.dependency("zcompute", .{}).module("zcompute")); + exe.root_module.addImport("search_spv", b.createModule(.{ .root_source_file = shader_spv })); exe.linkLibC(); - exe.step.dependOn(&shaders.step); - exe.linkage = .dynamic; - exe.single_threaded = singlethread; - exe.strip = strip; b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); @@ -81,16 +79,16 @@ pub fn build(b: *std.build.Builder) !void { const wasm = b.addSharedLibrary(.{ .name = "slimy", - .root_source_file = .{ .path = "src/web.zig" }, - .target = try std.zig.CrossTarget.parse(.{ + .root_source_file = b.path("src/web.zig"), + .target = b.resolveTargetQuery(std.Build.parseTargetQuery(.{ .arch_os_abi = "wasm32-freestanding", - }), + }) catch unreachable), .optimize = optimize, + .single_threaded = true, }); - wasm.single_threaded = true; const web = b.addInstallDirectory(.{ - .source_dir = .{ .path = "web" }, + .source_dir = b.path("web"), .install_dir = .prefix, .install_subdir = "web", }); @@ -100,9 +98,4 @@ pub fn build(b: *std.build.Builder) !void { const web_step = b.step("web", "Build web UI"); web_step.dependOn(&web.step); - - const test_step = b.addTest(.{ - .root_source_file = .{ .path = "src/slimy.zig" }, - }); - b.step("test", "Run tests").dependOn(&test_step.step); } diff --git a/build.zig.zon b/build.zig.zon index e63397b..ba16217 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,18 +1,26 @@ .{ .name = "slimy", .version = "0.1.0-dev", + .paths = .{ + "LICENSE", + "README.md", + "build.zig", + "build.zig.zon", + "src", + "web", + }, .dependencies = .{ .optz = .{ - .url = "https://github.com/silversquirl/optz/archive/a57f38365d85a8c1151171a7e3a715ed285e2a9d.tar.gz", - .hash = "12200ddfa43ada90f0a56d8cd1664c91321001a30c1bbb5a6ac6d405161c4750d6d2", + .url = "https://github.com/silversquirl/optz/archive/63c1c02ecbbfe18fa898b5b86dbee0e5e30df099.tar.gz", + .hash = "12200ca26c64345c3fd64caf744205c05b48abe11353261252b562c7d721a451589f", }, .cpuinfo = .{ - .url = "https://github.com/silversquirl/cpuinfo-zig/archive/bf816de759cf02c95ee9d94e7e7ab3e373a7286f.tar.gz", - .hash = "1220e168bbe411e4a92ffb194a7cf353997e69af530ca9ed4b4411c178948b340995", + .url = "https://github.com/silversquirl/cpuinfo-zig/archive/7a7d5aea11addee3b81baa9195ef84593376d39a.tar.gz", + .hash = "122048b51d1cdd9dd16c93927a47e9ee3ed7756d1060d33442749ce332b176ef0604", }, .zcompute = .{ - .url = "https://github.com/silversquirl/zcompute/archive/60312ae55c6447a387462ab0212b7c163dfd50d3.tar.gz", - .hash = "12206a1edb5a051dbdbdd106bdc19ac3f1f1237de076e80fb7325d5a98a98f8df54b", + .url = "https://github.com/silversquirl/zcompute/archive/321f260b3170e1a66cf9abf29f4d0ae5115b2185.tar.gz", + .hash = "12202fe573ff7fd505d2e00dc1c8eaa2393efb6ae1806abed15254c311d473b9eff2", }, }, } diff --git a/src/gpu.zig b/src/gpu.zig index 72c43e8..762d35a 100644 --- a/src/gpu.zig +++ b/src/gpu.zig @@ -39,7 +39,7 @@ pub const Context = struct { return error.VulkanInit; }; - self.shad = Shader.initBytes(arena.allocator(), &self.ctx, @embedFile("shader/search.spv")) catch |err| { + self.shad = Shader.initBytes(arena.allocator(), &self.ctx, @embedFile("search_spv")) catch |err| { log.err("Shader init error: {s}", .{@errorName(err)}); return error.ShaderInit; }; diff --git a/src/main.zig b/src/main.zig index 5c9015a..9ee8b04 100644 --- a/src/main.zig +++ b/src/main.zig @@ -203,7 +203,7 @@ test "output context" { .progress = false, }); - var pipe = try std.os.pipe(); + const pipe = try std.os.pipe(); var readf = std.fs.File{ .handle = pipe[0] }; defer readf.close(); var writef = std.fs.File{ .handle = pipe[1] }; diff --git a/src/slimy.zig b/src/slimy.zig index dd5554f..1c71c6e 100644 --- a/src/slimy.zig +++ b/src/slimy.zig @@ -57,7 +57,6 @@ pub const Result = struct { }; test { - @import("std").testing.refAllDecls(@This()); - @import("std").testing.refAllDecls(cpu); - @import("std").testing.refAllDecls(gpu); + _ = cpu; + _ = gpu; }