core: separate entrypoint from core module
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
47eac0d0c5
commit
033ebb8551
8 changed files with 21 additions and 21 deletions
|
|
@ -115,11 +115,6 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
|
|
||||||
var dependencies = std.ArrayList(std.build.ModuleDependency).init(b.allocator);
|
var dependencies = std.ArrayList(std.build.ModuleDependency).init(b.allocator);
|
||||||
try dependencies.append(.{ .name = "core", .module = module(b) });
|
try dependencies.append(.{ .name = "core", .module = module(b) });
|
||||||
try dependencies.append(.{ .name = "gpu", .module = deps.gpu.module(b) });
|
|
||||||
switch (platform) {
|
|
||||||
.native => try dependencies.append(.{ .name = "glfw", .module = deps.glfw.module(b) }),
|
|
||||||
.web => try dependencies.append(.{ .name = "sysjs", .module = deps.sysjs.module(b) }),
|
|
||||||
}
|
|
||||||
if (options.deps) |app_deps| try dependencies.appendSlice(app_deps);
|
if (options.deps) |app_deps| try dependencies.appendSlice(app_deps);
|
||||||
|
|
||||||
const app_module = b.createModule(.{
|
const app_module = b.createModule(.{
|
||||||
|
|
@ -137,7 +132,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
} else {
|
} else {
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
|
.root_source_file = .{ .path = sdkPath("/src/entry.zig") },
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
});
|
});
|
||||||
|
|
@ -151,7 +146,7 @@ pub fn Sdk(comptime deps: anytype) type {
|
||||||
};
|
};
|
||||||
|
|
||||||
step.main_pkg_path = sdkPath("/src");
|
step.main_pkg_path = sdkPath("/src");
|
||||||
step.addModule("gpu", deps.gpu.module(b));
|
step.addModule("core", module(b));
|
||||||
step.addModule("app", app_module);
|
step.addModule("app", app_module);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
pub usingnamespace @import("platform.zig").entry;
|
pub usingnamespace if (builtin.cpu.arch == .wasm32)
|
||||||
|
@import("platform/wasm/entry.zig")
|
||||||
|
else
|
||||||
|
@import("platform/native/entry.zig");
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
if (!builtin.is_test) {
|
if (!builtin.is_test) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
pub usingnamespace @import("entry.zig");
|
|
||||||
pub const Core = @import("Core.zig");
|
pub const Core = @import("Core.zig");
|
||||||
pub const Timer = @import("Timer.zig");
|
pub const Timer = @import("Timer.zig");
|
||||||
pub const gpu = @import("gpu");
|
pub const gpu = @import("gpu");
|
||||||
pub const sysjs = @import("sysjs");
|
pub const sysjs = @import("sysjs");
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
pub const platform_util = if (builtin.cpu.arch == .wasm32) {} else @import("platform/native/util.zig");
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = @import("platform/libmachcore.zig");
|
_ = @import("platform/libmachcore.zig");
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ else
|
||||||
|
|
||||||
// Verifies that a platform implementation exposes the expected function declarations.
|
// Verifies that a platform implementation exposes the expected function declarations.
|
||||||
comptime {
|
comptime {
|
||||||
assertHasDecl(@This(), "entry");
|
|
||||||
assertHasDecl(@This(), "Core");
|
assertHasDecl(@This(), "Core");
|
||||||
assertHasDecl(@This(), "Timer");
|
assertHasDecl(@This(), "Timer");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub const entry = @import("native/entry.zig");
|
|
||||||
pub const Core = @import("native/Core.zig");
|
pub const Core = @import("native/Core.zig");
|
||||||
pub const Timer = std.time.Timer;
|
pub const Timer = std.time.Timer;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const gpu = @import("gpu");
|
|
||||||
const App = @import("app").App;
|
const App = @import("app").App;
|
||||||
const util = @import("util.zig");
|
const core = @import("core");
|
||||||
|
const gpu = core.gpu;
|
||||||
|
|
||||||
pub const GPUInterface = gpu.dawn.Interface;
|
pub const GPUInterface = gpu.dawn.Interface;
|
||||||
|
|
||||||
|
|
@ -28,8 +28,8 @@ pub fn main() !void {
|
||||||
defer app.deinit();
|
defer app.deinit();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const pool = try util.AutoReleasePool.init();
|
const pool = try core.platform_util.AutoReleasePool.init();
|
||||||
defer util.AutoReleasePool.release(pool);
|
defer core.platform_util.AutoReleasePool.release(pool);
|
||||||
if (try app.update()) return;
|
if (try app.update()) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,2 @@
|
||||||
pub const Core = @import("wasm/Core.zig");
|
pub const Core = @import("wasm/Core.zig");
|
||||||
pub const Timer = @import("wasm/Timer.zig");
|
pub const Timer = @import("wasm/Timer.zig");
|
||||||
pub const entry = @import("wasm/entry.zig");
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const gpu = @import("gpu");
|
const core = @import("core");
|
||||||
|
const gpu = core.gpu;
|
||||||
const App = @import("app").App;
|
const App = @import("app").App;
|
||||||
const js = @import("js.zig");
|
|
||||||
|
pub extern "mach" fn machLogWrite(str: [*]const u8, len: u32) void;
|
||||||
|
pub extern "mach" fn machLogFlush() void;
|
||||||
|
pub extern "mach" fn machPanic(str: [*]const u8, len: u32) void;
|
||||||
|
|
||||||
pub const GPUInterface = gpu.StubInterface;
|
pub const GPUInterface = gpu.StubInterface;
|
||||||
const app_std_options = if (@hasDecl(App, "std_options")) App.std_options else struct {};
|
const app_std_options = if (@hasDecl(App, "std_options")) App.std_options else struct {};
|
||||||
|
|
@ -23,7 +27,7 @@ const LogError = error{};
|
||||||
const LogWriter = std.io.Writer(void, LogError, writeLog);
|
const LogWriter = std.io.Writer(void, LogError, writeLog);
|
||||||
|
|
||||||
fn writeLog(_: void, msg: []const u8) LogError!usize {
|
fn writeLog(_: void, msg: []const u8) LogError!usize {
|
||||||
js.machLogWrite(msg.ptr, msg.len);
|
machLogWrite(msg.ptr, msg.len);
|
||||||
return msg.len;
|
return msg.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +42,7 @@ pub const std_options = struct {
|
||||||
const writer = LogWriter{ .context = {} };
|
const writer = LogWriter{ .context = {} };
|
||||||
|
|
||||||
writer.print(message_level.asText() ++ prefix ++ format ++ "\n", args) catch return;
|
writer.print(message_level.asText() ++ prefix ++ format ++ "\n", args) catch return;
|
||||||
js.machLogFlush();
|
machLogFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const log_level = if (@hasDecl(app_std_options, "log_level"))
|
pub const log_level = if (@hasDecl(app_std_options, "log_level"))
|
||||||
|
|
@ -55,6 +59,6 @@ pub const std_options = struct {
|
||||||
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
|
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
|
||||||
_ = error_return_trace;
|
_ = error_return_trace;
|
||||||
_ = ret_addr;
|
_ = ret_addr;
|
||||||
js.machPanic(msg.ptr, msg.len);
|
machPanic(msg.ptr, msg.len);
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue