介绍
新Zig 0.14中发布的两大功能是增量编译和 x86 后端(无 LLVM)。
增量编译+文件系统观察
阅读此处了解增量编译
阅读此处有关文件系统观察的内容
(抱歉,我懒得重复其他资源涵盖的内容)
x86 后端
在这里阅读
(再次抱歉……哈哈)
构建.zig
这是我的 build.zig:
注意:注意紫色箭头和矩形。
完整代码:
const std = @import("std"); const ctPrint = std.fmt.comptimePrint; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); // List of Zig files in the programs/ directory const programs = [_][]const u8{ "main_add", "test_zigMaster_014", }; // Loop through each program and create exec inline for (programs) |program| { // Comptime program path const program_path = comptime ctPrint("programs/{s}.zig", .{program}); const exe = b.addExecutable(.{ .name = program, .root_source_file = b.path(program_path), .target = target, .optimize = optimize, .use_llvm = false, }); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } // Comptime step name and description const run_step_name = comptime ctPrint("run-{s}", .{program}); const run_step_desc = comptime ctPrint("Run the {s} program", .{program}); const run_step = b.step(run_step_name, run_step_desc); run_step.dependOn(&run_cmd.step); } const test_step = b.step("test", "Run tests for all programs"); inline for (programs) |program| { // Comptime program path const program_path = comptime ctPrint("programs/{s}.zig", .{program}); const test_exe = b.addTest(.{ .root_source_file = b.path(program_path), .target = target, .optimize = optimize, .use_llvm = false, }); const run_test_cmd = b.addRunArtifact(test_exe); test_step.dependOn(&run_test_cmd.step); } }
观看-fincremental –观看实际操作
主要亮点:
- 紫色箭头:运行命令
zig build -fincremental --watch
- 黄色矩形:初始构建 ~ 请注意我的两个 Zig 文件各花费约 700 毫秒的时间。
- 绿色矩形:增量构建,每当您进行更改并保存文件时都会自动完成。 -> 请注意,只花了大约 50 毫秒 –> 令人惊叹的 fwast!
增量编译加速的更多证据
-
来自 0.14 发行说明:
==从 14 秒到 63 毫秒==
-
来自 Jetzig 文档:
==从 16 秒到 139 毫秒==
如果您想阅读来源: Jetzig 博客
结论
就这样,这真是太神奇了不是吗?更重要的是,这些功能还没有完全成熟,所以下一个 Zig 版本 0.15 / 0.16 将会有更多的性能改进。这些功能的组合对于那些从事需要快速迭代的工作的人(尤其是游戏开发人员)来说至关重要。
我 10 岁的女儿正在使用 Godot 开发一款游戏,目前每次调试编译需要 20 秒。这 20 秒的延迟很烦人,而且确实破坏了动力。我想知道Mach(Zig游戏引擎)是否可以通过这种增量编译在亚秒内完成编译,我们不妨迁移到Mach?我们会看到…
原文: https://hwisnu.bearblog.dev/new-zig-014-compiler-features-fincremental-watch/