refactor: cleanup to have single entrypoints
This commit is contained in:
parent
126777caea
commit
06ce040347
4 changed files with 20 additions and 36 deletions
|
|
@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void {
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "temporalz",
|
.name = "temporalz",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path(if (is_freestanding) "src/wasm.zig" else "src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.link_libc = !is_freestanding,
|
.link_libc = !is_freestanding,
|
||||||
|
|
@ -21,6 +21,7 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
exe.root_module.addImport("temporalz", temporalz.module("temporalz"));
|
exe.root_module.addImport("temporalz", temporalz.module("temporalz"));
|
||||||
exe.rdynamic = is_freestanding;
|
exe.rdynamic = is_freestanding;
|
||||||
|
if (is_freestanding) exe.entry = .disabled;
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
b.enable_wasmtime = true; // This doesn't work since Zig 0.17.0 release
|
b.enable_wasmtime = true; // This doesn't work since Zig 0.17.0 release
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,24 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const builtin = @import("builtin");
|
||||||
const program = @import("root.zig");
|
const program = @import("root.zig");
|
||||||
|
|
||||||
pub fn main(init: std.process.Init) !void {
|
const freestanding = builtin.os.tag == .freestanding;
|
||||||
const allocator = init.arena.allocator();
|
|
||||||
const io = init.io;
|
pub fn main(init: Init) !void {
|
||||||
|
const allocator = std.heap.page_allocator;
|
||||||
|
const io = if (freestanding) null else init.io;
|
||||||
|
|
||||||
try program.run(allocator, io);
|
try program.run(allocator, io);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- //
|
||||||
|
const Init = if (freestanding) std.process.Init.Minimal else std.process.Init;
|
||||||
|
pub const std_options: std.Options = .{
|
||||||
|
.logFn = if (freestanding) logFn else std.log.defaultLog,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern fn console(ptr: [*]u8, len: u32) void;
|
||||||
|
fn logFn(comptime _: anytype, comptime _: anytype, comptime format: []const u8, args: anytype) void {
|
||||||
|
const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, format, args) catch return;
|
||||||
|
console(formatted.ptr, formatted.len);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -911,18 +911,3 @@ pub fn runTimeZoneExamples(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern fn consoleLog(ptr: [*]u8, len: u32) void;
|
|
||||||
pub fn logFn(comptime message_level: std.log.Level, comptime scope: @TypeOf(.enum_literal), comptime format: []const u8, args: anytype) void {
|
|
||||||
if (builtin.os.tag == .freestanding) {
|
|
||||||
const prefix = if (scope == .default) "" else "(" ++ @tagName(scope) ++ ") ";
|
|
||||||
const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, prefix ++ format, args) catch return;
|
|
||||||
consoleLog(formatted.ptr, formatted.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
std.log.defaultLog(message_level, scope, format, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const std_options: std.Options = .{
|
|
||||||
.logFn = logFn,
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
const std = @import("std");
|
|
||||||
const program = @import("root.zig");
|
|
||||||
const Temporal = @import("temporalz");
|
|
||||||
|
|
||||||
export fn _start() void {
|
|
||||||
const allocator = std.heap.page_allocator;
|
|
||||||
program.run(allocator, null) catch {};
|
|
||||||
}
|
|
||||||
|
|
||||||
extern fn console(ptr: [*]u8, len: u32) void;
|
|
||||||
|
|
||||||
fn logFn(comptime _: anytype, comptime _: anytype, comptime format: []const u8, args: anytype) void {
|
|
||||||
const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, format, args) catch return;
|
|
||||||
console(formatted.ptr, formatted.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const std_options: std.Options = .{ .logFn = logFn };
|
|
||||||
Loading…
Add table
Reference in a new issue