summaryrefslogtreecommitdiff
path: root/src/sketch/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sketch/root.zig')
-rw-r--r--src/sketch/root.zig23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/sketch/root.zig b/src/sketch/root.zig
index bc09add..c70b326 100644
--- a/src/sketch/root.zig
+++ b/src/sketch/root.zig
@@ -300,15 +300,24 @@ pub const Console = struct {
}
};
+/// What the build knows of a sketch and passes to `sketch` and
+/// `exportSketch` (build.zig's generated roots fill it in).
+pub const Build = struct {
+ /// The repository revision the sketch was built from, "" when unknown.
+ source: []const u8 = "",
+ /// Record sessions to a file (`abi.Info.record`).
+ record: bool = false,
+};
+
/// The entry points of `App`, for a host that links it statically.
-pub fn sketch(comptime App: type) abi.Sketch {
- const G = Glue(App);
+pub fn sketch(comptime App: type, comptime made: Build) abi.Sketch {
+ const G = Glue(App, made);
return .{ .info = G.info, .defaults = G.defaults, .init = G.init, .setup = G.setup, .update = G.update, .draw = G.draw, .command = G.command };
}
/// Exports `App` under `abi.Sketch.symbols`, for a hot-reloaded library.
-pub fn exportSketch(comptime App: type) void {
- const G = Glue(App);
+pub fn exportSketch(comptime App: type, comptime made: Build) void {
+ const G = Glue(App, made);
const names = abi.Sketch.symbols;
@export(&G.info, .{ .name = names.info });
@export(&G.defaults, .{ .name = names.defaults });
@@ -320,7 +329,7 @@ pub fn exportSketch(comptime App: type) void {
@export(&G.build, .{ .name = "sketch_build" });
}
-pub fn Glue(comptime App: type) type {
+pub fn Glue(comptime App: type, comptime made: Build) type {
return struct {
pub const State = if (@hasDecl(App, "State")) App.State else struct {};
pub const Session = if (@hasDecl(App, "Session")) App.Session else struct {};
@@ -337,6 +346,8 @@ pub fn Glue(comptime App: type) type {
.session = abi.layout.of(Session, .session),
.store = abi.layout.of(Store, .store),
.commands = if (@hasDecl(App, "commands")) &App.commands else &.{},
+ .source = made.source ++ " " ++ abi.build,
+ .record = made.record,
};
/// What a call can offer, by type.
@@ -471,7 +482,7 @@ test "setup receives session resources without a Frame and reports errors" {
ctx.session_root = std.mem.asBytes(&session);
ctx.session = std.testing.allocator;
ctx.store = std.testing.allocator;
- const app = sketch(App);
+ const app = sketch(App, .{});
try std.testing.expect(!app.setup(&ctx));
defer std.testing.allocator.free(session.bytes);
try std.testing.expectEqualStrings("ready", session.bytes);