diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 036d87bb..902986f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,7 +40,7 @@ jobs: - name: Build and run tests run: zig build test - name: Build examples - run: zig build examples + run: zig build -Dskipexamples=particle_life,intersection_2d examples build-macos: runs-on: macos-latest @@ -170,7 +170,7 @@ jobs: } write-mode: overwrite - name: Build examples - run: zig build -Dtarget=x86_64-windows-gnu examples + run: zig build -Dtarget=x86_64-windows-gnu -Dskipexamples=particle_life examples build-cross-linux: strategy: @@ -192,4 +192,4 @@ jobs: with: version: ${{ steps.zigversion.outputs.content }} - name: Build examples - run: zig build -Dtarget=${{matrix.target}} examples + run: zig build -Dtarget=${{matrix.target}} -Dskipexamples=particle_life examples diff --git a/build.zig b/build.zig index def71ece..b8309b5b 100644 --- a/build.zig +++ b/build.zig @@ -10,6 +10,17 @@ pub fn build(b: *Build) void { if (skip) return; } + // Get skipped examples' names + var skipexamples = std.StringHashMap(bool).init(b.allocator); + if (b.option( + []const u8, + "skipexamples", + "skip given examples when building all. e.g. \"particle_life,intersection_2d\"", + )) |s| { + var it = std.mem.splitScalar(u8, s, ','); + while (it.next()) |name| skipexamples.put(name, true) catch unreachable; + } + const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -25,7 +36,7 @@ pub fn build(b: *Build) void { .install_dir = .bin, .install_subdir = "assets", }); - const examples = [_]struct { name: []const u8, opt: BuildOptions, add_example: bool = true }{ + const examples = [_]struct { name: []const u8, opt: BuildOptions }{ .{ .name = "hello", .opt = .{ .dep_name = null } }, .{ .name = "imgui_demo", .opt = .{ .dep_name = null } }, .{ .name = "sprite_benchmark", .opt = .{ .dep_name = null } }, @@ -42,7 +53,7 @@ pub fn build(b: *Build) void { .{ .name = "solar_system", .opt = .{ .dep_name = null } }, .{ .name = "font_demo", .opt = .{ .dep_name = null } }, .{ .name = "skybox", .opt = .{ .dep_name = null } }, - .{ .name = "particle_life", .opt = .{ .dep_name = null, .use_nfd = true }, .add_example = false }, + .{ .name = "particle_life", .opt = .{ .dep_name = null, .use_nfd = true } }, .{ .name = "audio_demo", .opt = .{ .dep_name = null } }, .{ .name = "easing", .opt = .{ .dep_name = null } }, .{ .name = "svg", .opt = .{ .dep_name = null } }, @@ -79,7 +90,9 @@ pub fn build(b: *Build) void { "compile & run example " ++ demo.name, ); run_step.dependOn(&run_cmd.step); - if (demo.add_example) build_examples.dependOn(&install_cmd.step); + if (skipexamples.get(demo.name) == null) { + build_examples.dependOn(&install_cmd.step); + } } }