Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5857c1a

Browse files
committed
Rejig build.zig
1 parent4c5ddf8 commit5857c1a

File tree

1 file changed

+139
-151
lines changed

1 file changed

+139
-151
lines changed

‎build.zig

Lines changed: 139 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,18 @@
11
constbuiltin=@import("builtin");
22
conststd=@import("std");
33

4-
pubfnbuild(b:*std.Build)void {
5-
if (checkGitLfsContent()==false) {
6-
ensureGit(b.allocator)catchreturn;
7-
ensureGitLfs(b.allocator,"install")catchreturn;
8-
ensureGitLfs(b.allocator,"pull")catchreturn;
9-
if (checkGitLfsContent()==false) {
10-
std.log.err("\n"++
11-
\\---------------------------------------------------------------------------
12-
\\
13-
\\Something went wrong, Git LFS content has not been downloaded.
14-
\\
15-
\\Please try to re-clone the repo and build again.
16-
\\
17-
\\---------------------------------------------------------------------------
18-
\\
19-
, .{});
20-
return;
21-
}
22-
}
23-
24-
consttarget=b.standardTargetOptions(.{});
25-
constoptimize=b.standardOptimizeOption(.{});
26-
27-
constzpix_enable=b.option(
28-
bool,
29-
"zpix-enable",
30-
"Enable PIX for Windows profiler",
31-
)orelsefalse;
32-
constoptions= .{
33-
.optimize=optimize,
34-
.target=target,
35-
.zxaudio2_debug_layer=b.option(
36-
bool,
37-
"zxaudio2_debug_layer",
38-
"Enable XAudio2 debug layer",
39-
)orelsefalse,
40-
.zd3d12_debug_layer=b.option(
41-
bool,
42-
"zd3d12_debug_layer",
43-
"Enable DirectX 12 debug layer",
44-
)orelsefalse,
45-
.zd3d12_gbv=b.option(
46-
bool,
47-
"zd3d12_gbv",
48-
"Enable DirectX 12 GPU-Based Validation (GBV)",
49-
)orelsefalse,
50-
.zpix_enable=zpix_enable,
51-
.zpix_path=b.option(
52-
[]constu8,
53-
"zpix-path",
54-
"Installed PIX path",
55-
)orelseif (zpix_enable)@panic("PIX path is required when enabled")else"",
4+
pubfnbuild(b:*std.Build)!void {
5+
checkGitLfsContent()catch {
6+
tryensureGit(b.allocator);
7+
tryensureGitLfs(b.allocator,"install");
8+
tryensureGitLfs(b.allocator,"pull");
9+
trycheckGitLfsContent();
5610
};
5711

58-
if (target.result.os.tag==.windows) {
59-
if (builtin.target.os.tag==.windowsorbuiltin.target.os.tag==.linux) {
60-
constactivate_zwindows=@import("zwindows").activateSdk(b,b.dependency("zwindows", .{}));
61-
b.default_step.dependOn(activate_zwindows);
62-
63-
samples.build(b,options,activate_zwindows,samples.windows_linux_cross);
64-
65-
if (builtin.target.os.tag==.windows) {
66-
// TODO: Try to upgrade these to windows_linux_cross
67-
samples.build(b,options,activate_zwindows,samples.windows_only);
68-
}
69-
}else@panic("Unsupported host OS for Windows target");
70-
}
71-
72-
if (target.result.os.tag==.emscripten) {
73-
constactivate_emsdk=@import("zemscripten").activateEmsdkStep(b);
74-
b.default_step.dependOn(activate_emsdk);
75-
76-
constweb_options= .{
77-
.optimize=optimize,
78-
.target=target,
79-
};
80-
samples.buildWeb(b,web_options,activate_emsdk);
81-
}else {
82-
samples.build(b,options,null,samples.crossplatform);
83-
}
84-
85-
// Install prebuilt SDL2 libs in bin output dir
86-
if (@import("zsdl").prebuilt_sdl2.install(b,options.target.result,.bin, .{
87-
.ttf=true,
88-
.image=true,
89-
}))|install_sdl2_step| {
90-
b.getInstallStep().dependOn(install_sdl2_step);
91-
}
92-
93-
{// Benchmarks
94-
constbenchmark_step=b.step("benchmark","Run all benchmarks");
95-
constzmath=b.dependency("zmath", .{
96-
.optimize=.ReleaseFast,
97-
});
98-
benchmark_step.dependOn(&b.addRunArtifact(zmath.artifact("zmath-benchmarks")).step);
99-
}
100-
101-
// Experiments
102-
if (b.option(bool,"experiments","Build our prototypes and experimental programs")orelsefalse) {
103-
@import("experiments/build.zig").build(b,options);
12+
consttarget=b.standardTargetOptions(.{});
13+
switch (target.result.os.tag) {
14+
.emscripten=>buildWeb(b,target),
15+
else=>buildDesktop(b,target),
10416
}
10517
}
10618

@@ -160,13 +72,15 @@ pub const samples = struct {
16072
/// Sample apps that can be built as web applications using zemscripten.
16173
pubconstweb=struct {
16274
pubconstsdl2_demo=samples.crossplatform.sdl2_demo;
163-
pubconstminimal_glfw_gl=samples.crossplatform.minimal_glfw_gl;
16475

165-
// TODO: WebGL samples
76+
// WebGL samples
77+
// TODO:
16678
// pub const minimal_sdl_gl = samples.crossplatform.minimal_sdl_gl;
79+
pubconstminimal_glfw_gl=samples.crossplatform.minimal_glfw_gl;
16780
// pub const minimal_zgui_glfw_gl = samples.crossplatform.minimal_zgui_glfw_gl;
16881

169-
// TODO: WebGPU samples
82+
// WebGPU samples
83+
// TODO:
17084
// pub const audio_experiments_wgpu = samples.crossplatform.audio_experiments_wgpu;
17185
// pub const bullet_physics_test_wgpu = samples.crossplatform.bullet_physics_test_wgpu;
17286
// pub const gamepad_wgpu = samples.crossplatform.gamepad_wgpu;
@@ -181,60 +95,132 @@ pub const samples = struct {
18195
// pub const textured_quad_wgpu = samples.crossplatform.textured_quad_wgpu;
18296
// pub const triangle_wgpu = samples.crossplatform.triangle_wgpu;
18397
};
98+
};
18499

185-
fnbuild(
186-
b:*std.Build,
187-
options:anytype,
188-
maybe_depend_step:?*std.Build.Step,
189-
comptimeapps:anytype,
190-
)void {
191-
inlinefor (comptimestd.meta.declarations(apps))|d| {
192-
constexe=buildExe(b,options,@field(apps,d.name));
193-
if (maybe_depend_step)|step| {
194-
exe.step.dependOn(step);
195-
}
196-
}
100+
fnbuildWeb(b:*std.Build,target:std.Build.ResolvedTarget)void {
101+
constoptions= .{
102+
.optimize=b.standardOptimizeOption(.{
103+
.preferred_optimize_mode=.ReleaseSmall,
104+
}),
105+
.target=target,
106+
};
107+
108+
constactivate_emsdk=@import("zemscripten").activateEmsdkStep(b);
109+
b.default_step.dependOn(activate_emsdk);
110+
111+
inlinefor (comptimestd.meta.declarations(samples.web))|d| {
112+
constbuild_web_app_step=@field(samples.web,d.name).buildWeb(b,options);
113+
build_web_app_step.dependOn(activate_emsdk);
114+
115+
b.getInstallStep().dependOn(build_web_app_step);
116+
117+
consthtml_filename=std.fmt.allocPrint(
118+
b.allocator,
119+
"{s}.html",
120+
.{d.name},
121+
)catchunreachable;
122+
123+
constemrun_step=@import("zemscripten").emrunStep(
124+
b,
125+
b.getInstallPath(.{ .custom="web" },html_filename),
126+
&.{},
127+
);
128+
emrun_step.dependOn(build_web_app_step);
129+
130+
b.step(
131+
d.name,
132+
"Build '"++d.name++"' sample as a web app",
133+
).dependOn(build_web_app_step);
134+
135+
b.step(
136+
d.name++"-emrun",
137+
"Build '"++d.name++"' sample as a web app and serve locally using `emrun`",
138+
).dependOn(emrun_step);
197139
}
198140

199-
fnbuildWeb(
200-
b:*std.Build,
201-
options:anytype,
202-
maybe_depend_step:?*std.Build.Step,
203-
)void {
204-
inlinefor (comptimestd.meta.declarations(samples.web))|d| {
205-
constbuild_web_app_step=@field(samples.web,d.name).buildWeb(b,options);
141+
buildBenchmarks(b,options.target);
142+
}
143+
144+
fnbuildDesktop(b:*std.Build,target:std.Build.ResolvedTarget)void {
145+
constoptimize=b.standardOptimizeOption(.{});
206146

207-
if (maybe_depend_step)|step| {
208-
build_web_app_step.dependOn(step);
147+
constzpix_enable=b.option(
148+
bool,
149+
"zpix-enable",
150+
"Enable PIX for Windows profiler",
151+
)orelsefalse;
152+
constoptions= .{
153+
.optimize=optimize,
154+
.target=target,
155+
.zxaudio2_debug_layer=b.option(
156+
bool,
157+
"zxaudio2_debug_layer",
158+
"Enable XAudio2 debug layer",
159+
)orelsefalse,
160+
.zd3d12_debug_layer=b.option(
161+
bool,
162+
"zd3d12_debug_layer",
163+
"Enable DirectX 12 debug layer",
164+
)orelsefalse,
165+
.zd3d12_gbv=b.option(
166+
bool,
167+
"zd3d12_gbv",
168+
"Enable DirectX 12 GPU-Based Validation (GBV)",
169+
)orelsefalse,
170+
.zpix_enable=zpix_enable,
171+
.zpix_path=b.option(
172+
[]constu8,
173+
"zpix-path",
174+
"Installed PIX path",
175+
)orelseif (zpix_enable)@panic("PIX path is required when enabled")else"",
176+
};
177+
178+
if (target.result.os.tag==.windows) {
179+
if (builtin.target.os.tag==.windowsorbuiltin.target.os.tag==.linux) {
180+
constactivate_zwindows=@import("zwindows").activateSdk(b,b.dependency("zwindows", .{}));
181+
b.default_step.dependOn(activate_zwindows);
182+
183+
inlinefor (comptimestd.meta.declarations(samples.windows_linux_cross))|d| {
184+
_=buildExe(b,options,@field(samples.windows_linux_cross,d.name));
209185
}
210186

211-
b.getInstallStep().dependOn(build_web_app_step);
212-
213-
consthtml_filename=std.fmt.allocPrint(
214-
b.allocator,
215-
"{s}.html",
216-
.{d.name},
217-
)catchunreachable;
218-
219-
constemrun_step=@import("zemscripten").emrunStep(
220-
b,
221-
b.getInstallPath(.{ .custom="web" },html_filename),
222-
&.{},
223-
);
224-
emrun_step.dependOn(build_web_app_step);
225-
226-
b.step(
227-
d.name,
228-
"Build '"++d.name++"' sample as a web app",
229-
).dependOn(build_web_app_step);
230-
231-
b.step(
232-
d.name++"-emrun",
233-
"Build '"++d.name++"' sample as a web app and serve locally using `emrun`",
234-
).dependOn(emrun_step);
235-
}
187+
if (builtin.target.os.tag==.windows) {
188+
// TODO: Try to upgrade these to windows_linux_cross
189+
inlinefor (comptimestd.meta.declarations(samples.windows_only))|d| {
190+
_=buildExe(b,options,@field(samples.windows_only,d.name));
191+
}
192+
}
193+
}else@panic("Unsupported host OS for Windows target");
236194
}
237-
};
195+
196+
inlinefor (comptimestd.meta.declarations(samples.crossplatform))|d| {
197+
_=buildExe(b,options,@field(samples.crossplatform,d.name));
198+
}
199+
200+
// Install prebuilt SDL2 libs in bin output dir
201+
if (@import("zsdl").prebuilt_sdl2.install(b,options.target.result,.bin, .{
202+
.ttf=true,
203+
.image=true,
204+
}))|install_sdl2_step| {
205+
b.getInstallStep().dependOn(install_sdl2_step);
206+
}
207+
208+
buildBenchmarks(b,options.target);
209+
210+
// Experiments
211+
if (b.option(bool,"experiments","Build our prototypes and experimental programs")orelsefalse) {
212+
@import("experiments/build.zig").build(b,options);
213+
}
214+
}
215+
216+
fnbuildBenchmarks(b:*std.Build,target:std.Build.ResolvedTarget)void {
217+
constbenchmark_step=b.step("benchmark","Run all benchmarks");
218+
constzmath=b.dependency("zmath", .{
219+
.target=target,
220+
.optimize=.ReleaseFast,
221+
});
222+
benchmark_step.dependOn(&b.addRunArtifact(zmath.artifact("zmath-benchmarks")).step);
223+
}
238224

239225
fnbuildExe(b:*std.Build,options:anytype,sample:anytype)*std.Build.Step.Compile {
240226
constexe=sample.build(b,options);
@@ -323,14 +309,16 @@ fn ensureGitLfs(allocator: std.mem.Allocator, cmd: []const u8) !void {
323309
}
324310
}
325311

326-
fncheckGitLfsContent()bool {
312+
fncheckGitLfsContent()!void {
327313
constexpected_contents=
328314
\\DO NOT EDIT OR DELETE
329315
\\This file is used to check if Git LFS content has been downloaded
330316
;
331317
varbuf: [expected_contents.len]u8=undefined;
332318
_=std.fs.cwd().readFile(".lfs-content-token",&buf)catch {
333-
returnfalse;
319+
returnerror.GitLfsContentTokenNotFound;
334320
};
335-
returnstd.mem.eql(u8,expected_contents,&buf);
321+
if (!std.mem.eql(u8,expected_contents,&buf)) {
322+
returnerror.GitLfsContentCheckFailed;
323+
}
336324
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp