-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
149 lines (120 loc) · 4.74 KB
/
build.zig
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const std = @import("std");
const builtin = @import("builtin");
const min_zig_version = std.SemanticVersion.parse("0.14.0-dev.1911") catch @panic("Where is .zigversion?");
const version = std.SemanticVersion.parse(@embedFile(".version")) catch @panic("Where is .version?");
const cetech1_build = @import("cetech1");
const enabled_cetech_modules = cetech1_build.core_modules ++ cetech1_build.editor_modules;
pub const modules = [_][]const u8{
// Minimal
"minimal",
};
pub fn build(b: *std.Build) !void {
try ensureZigVersion();
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
//
// OPTIONS
//
const options = .{
.externals_optimize = b.option(std.builtin.OptimizeMode, "externals_optimize", "Optimize for externals libs") orelse .ReleaseFast,
.dynamic_modules = b.option(bool, "dynamic_modules", "build all modules in dynamic mode.") orelse true,
//.static_modules = b.option(bool, "static_modules", "build all modules in static mode.") orelse false,
// Tracy options
.enable_tracy = b.option(bool, "with_tracy", "build with tracy.") orelse true,
.tracy_on_demand = b.option(bool, "tracy_on_demand", "build tracy with TRACY_ON_DEMAND") orelse true,
.enable_shaderc = b.option(bool, "with_shaderc", "build with shaderc support") orelse true,
};
const options_step = b.addOptions();
options_step.addOption(std.SemanticVersion, "version", version);
// add build args
inline for (std.meta.fields(@TypeOf(options))) |field| {
options_step.addOption(field.type, field.name, @field(options, field.name));
}
const options_module = options_step.createModule();
_ = options_module; // autofix
//
// Extrnals
//
// Cetech1
const cetech1 = b.dependency(
"cetech1",
.{
.target = target,
.optimize = optimize,
.externals_optimize = options.externals_optimize,
.with_tracy = options.enable_tracy,
.tracy_on_demand = options.tracy_on_demand,
.with_shaderc = options.enable_shaderc,
//.static_modules = options.static_modules,
.dynamic_modules = options.dynamic_modules,
},
);
//
// TOOLS
//
const generate_vscode_tool = b.addExecutable(.{
.name = "generate_vscode",
.root_source_file = b.path("tools/generate_vscode.zig"),
.target = target,
});
generate_vscode_tool.root_module.addAnonymousImport("generate_vscode", .{
.root_source_file = b.path("externals/cetech1/src/tools/generate_vscode.zig"),
});
//
// Init repository step
//
const init_step = b.step("init", "init repository");
cetech1_build.initStep(b, init_step, "externals/cetech1/");
//
// Gen vscode
//
const vscode_step = b.step("vscode", "init/update vscode configs");
const gen_vscode = b.addRunArtifact(generate_vscode_tool);
gen_vscode.addDirectoryArg(b.path(".vscode/"));
vscode_step.dependOn(&gen_vscode.step);
if (options.enable_shaderc) {
b.installArtifact(cetech1.artifact("shaderc"));
}
if (options.dynamic_modules) {
b.installArtifact(cetech1.artifact("cetech1"));
var buff: [256:0]u8 = undefined;
// CETech modules
for (enabled_cetech_modules) |m| {
const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m});
const art = cetech1.artifact(artifact_name);
const step = b.addInstallArtifact(art, .{});
b.default_step.dependOn(&step.step);
}
// Project modules
for (modules) |m| {
const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m});
const art = b.dependency(m, .{
.target = target,
.optimize = optimize,
}).artifact(artifact_name);
const step = b.addInstallArtifact(art, .{});
b.default_step.dependOn(&step.step);
}
}
}
fn ensureZigVersion() !void {
var installed_ver = builtin.zig_version;
installed_ver.build = null;
if (installed_ver.order(min_zig_version) == .lt) {
std.log.err("\n" ++
\\---------------------------------------------------------------------------
\\
\\Installed Zig compiler version is too old.
\\
\\Min. required version: {any}
\\Installed version: {any}
\\
\\Please install newer version and try again.
\\zig/get_zig.sh <ARCH>
\\
\\---------------------------------------------------------------------------
\\
, .{ min_zig_version, installed_ver });
return error.ZigIsTooOld;
}
}