mach: improve compatibility with self-hosted compiler

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-20 12:02:01 -07:00
parent 1c43f0f1e8
commit 192de6946e
2 changed files with 15 additions and 23 deletions

View file

@ -8,39 +8,24 @@ pub fn checkApplication(comptime app_pkg: type) void {
if (@hasDecl(App, "init")) {
const InitFn = @TypeOf(@field(App, "init"));
if (@import("builtin").zig_backend == .stage1) {
if (InitFn != fn (app: *App, core: *Core) @typeInfo(@typeInfo(InitFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn init(app: *App, core: *mach.Core) !void' found '" ++ @typeName(InitFn) ++ "'");
} else {
if (InitFn != *const fn (app: *App, core: *Core) @typeInfo(@typeInfo(InitFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn init(app: *App, core: *mach.Core) !void' found '" ++ @typeName(InitFn) ++ "'");
}
if (InitFn != fn (app: *App, core: *Core) @typeInfo(@typeInfo(InitFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn init(app: *App, core: *mach.Core) !void' found '" ++ @typeName(InitFn) ++ "'");
} else {
@compileError("App must export 'pub fn init(app: *App, core: *mach.Core) !void'");
}
if (@hasDecl(App, "update")) {
const UpdateFn = @TypeOf(@field(App, "update"));
if (@import("builtin").zig_backend == .stage1) {
if (UpdateFn != fn (app: *App, core: *Core) @typeInfo(@typeInfo(UpdateFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn update(app: *App, core: *mach.Core) !void' found '" ++ @typeName(UpdateFn) ++ "'");
} else {
if (UpdateFn != *const fn (app: *App, core: *Core) @typeInfo(@typeInfo(UpdateFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn update(app: *App, core: *mach.Core) !void' found '" ++ @typeName(UpdateFn) ++ "'");
}
if (UpdateFn != fn (app: *App, core: *Core) @typeInfo(@typeInfo(UpdateFn).Fn.return_type.?).ErrorUnion.error_set!void)
@compileError("expected 'pub fn update(app: *App, core: *mach.Core) !void' found '" ++ @typeName(UpdateFn) ++ "'");
} else {
@compileError("App must export 'pub fn update(app: *App, core: *mach.Core) !void'");
}
if (@hasDecl(App, "deinit")) {
const DeinitFn = @TypeOf(@field(App, "deinit"));
if (@import("builtin").zig_backend == .stage1) {
if (DeinitFn != fn (app: *App, core: *Core) void)
@compileError("expected 'pub fn deinit(app: *App, core: *mach.Core) void' found '" ++ @typeName(DeinitFn) ++ "'");
} else {
if (DeinitFn != *const fn (app: *App, core: *Core) void)
@compileError("expected 'pub fn deinit(app: *App, core: *mach.Core) void' found '" ++ @typeName(DeinitFn) ++ "'");
}
if (DeinitFn != fn (app: *App, core: *Core) void)
@compileError("expected 'pub fn deinit(app: *App, core: *mach.Core) void' found '" ++ @typeName(DeinitFn) ++ "'");
} else {
@compileError("App must export 'pub fn deinit(app: *App, core: *mach.Core) void'");
}

View file

@ -341,8 +341,8 @@ pub const Platform = struct {
try platform.window.setSize(.{ .width = options.width, .height = options.height });
try platform.window.setTitle(options.title);
try platform.window.setSizeLimits(
@bitCast(glfw.Window.SizeOptional, options.size_min),
@bitCast(glfw.Window.SizeOptional, options.size_max),
glfwSizeOptional(options.size_min),
glfwSizeOptional(options.size_max),
);
platform.core.target_desc.present_mode = switch (options.vsync) {
.none => .immediate,
@ -669,3 +669,10 @@ pub fn coreUpdate(core: *Core, resize: ?CoreResizeCallback) !void {
core.current_desc = core.target_desc;
}
}
fn glfwSizeOptional(size: structs.SizeOptional) glfw.Window.SizeOptional {
return .{
.width = size.width,
.height = size.height,
};
}