avoid using static library when hot reloading is disabled
This commit is contained in:
parent
9d733902b5
commit
daeb07379f
@ -31,13 +31,6 @@ pub fn init(outer_builder: *std.Build, opts: InitOptions) void {
|
|||||||
hot_reload = opts.hot_reload orelse (opts.optimize == .Debug);
|
hot_reload = opts.hot_reload orelse (opts.optimize == .Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.root_module.resolved_target = opts.target;
|
|
||||||
opts.root_module.optimize = opts.optimize;
|
|
||||||
const game_lib = b.addLibrary(.{
|
|
||||||
.name = "game",
|
|
||||||
.root_module = opts.root_module,
|
|
||||||
.linkage = if (hot_reload) .dynamic else .static,
|
|
||||||
});
|
|
||||||
const engine_lib = b.createModule(.{
|
const engine_lib = b.createModule(.{
|
||||||
.root_source_file = b.path("src/lib/root.zig")
|
.root_source_file = b.path("src/lib/root.zig")
|
||||||
});
|
});
|
||||||
@ -50,6 +43,10 @@ pub fn init(outer_builder: *std.Build, opts: InitOptions) void {
|
|||||||
.has_imgui = opts.has_imgui,
|
.has_imgui = opts.has_imgui,
|
||||||
.hot_reload = hot_reload
|
.hot_reload = hot_reload
|
||||||
});
|
});
|
||||||
|
engine_module.root_module.addImport("lib", engine_lib);
|
||||||
|
if (!hot_reload) {
|
||||||
|
engine_module.root_module.addImport("game", opts.root_module);
|
||||||
|
}
|
||||||
|
|
||||||
const mod_main = b.createModule(.{
|
const mod_main = b.createModule(.{
|
||||||
.root_source_file = b.path("src/runtime/main.zig"),
|
.root_source_file = b.path("src/runtime/main.zig"),
|
||||||
@ -57,11 +54,7 @@ pub fn init(outer_builder: *std.Build, opts: InitOptions) void {
|
|||||||
.optimize = opts.optimize,
|
.optimize = opts.optimize,
|
||||||
.link_libc = true
|
.link_libc = true
|
||||||
});
|
});
|
||||||
mod_main.addImport("lib", engine_lib);
|
|
||||||
mod_main.addImport("engine", engine_module.root_module);
|
mod_main.addImport("engine", engine_module.root_module);
|
||||||
if (!hot_reload) {
|
|
||||||
mod_main.linkLibrary(game_lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
var run_cmd_step: *std.Build.Step = undefined;
|
var run_cmd_step: *std.Build.Step = undefined;
|
||||||
if (isWasm) {
|
if (isWasm) {
|
||||||
@ -95,6 +88,14 @@ pub fn init(outer_builder: *std.Build, opts: InitOptions) void {
|
|||||||
run_cmd.addArgs(args);
|
run_cmd.addArgs(args);
|
||||||
}
|
}
|
||||||
if (hot_reload) {
|
if (hot_reload) {
|
||||||
|
opts.root_module.resolved_target = opts.target;
|
||||||
|
opts.root_module.optimize = opts.optimize;
|
||||||
|
const game_lib = b.addLibrary(.{
|
||||||
|
.name = "game",
|
||||||
|
.root_module = opts.root_module,
|
||||||
|
.linkage = .dynamic
|
||||||
|
});
|
||||||
|
|
||||||
run_cmd.addFileArg(game_lib.getEmittedBin());
|
run_cmd.addFileArg(game_lib.getEmittedBin());
|
||||||
}
|
}
|
||||||
run_cmd_step = &run_cmd.step;
|
run_cmd_step = &run_cmd.step;
|
||||||
@ -134,10 +135,6 @@ fn createEngineModule(b: *std.Build, opts: EngineModule.Options) EngineModule {
|
|||||||
.optimize = opts.optimize,
|
.optimize = opts.optimize,
|
||||||
.link_libc = true
|
.link_libc = true
|
||||||
});
|
});
|
||||||
const lib = b.createModule(.{
|
|
||||||
.root_source_file = b.path("src/lib/root.zig")
|
|
||||||
});
|
|
||||||
mod.addImport("lib", lib);
|
|
||||||
|
|
||||||
const dep_sokol = b.dependency("sokol", .{
|
const dep_sokol = b.dependency("sokol", .{
|
||||||
.target = opts.target,
|
.target = opts.target,
|
||||||
|
|||||||
@ -36,11 +36,6 @@ const GameCallbacks = struct {
|
|||||||
debug: if (build_options.has_imgui) Debug else void
|
debug: if (build_options.has_imgui) Debug else void
|
||||||
};
|
};
|
||||||
|
|
||||||
extern fn init(opts: *const Lib.Init) void;
|
|
||||||
extern fn tick(frame: *Lib.Frame) void;
|
|
||||||
extern fn deinit() void;
|
|
||||||
extern fn debug(imgui: *Lib.ImGui) void;
|
|
||||||
|
|
||||||
const GameLinking = union(enum) {
|
const GameLinking = union(enum) {
|
||||||
static,
|
static,
|
||||||
dynamic: struct {
|
dynamic: struct {
|
||||||
@ -54,11 +49,12 @@ const GameLinking = union(enum) {
|
|||||||
return error.StaticLinkingDisabled;
|
return error.StaticLinkingDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const game = @import("game");
|
||||||
return GameCallbacks{
|
return GameCallbacks{
|
||||||
.init = init,
|
.init = game.init,
|
||||||
.deinit = deinit,
|
.deinit = game.deinit,
|
||||||
.tick = tick,
|
.tick = game.tick,
|
||||||
.debug = if (build_options.has_imgui) debug else {},
|
.debug = if (build_options.has_imgui) game.debug else {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
.dynamic => |*opts| {
|
.dynamic => |*opts| {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user