From 957deba00c2e8d20d9e72e87b656a8c45e8a8bb7 Mon Sep 17 00:00:00 2001 From: Matt Knight Date: Thu, 16 May 2024 14:36:45 -0700 Subject: [PATCH] start showcase setup --- .github/workflows/build.yml | 4 + build.zig | 91 ++++-------------- build.zig.zon | 1 + showcase/carts/blobs/build.zig | 19 ++++ showcase/carts/blobs/build.zig.zon | 12 +++ .../carts/blobs/src}/blobs.zig | 0 .../carts/blobs/src}/colors.zig | 0 .../carts/blobs/src}/music.zig | 0 .../carts/blobs/src}/startlogo.zig | 0 .../carts}/zeroman/assets/door.png | Bin .../carts}/zeroman/assets/effects.png | Bin .../carts}/zeroman/assets/font.png | Bin .../carts}/zeroman/assets/gopher.png | Bin .../carts}/zeroman/assets/healthbar.png | Bin .../carts}/zeroman/assets/hurt.png | Bin .../carts}/zeroman/assets/needleman.png | Bin .../carts}/zeroman/assets/shot.png | Bin .../carts}/zeroman/assets/spike.png | Bin .../carts}/zeroman/assets/teleport.png | Bin .../carts}/zeroman/assets/title.png | Bin .../carts}/zeroman/assets/zero.png | Bin showcase/carts/zeroman/build.zig | 74 ++++++++++++++ showcase/carts/zeroman/build.zig.zon | 18 ++++ .../carts}/zeroman/build/convert_gfx.zig | 0 .../carts/zeroman/src}/Box.zig | 0 .../carts/zeroman/src}/Enemy.zig | 0 .../carts/zeroman/src}/Entity.zig | 0 .../carts/zeroman/src}/Player.zig | 0 .../carts/zeroman/src}/Renderer.zig | 0 .../carts/zeroman/src}/Room.zig | 0 .../carts/zeroman/src}/Stage.zig | 0 .../carts/zeroman/src}/Tile.zig | 0 .../carts/zeroman/src}/effects.zig | 0 .../carts/zeroman/src}/main.zig | 0 .../carts/zeroman/src}/stages/needleman.zig | 0 35 files changed, 147 insertions(+), 72 deletions(-) create mode 100644 showcase/carts/blobs/build.zig create mode 100644 showcase/carts/blobs/build.zig.zon rename {samples/blobs => showcase/carts/blobs/src}/blobs.zig (100%) rename {samples/blobs => showcase/carts/blobs/src}/colors.zig (100%) rename {samples/blobs => showcase/carts/blobs/src}/music.zig (100%) rename {samples/blobs => showcase/carts/blobs/src}/startlogo.zig (100%) rename {samples => showcase/carts}/zeroman/assets/door.png (100%) rename {samples => showcase/carts}/zeroman/assets/effects.png (100%) rename {samples => showcase/carts}/zeroman/assets/font.png (100%) rename {samples => showcase/carts}/zeroman/assets/gopher.png (100%) rename {samples => showcase/carts}/zeroman/assets/healthbar.png (100%) rename {samples => showcase/carts}/zeroman/assets/hurt.png (100%) rename {samples => showcase/carts}/zeroman/assets/needleman.png (100%) rename {samples => showcase/carts}/zeroman/assets/shot.png (100%) rename {samples => showcase/carts}/zeroman/assets/spike.png (100%) rename {samples => showcase/carts}/zeroman/assets/teleport.png (100%) rename {samples => showcase/carts}/zeroman/assets/title.png (100%) rename {samples => showcase/carts}/zeroman/assets/zero.png (100%) create mode 100644 showcase/carts/zeroman/build.zig create mode 100644 showcase/carts/zeroman/build.zig.zon rename {samples => showcase/carts}/zeroman/build/convert_gfx.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Box.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Enemy.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Entity.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Player.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Renderer.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Room.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Stage.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/Tile.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/effects.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/main.zig (100%) rename {samples/zeroman => showcase/carts/zeroman/src}/stages/needleman.zig (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09e485a..1fd773a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,3 +25,7 @@ jobs: - name: Build run: zig build + + - name: Build Showcase + working-directory: showcase + run: zig build diff --git a/build.zig b/build.zig index 2c36892..9ac67b6 100644 --- a/build.zig +++ b/build.zig @@ -32,11 +32,11 @@ pub fn build(b: *Build) void { const ws_dep = b.dependency("ws", .{}); const mime_dep = b.dependency("mime", .{}); - _ = b.addModule("cart-api", .{ .root_source_file = .{ .path = "src/cart/api.zig" } }); + _ = b.addModule("cart-api", .{ .root_source_file = b.path("src/cart/api.zig") }); const watch = b.addExecutable(.{ .name = "watch", - .root_source_file = .{ .path = "src/watch/main.zig" }, + .root_source_file = b.path("src/watch/main.zig"), .target = b.host, .optimize = optimize, }); @@ -52,34 +52,31 @@ pub fn build(b: *Build) void { .dest_dir = .disabled, }).step); + //const showcase_dep = b.dependency("showcase", .{ + // .optimize = optimize, + //}); + //b.getInstallStep().dependOn(showcase_dep.builder.getInstallStep()); + var dep: std.Build.Dependency = .{ .builder = b }; const feature_test_cart = add_cart(&dep, b, .{ .name = "feature_test", .optimize = optimize, - .root_source_file = .{ .path = "samples/feature_test.zig" }, + .root_source_file = b.path("samples/feature_test.zig"), }); feature_test_cart.install(b); const watch_run_step = feature_test_cart.install_with_watcher(&dep, b, .{}); - const zeroman_cart = add_cart(&dep, b, .{ - .name = "zeroman", - .optimize = optimize, - .root_source_file = .{ .path = "samples/zeroman/main.zig" }, - }); - add_zeroman_assets_step(b, zeroman_cart); - zeroman_cart.install(b); - - { - const cart = add_cart(&dep, b, .{ - .name = "blobs", - .optimize = .ReleaseSmall, - .root_source_file = .{ .path = "samples/blobs/blobs.zig" }, - }); - cart.install(b); - b.step("watch-blobs", "Watch/run blobs in the simulator").dependOn( - &cart.install_with_watcher(&dep, b, .{}).step, - ); - } + //{ + // const cart = add_cart(&dep, b, .{ + // .name = "blobs", + // .optimize = .ReleaseSmall, + // .root_source_file = .{ .path = "samples/blobs/blobs.zig" }, + // }); + // cart.install(b); + // b.step("watch-blobs", "Watch/run blobs in the simulator").dependOn( + // &cart.install_with_watcher(&dep, b, .{}).step, + // ); + //} const watch_step = b.step("watch", ""); watch_step.dependOn(&watch_run_step.step); @@ -261,53 +258,3 @@ pub fn install_cart(b: *Build, cart: *Cart) void { cart.mz.install_firmware(b, cart.fw, .{ .format = .elf }); cart.mz.install_firmware(b, cart.fw, .{ .format = .{ .uf2 = .SAMD51 } }); } - -fn add_zeroman_assets_step(b: *Build, cart: *Cart) void { - const convert = b.addExecutable(.{ - .name = "convert_gfx", - .root_source_file = b.path("samples/zeroman/build/convert_gfx.zig"), - .target = b.host, - .optimize = cart.options.optimize, - .link_libc = true, - }); - convert.root_module.addImport("zigimg", b.dependency("zigimg", .{}).module("zigimg")); - - const base_path = "samples/zeroman/assets/"; - const gen_gfx = b.addRunArtifact(convert); - inline for (zeroman_assets) |file| { - gen_gfx.addArg("-i"); - gen_gfx.addFileArg(b.path(base_path ++ file.path)); - gen_gfx.addArg(std.fmt.comptimePrint("{}", .{file.bits})); - gen_gfx.addArg(std.fmt.comptimePrint("{}", .{file.transparency})); - } - gen_gfx.addArg("-o"); - const gfx_zig = gen_gfx.addOutputFileArg("gfx.zig"); - - const gfx_mod = b.addModule("gfx", .{ - .root_source_file = gfx_zig, - .optimize = cart.options.optimize, - }); - var dep: std.Build.Dependency = .{ .builder = b }; - gfx_mod.addImport("cart-api", dep.module("cart-api")); - - cart.wasm.step.dependOn(&gen_gfx.step); - cart.wasm.root_module.addImport("gfx", gfx_mod); - cart.cart_lib.root_module.addImport("gfx", gfx_mod); -} - -const GfxAsset = struct { path: []const u8, bits: u4, transparency: bool }; - -const zeroman_assets = [_]GfxAsset{ - .{ .path = "door.png", .bits = 2, .transparency = false }, - .{ .path = "effects.png", .bits = 2, .transparency = true }, - .{ .path = "font.png", .bits = 2, .transparency = true }, - .{ .path = "gopher.png", .bits = 4, .transparency = true }, - .{ .path = "healthbar.png", .bits = 4, .transparency = true }, - .{ .path = "hurt.png", .bits = 1, .transparency = true }, - .{ .path = "needleman.png", .bits = 4, .transparency = false }, - .{ .path = "shot.png", .bits = 2, .transparency = true }, - .{ .path = "spike.png", .bits = 2, .transparency = true }, - .{ .path = "teleport.png", .bits = 2, .transparency = true }, - .{ .path = "title.png", .bits = 4, .transparency = false }, - .{ .path = "zero.png", .bits = 4, .transparency = true }, -}; diff --git a/build.zig.zon b/build.zig.zon index f6b3839..66209cd 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,6 +9,7 @@ }, .dependencies = .{ + //.showcase = .{ .path = "showcase" }, .@"microzig/build" = .{ .url = "https://downloads.microzig.tech/microzig-0.12.1/build-0.0.1.tar.gz", .hash = "122066a2dd8e6cfef346bc5cd6de8294fe9d53bde59b65b042750ee25537438df2ad", diff --git a/showcase/carts/blobs/build.zig b/showcase/carts/blobs/build.zig new file mode 100644 index 0000000..8d9c212 --- /dev/null +++ b/showcase/carts/blobs/build.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const sycl_badge = @import("sycl_badge"); + +pub const author_name = "Jonathan Marler"; +pub const author_handle = "marler"; +pub const cart_title = "blobs"; +pub const description = ": get Marler to give a description"; + +pub fn build(b: *std.Build) void { + const optimize = b.standardOptimizeOption(.{}); + const sycl_badge_dep = b.dependency("sycl_badge", .{}); + + const cart = sycl_badge.add_cart(sycl_badge_dep, b, .{ + .name = "blobs", + .optimize = optimize, + .root_source_file = b.path("src/blobs.zig"), + }); + cart.install(b); +} diff --git a/showcase/carts/blobs/build.zig.zon b/showcase/carts/blobs/build.zig.zon new file mode 100644 index 0000000..5bcdad4 --- /dev/null +++ b/showcase/carts/blobs/build.zig.zon @@ -0,0 +1,12 @@ +.{ + .name = "blobs", + .version = "0.0.0", + .dependencies = .{ + .sycl_badge = .{ .path = "../../.." }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/samples/blobs/blobs.zig b/showcase/carts/blobs/src/blobs.zig similarity index 100% rename from samples/blobs/blobs.zig rename to showcase/carts/blobs/src/blobs.zig diff --git a/samples/blobs/colors.zig b/showcase/carts/blobs/src/colors.zig similarity index 100% rename from samples/blobs/colors.zig rename to showcase/carts/blobs/src/colors.zig diff --git a/samples/blobs/music.zig b/showcase/carts/blobs/src/music.zig similarity index 100% rename from samples/blobs/music.zig rename to showcase/carts/blobs/src/music.zig diff --git a/samples/blobs/startlogo.zig b/showcase/carts/blobs/src/startlogo.zig similarity index 100% rename from samples/blobs/startlogo.zig rename to showcase/carts/blobs/src/startlogo.zig diff --git a/samples/zeroman/assets/door.png b/showcase/carts/zeroman/assets/door.png similarity index 100% rename from samples/zeroman/assets/door.png rename to showcase/carts/zeroman/assets/door.png diff --git a/samples/zeroman/assets/effects.png b/showcase/carts/zeroman/assets/effects.png similarity index 100% rename from samples/zeroman/assets/effects.png rename to showcase/carts/zeroman/assets/effects.png diff --git a/samples/zeroman/assets/font.png b/showcase/carts/zeroman/assets/font.png similarity index 100% rename from samples/zeroman/assets/font.png rename to showcase/carts/zeroman/assets/font.png diff --git a/samples/zeroman/assets/gopher.png b/showcase/carts/zeroman/assets/gopher.png similarity index 100% rename from samples/zeroman/assets/gopher.png rename to showcase/carts/zeroman/assets/gopher.png diff --git a/samples/zeroman/assets/healthbar.png b/showcase/carts/zeroman/assets/healthbar.png similarity index 100% rename from samples/zeroman/assets/healthbar.png rename to showcase/carts/zeroman/assets/healthbar.png diff --git a/samples/zeroman/assets/hurt.png b/showcase/carts/zeroman/assets/hurt.png similarity index 100% rename from samples/zeroman/assets/hurt.png rename to showcase/carts/zeroman/assets/hurt.png diff --git a/samples/zeroman/assets/needleman.png b/showcase/carts/zeroman/assets/needleman.png similarity index 100% rename from samples/zeroman/assets/needleman.png rename to showcase/carts/zeroman/assets/needleman.png diff --git a/samples/zeroman/assets/shot.png b/showcase/carts/zeroman/assets/shot.png similarity index 100% rename from samples/zeroman/assets/shot.png rename to showcase/carts/zeroman/assets/shot.png diff --git a/samples/zeroman/assets/spike.png b/showcase/carts/zeroman/assets/spike.png similarity index 100% rename from samples/zeroman/assets/spike.png rename to showcase/carts/zeroman/assets/spike.png diff --git a/samples/zeroman/assets/teleport.png b/showcase/carts/zeroman/assets/teleport.png similarity index 100% rename from samples/zeroman/assets/teleport.png rename to showcase/carts/zeroman/assets/teleport.png diff --git a/samples/zeroman/assets/title.png b/showcase/carts/zeroman/assets/title.png similarity index 100% rename from samples/zeroman/assets/title.png rename to showcase/carts/zeroman/assets/title.png diff --git a/samples/zeroman/assets/zero.png b/showcase/carts/zeroman/assets/zero.png similarity index 100% rename from samples/zeroman/assets/zero.png rename to showcase/carts/zeroman/assets/zero.png diff --git a/showcase/carts/zeroman/build.zig b/showcase/carts/zeroman/build.zig new file mode 100644 index 0000000..5c8a663 --- /dev/null +++ b/showcase/carts/zeroman/build.zig @@ -0,0 +1,74 @@ +const std = @import("std"); +const Build = std.Build; + +const sycl_badge = @import("sycl_badge"); + +pub const author_name = "Fabio Arnold"; +pub const author_handle = "CaptainHorst"; +pub const cart_title = "Zeroman"; +pub const description = ": get Fabio to give a description"; + +pub fn build(b: *Build) void { + const optimize = b.standardOptimizeOption(.{}); + const sycl_badge_dep = b.dependency("sycl_badge", .{}); + + const cart = sycl_badge.add_cart(sycl_badge_dep, b, .{ + .name = "zeroman", + .optimize = optimize, + .root_source_file = b.path("src/main.zig"), + }); + add_zeroman_assets_step(sycl_badge_dep, b, cart); + cart.install(b); +} + +fn add_zeroman_assets_step( + sycl_badge_dep: *Build.Dependency, + b: *Build, + cart: *sycl_badge.Cart, +) void { + const convert = b.addExecutable(.{ + .name = "convert_gfx", + .root_source_file = b.path("build/convert_gfx.zig"), + .target = b.host, + .optimize = cart.options.optimize, + .link_libc = true, + }); + convert.root_module.addImport("zigimg", b.dependency("zigimg", .{}).module("zigimg")); + + const gen_gfx = b.addRunArtifact(convert); + inline for (zeroman_assets) |file| { + gen_gfx.addArg("-i"); + gen_gfx.addFileArg(b.path(file.path)); + gen_gfx.addArg(std.fmt.comptimePrint("{}", .{file.bits})); + gen_gfx.addArg(std.fmt.comptimePrint("{}", .{file.transparency})); + } + gen_gfx.addArg("-o"); + const gfx_zig = gen_gfx.addOutputFileArg("gfx.zig"); + + const gfx_mod = b.addModule("gfx", .{ + .root_source_file = gfx_zig, + .optimize = cart.options.optimize, + }); + gfx_mod.addImport("cart-api", sycl_badge_dep.module("cart-api")); + + cart.wasm.step.dependOn(&gen_gfx.step); + cart.wasm.root_module.addImport("gfx", gfx_mod); + cart.cart_lib.root_module.addImport("gfx", gfx_mod); +} + +const GfxAsset = struct { path: []const u8, bits: u4, transparency: bool }; + +const zeroman_assets = [_]GfxAsset{ + .{ .path = "assets/door.png", .bits = 2, .transparency = false }, + .{ .path = "assets/effects.png", .bits = 2, .transparency = true }, + .{ .path = "assets/font.png", .bits = 2, .transparency = true }, + .{ .path = "assets/gopher.png", .bits = 4, .transparency = true }, + .{ .path = "assets/healthbar.png", .bits = 4, .transparency = true }, + .{ .path = "assets/hurt.png", .bits = 1, .transparency = true }, + .{ .path = "assets/needleman.png", .bits = 4, .transparency = false }, + .{ .path = "assets/shot.png", .bits = 2, .transparency = true }, + .{ .path = "assets/spike.png", .bits = 2, .transparency = true }, + .{ .path = "assets/teleport.png", .bits = 2, .transparency = true }, + .{ .path = "assets/title.png", .bits = 4, .transparency = false }, + .{ .path = "assets/zero.png", .bits = 4, .transparency = true }, +}; diff --git a/showcase/carts/zeroman/build.zig.zon b/showcase/carts/zeroman/build.zig.zon new file mode 100644 index 0000000..fb3cee8 --- /dev/null +++ b/showcase/carts/zeroman/build.zig.zon @@ -0,0 +1,18 @@ +.{ + .name = "zeroman", + .version = "0.0.0", + .dependencies = .{ + .sycl_badge = .{ .path = "../../.." }, + .zigimg = .{ + .url = "https://github.com/zigimg/zigimg/archive/637974e2d31dcdbc33f1e9cc8ffb2e46abd2e215.tar.gz", + .hash = "122012026c3a65ff1d4acba3b3fe80785f7cee9c6b4cdaff7ed0fbf23b0a6c803989", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + "build", + "assets", + }, +} diff --git a/samples/zeroman/build/convert_gfx.zig b/showcase/carts/zeroman/build/convert_gfx.zig similarity index 100% rename from samples/zeroman/build/convert_gfx.zig rename to showcase/carts/zeroman/build/convert_gfx.zig diff --git a/samples/zeroman/Box.zig b/showcase/carts/zeroman/src/Box.zig similarity index 100% rename from samples/zeroman/Box.zig rename to showcase/carts/zeroman/src/Box.zig diff --git a/samples/zeroman/Enemy.zig b/showcase/carts/zeroman/src/Enemy.zig similarity index 100% rename from samples/zeroman/Enemy.zig rename to showcase/carts/zeroman/src/Enemy.zig diff --git a/samples/zeroman/Entity.zig b/showcase/carts/zeroman/src/Entity.zig similarity index 100% rename from samples/zeroman/Entity.zig rename to showcase/carts/zeroman/src/Entity.zig diff --git a/samples/zeroman/Player.zig b/showcase/carts/zeroman/src/Player.zig similarity index 100% rename from samples/zeroman/Player.zig rename to showcase/carts/zeroman/src/Player.zig diff --git a/samples/zeroman/Renderer.zig b/showcase/carts/zeroman/src/Renderer.zig similarity index 100% rename from samples/zeroman/Renderer.zig rename to showcase/carts/zeroman/src/Renderer.zig diff --git a/samples/zeroman/Room.zig b/showcase/carts/zeroman/src/Room.zig similarity index 100% rename from samples/zeroman/Room.zig rename to showcase/carts/zeroman/src/Room.zig diff --git a/samples/zeroman/Stage.zig b/showcase/carts/zeroman/src/Stage.zig similarity index 100% rename from samples/zeroman/Stage.zig rename to showcase/carts/zeroman/src/Stage.zig diff --git a/samples/zeroman/Tile.zig b/showcase/carts/zeroman/src/Tile.zig similarity index 100% rename from samples/zeroman/Tile.zig rename to showcase/carts/zeroman/src/Tile.zig diff --git a/samples/zeroman/effects.zig b/showcase/carts/zeroman/src/effects.zig similarity index 100% rename from samples/zeroman/effects.zig rename to showcase/carts/zeroman/src/effects.zig diff --git a/samples/zeroman/main.zig b/showcase/carts/zeroman/src/main.zig similarity index 100% rename from samples/zeroman/main.zig rename to showcase/carts/zeroman/src/main.zig diff --git a/samples/zeroman/stages/needleman.zig b/showcase/carts/zeroman/src/stages/needleman.zig similarity index 100% rename from samples/zeroman/stages/needleman.zig rename to showcase/carts/zeroman/src/stages/needleman.zig