-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
90 lines (80 loc) · 3.58 KB
/
build.zig
File metadata and controls
90 lines (80 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const std = @import("std");
const Build = std.Build;
const Module = std.Build.Module;
const Target = std.Build.ResolvedTarget;
const Optimize = std.builtin.OptimizeMode;
const zbgfx = @import("zbgfx");
const Imports = []const Module.Import;
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .Debug });
const math = @import("libs/math/build.zig").apply(b, target, optimize);
const type_id = @import("libs/type_id/build.zig").apply(b, target, optimize);
const window = @import("libs/window/build.zig").apply(b, target, optimize);
const stb = @import("libs/stb/build.zig").apply(b, target, optimize);
const dyn = @import("libs/dyn/build.zig").apply(b, target, optimize);
const plugin = @import("libs/plugin/build.zig").apply(b, target, optimize);
const res_pool = @import("libs/res_pool/build.zig").apply(b, target, optimize);
const scheduler = @import("libs/scheduler/build.zig").apply(b, target, optimize);
const runtime = buildRuntime(b, target, optimize, &.{
.{ .name = "math", .module = math },
.{ .name = "stb", .module = stb },
.{ .name = "window", .module = window },
.{ .name = "dyn", .module = dyn },
.{ .name = "type_id", .module = type_id },
.{ .name = "plugin", .module = plugin },
.{ .name = "res_pool", .module = res_pool },
.{ .name = "scheduler", .module = scheduler },
});
linkSimpleModDep(b, runtime, "entt", "ecs", "zig-ecs");
const window_plugin = @import("plugins/window/build.zig").apply(b, target, optimize);
const renderer_plugin = @import("plugins/renderer/build.zig").apply(b, target, optimize);
buildSandbox(b, target, optimize, &.{
.{ .name = "framework-runtime", .module = runtime },
.{ .name = "window", .module = window_plugin },
.{ .name = "renderer", .module = renderer_plugin },
});
}
fn exportLib(b: *std.Build, target: Target, optimize: Optimize, impl: anytype) *Module {
return impl.apply(b, target, optimize);
}
fn buildRuntime(b: *Build, target: Target, optimize: Optimize, imports: Imports) *Module {
const runtime = b.addModule("runtime", .{
.root_source_file = b.path("runtime/root.zig"),
.optimize = optimize,
.target = target,
.imports = imports,
});
return runtime;
}
fn buildSandbox(b: *Build, target: Target, optimize: Optimize, imports: Imports) void {
const exe = b.addExecutable(.{
.name = "sandbox",
.root_module = b.createModule(.{
.optimize = optimize,
.target = target,
.root_source_file = b.path("sandbox/main.zig"),
.imports = imports,
}),
});
b.installArtifact(exe);
// Add run step
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
fn linkSimpleModDep(b: *std.Build, module: *std.Build.Module, dep_name: []const u8, name: []const u8, mod_name: []const u8) void {
const dep = b.dependency(dep_name, .{});
const mod = dep.module(mod_name);
module.addImport(name, mod);
}
fn linkSimpleModDepWithArtifact(b: *std.Build, module: *std.Build.Module, dep_name: []const u8, name: []const u8, mod_name: []const u8, artifact: []const u8) void {
const dep = b.dependency(dep_name, .{});
const mod = dep.module(mod_name);
module.addImport(name, mod);
module.linkLibrary(dep.artifact(artifact));
}