Skip to content

Commit

Permalink
start showcase setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed May 16, 2024
1 parent c1e97d4 commit 957deba
Show file tree
Hide file tree
Showing 35 changed files with 147 additions and 72 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ jobs:

- name: Build
run: zig build

- name: Build Showcase
working-directory: showcase
run: zig build
91 changes: 19 additions & 72 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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);
Expand Down Expand Up @@ -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 },
};
1 change: 1 addition & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions showcase/carts/blobs/build.zig
Original file line number Diff line number Diff line change
@@ -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 = "<TODO>: 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);
}
12 changes: 12 additions & 0 deletions showcase/carts/blobs/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.{
.name = "blobs",
.version = "0.0.0",
.dependencies = .{
.sycl_badge = .{ .path = "../../.." },
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
74 changes: 74 additions & 0 deletions showcase/carts/zeroman/build.zig
Original file line number Diff line number Diff line change
@@ -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 = "<TODO>: 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 },
};
18 changes: 18 additions & 0 deletions showcase/carts/zeroman/build.zig.zon
Original file line number Diff line number Diff line change
@@ -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",
},
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 957deba

Please sign in to comment.