Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start showcase setup #58

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
93 changes: 93 additions & 0 deletions showcase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SYCL Badge Cart Showcase

Here is a number of carts people have made with the SYCL Badge.

## Contributing

If you'd like to share what you've made with the SYCL Badge you can PR your
project. This helps the project because we can test changes to the base badge
firmware against a large number of applications, and in the future we'd like to
generate a website from all this info. To add your project you're going to add
it as a Zig package:

1. Put your code under `carts/<my_cart_name>/`. Add `sycl_badge` as a path
dependency:

```zig
.{
.name = "blobs",
.version = "0.0.0",
.dependencies = .{
.sycl_badge = .{ .path = "../../.." },
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
```

2. Build your cart in the package `build.zig` and export some metadata
(`author_handle` is optional):

```zig
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);
}
```

2. Add it as a path dependency of `showcase` in `build.zig.zon`:

```zig
.{
.name = "sycl-badge/showcase",
.version = "0.0.0",
.dependencies = .{
.sycl_badge = .{
.path = "..",
},
//.zine = .{
// .path = "../../zine",
//},

// Carts go here
.zeroman = .{ .path = "carts/zeroman" },
.blobs = .{ .path = "carts/blobs" },
},
.paths = .{
"README.md",
"build.zig.zon",
"build.zig",
"carts",
},
}

```

3. Fill in the table of cart dependencies in `build.zig`:

```zig
const carts = .{
.{ "zeroman", @import("zeroman") },
.{ "blobs", @import("blobs") },
// Right here
};
```

33 changes: 33 additions & 0 deletions showcase/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const std = @import("std");
//const zine = @import("zine");

const root = @import("root");
// cart imports
const carts = .{
.{ "zeroman", @import("zeroman") },
.{ "blobs", @import("blobs") },
};

pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});

inline for (carts) |cart| {
const cart_name = cart[0];
const cart_import = cart[1];
_ = cart_import.author_name;
if (@hasDecl(cart_import, "author_handle"))
_ = cart_import.author_handle;
_ = cart_import.cart_title;
_ = cart_import.description;
const dep = b.dependency(cart_name, .{ .optimize = optimize });
b.getInstallStep().dependOn(dep.builder.getInstallStep());
}

//zine.addWebsite(b, .{
// .title = "SYCL Badge Showcase",
// .host_url = "https://sample.com",
// .layouts_dir_path = "layouts",
// .content_dir_path = "content",
// .static_dir_path = "static",
//}) catch unreachable;
}
22 changes: 22 additions & 0 deletions showcase/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.{
.name = "sycl-badge/showcase",
.version = "0.0.0",
.dependencies = .{
.sycl_badge = .{
.path = "..",
},
//.zine = .{
// .path = "../../zine",
//},

// Carts go here
.zeroman = .{ .path = "carts/zeroman" },
.blobs = .{ .path = "carts/blobs" },
},
.paths = .{
"README.md",
"build.zig.zon",
"build.zig",
"carts",
},
}
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.
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 },
};
Loading
Loading