Skip to content

Commit

Permalink
Update to latest Zig
Browse files Browse the repository at this point in the history
Tested on Zig 0.14.0-dev.367+a57479afc.
  • Loading branch information
mlugg committed Jul 19, 2024
1 parent 559dddc commit e7ef90d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
zig-cache/
.zig-cache/
zig-out/
49 changes: 21 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,24 +11,23 @@ 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,
)) |commit| {
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,
Expand All @@ -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);
Expand All @@ -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",
});
Expand All @@ -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);
}
20 changes: 14 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -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",
},
},
}
2 changes: 1 addition & 1 deletion src/gpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
Expand Down
5 changes: 2 additions & 3 deletions src/slimy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e7ef90d

Please sign in to comment.