mach: require a 'pub const App' to be exposed

This requires apps expose a `pub const App` from their `main.zig`, effectively adopting
the high-level/low-level application API outlined in hexops/mach#349

If `pub const App` does not exist, a clear compiler error is produced:

```
./src/platform/common.zig:5:9: error: expected e.g. `pub const App = mach.App(modules, init)' (App definition missing in your main Zig file)
        @compileError("expected e.g. `pub const App = mach.App(modules, init)' (App definition missing in your main Zig file)");
        ^
./src/platform/native.zig:13:28: note: called from here
    common.checkApplication(app_pkg);
                           ^
./src/platform/native.zig:12:10: note: called from here
comptime {
         ^
./src/platform/native.zig:15:20: error: container '.app' has no member called 'App'
const App = app_pkg.App;
                   ^
```

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-04 21:16:16 -07:00 committed by Stephen Gutekanst
parent 1b97c9f1e5
commit 72ea652dca
3 changed files with 20 additions and 13 deletions

View file

@ -1,5 +1,5 @@
const std = @import("std");
const App = @import("app");
const app_pkg = @import("app");
const Core = @import("../Core.zig");
const structs = @import("../structs.zig");
const enums = @import("../enums.zig");
@ -29,6 +29,12 @@ const js = struct {
extern fn machPanic(str: [*]const u8, len: u32) void;
};
const common = @import("common.zig");
comptime {
common.checkApplication(app_pkg);
}
const App = app_pkg.App;
pub const CanvasId = u32;
pub const Platform = struct {
@ -273,11 +279,6 @@ pub const BackingTimer = struct {
}
};
const common = @import("common.zig");
comptime {
common.checkApplication(App);
}
var app: App = undefined;
var core: Core = undefined;