adding option to disable example building
Some checks failed
Build / build (push) Failing after 1m29s
Test / build (push) Has been cancelled

This commit is contained in:
2026-01-21 21:41:56 +01:00
parent c175224a01
commit 8a08b96777
5 changed files with 56 additions and 48 deletions

View File

@@ -23,7 +23,7 @@ jobs:
node-version: 24 node-version: 24
- name: Building - name: Building
run: zig build run: zig build -Dno-example=true
- name: Generating docs - name: Generating docs
run: zig build docs run: zig build docs

View File

@@ -20,4 +20,8 @@ jobs:
- uses: mlugg/setup-zig@v2 - uses: mlugg/setup-zig@v2
- name: Test - name: Test
run: zig build test run: |
zig build test -Dno-example=true
zig build test -Dno-example=true --release=fast
zig build test -Dno-example=true --release=safe
zig build test -Dno-example=true --release=small

View File

@@ -13,6 +13,11 @@ pub fn build(b: *std.Build) void {
const pretty = b.dependency("pretty", .{ .target = target, .optimize = optimize }); const pretty = b.dependency("pretty", .{ .target = target, .optimize = optimize });
mod.addImport("pretty", pretty.module("pretty")); mod.addImport("pretty", pretty.module("pretty"));
var it = b.user_input_options.iterator();
while (it.next()) |entry| {
std.debug.print("{s} - {s} {any}", .{ entry.key_ptr.*, entry.value_ptr.name, entry.value_ptr.used });
}
const lib = b.addLibrary(.{ const lib = b.addLibrary(.{
.name = "spirv_interpreter", .name = "spirv_interpreter",
.root_module = mod, .root_module = mod,
@@ -23,52 +28,51 @@ pub fn build(b: *std.Build) void {
// Zig example setup // Zig example setup
const sdl3 = b.lazyDependency("sdl3", .{ const no_example = b.option(bool, "no-example", "skips example dependencies fetch") orelse false;
.target = target,
.optimize = optimize,
}) orelse return;
const example_exe = b.addExecutable(.{ if (!no_example) {
.name = "spirv_interpreter_example", const sdl3 = b.lazyDependency("sdl3", .{ .target = target, .optimize = optimize }) orelse return;
const example_exe = b.addExecutable(.{
.name = "spirv_interpreter_example",
.root_module = b.createModule(.{
.root_source_file = b.path("example/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "spv", .module = mod },
.{ .name = "sdl3", .module = sdl3.module("sdl3") },
//.{ .name = "pretty", .module = pretty.module("pretty") },
},
}),
});
const example_install = b.addInstallArtifact(example_exe, .{});
example_install.step.dependOn(&lib_install.step);
const run_example = b.addRunArtifact(example_exe);
run_example.step.dependOn(&example_install.step);
const run_example_step = b.step("example", "Run the example");
run_example_step.dependOn(&run_example.step);
const compile_shader_cmd = b.addSystemCommand(&[_][]const u8{ "nzslc", "example/shader.nzsl", "--compile=spv,spv-dis", "-o", "example" });
const compile_shader_step = b.step("example-shader", "Compiles example's shader (needs nzslc installed)");
compile_shader_step.dependOn(&compile_shader_cmd.step);
}
// Zig unit tests setup
const nzsl = b.lazyDependency("NZSL", .{ .target = target, .optimize = optimize }) orelse return;
const lib_tests = b.addTest(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path("example/main.zig"), .root_source_file = b.path("test/root.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.imports = &.{ .imports = &.{
.{ .name = "spv", .module = mod }, .{ .name = "spv", .module = mod },
.{ .name = "sdl3", .module = sdl3.module("sdl3") }, .{ .name = "nzsl", .module = nzsl.module("nzigsl") },
//.{ .name = "pretty", .module = pretty.module("pretty") },
}, },
}), }),
});
const example_install = b.addInstallArtifact(example_exe, .{});
example_install.step.dependOn(&lib_install.step);
const run_example = b.addRunArtifact(example_exe);
run_example.step.dependOn(&example_install.step);
const run_example_step = b.step("example", "Run the example");
run_example_step.dependOn(&run_example.step);
const compile_shader_cmd = b.addSystemCommand(&[_][]const u8{ "nzslc", "example/shader.nzsl", "--compile=spv,spv-dis", "-o", "example" });
const compile_shader_step = b.step("example-shader", "Compiles example's shader");
compile_shader_step.dependOn(&compile_shader_cmd.step);
// Zig unit tests setup
const nzsl = b.lazyDependency("NZSL", .{}) orelse return;
const test_mod = b.createModule(.{
.root_source_file = b.path("test/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "spv", .module = mod },
.{ .name = "nzsl", .module = nzsl.module("nzigsl") },
},
});
const lib_tests = b.addTest(.{
.root_module = test_mod,
.test_runner = .{ .path = b.path("test/test_runner.zig"), .mode = .simple }, .test_runner = .{ .path = b.path("test/test_runner.zig"), .mode = .simple },
}); });
const run_tests = b.addRunArtifact(lib_tests); const run_tests = b.addRunArtifact(lib_tests);

View File

@@ -12,8 +12,8 @@
.lazy = true, .lazy = true,
}, },
.sdl3 = .{ .sdl3 = .{
.url = "git+https://codeberg.org/7Games/zig-sdl3?ref=master#eefd1b86205ed4fbc5f5274b5ba34aa97798d693", .url = "git+https://codeberg.org/7Games/zig-sdl3?ref=v0.1.6#9c1842246c59f03f87ba59b160ca7e3d5e5ce972",
.hash = "sdl3-0.1.6-NmT1Q8kQJgCrbdH9Z3ZmLo5uJ1et3oxhfYazrNTtfsgv", .hash = "sdl3-0.1.6-NmT1Q5sQJgCzT6hLj7WOSrwxE0Qsef1wIkDopbOOFru0",
.lazy = true, .lazy = true,
}, },
}, },

View File

@@ -19,7 +19,7 @@ pub fn init(buffer: []const SpvWord) Self {
}; };
} }
pub fn nextOrNull(self: *Self) ?SpvWord { pub inline fn nextOrNull(self: *Self) ?SpvWord {
const word = self.peek() orelse return null; const word = self.peek() orelse return null;
self.index += 1; self.index += 1;
return word; return word;
@@ -33,15 +33,15 @@ pub inline fn next(self: *Self) RuntimeError!SpvWord {
return self.nextOrNull() orelse return RuntimeError.InvalidSpirV; return self.nextOrNull() orelse return RuntimeError.InvalidSpirV;
} }
pub fn nextAs(self: *Self, comptime E: type) RuntimeError!E { pub inline fn nextAs(self: *Self, comptime E: type) RuntimeError!E {
return self.nextAsOrNull(E) orelse return RuntimeError.InvalidSpirV; return self.nextAsOrNull(E) orelse return RuntimeError.InvalidSpirV;
} }
pub fn peek(self: *const Self) ?SpvWord { pub inline fn peek(self: *const Self) ?SpvWord {
return if (self.index >= self.buffer.len) null else self.buffer[self.index]; return if (self.index >= self.buffer.len) null else self.buffer[self.index];
} }
pub fn skip(self: *Self) bool { pub inline fn skip(self: *Self) bool {
if (self.index >= self.buffer.len) { if (self.index >= self.buffer.len) {
return false; return false;
} }
@@ -49,7 +49,7 @@ pub fn skip(self: *Self) bool {
return true; return true;
} }
pub fn skipN(self: *Self, count: usize) bool { pub inline fn skipN(self: *Self, count: usize) bool {
if (self.index >= self.buffer.len) { if (self.index >= self.buffer.len) {
return false; return false;
} }
@@ -57,7 +57,7 @@ pub fn skipN(self: *Self, count: usize) bool {
return true; return true;
} }
pub fn skipToEnd(self: *Self) void { pub inline fn skipToEnd(self: *Self) void {
self.index = self.buffer.len; self.index = self.buffer.len;
} }