From 81b3aed8884377e6b288eab55f9c8f6108dd140a Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 19 Sep 2023 15:54:30 +0200 Subject: [PATCH] 0.11: ugrade build.zig --- build.zig | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/build.zig b/build.zig index 7436c621..c6c75dd4 100644 --- a/build.zig +++ b/build.zig @@ -14,12 +14,17 @@ pub fn build(b: *std.build.Builder) !void { // ------- // compile and install - const exe = b.addExecutable("browsercore", "src/main.zig"); - try common(exe, mode, target, options); - exe.install(); + const exe = b.addExecutable(.{ + .name = "browsercore", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = mode, + }); + try common(exe, options); + b.installArtifact(exe); // run - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); @@ -33,14 +38,19 @@ pub fn build(b: *std.build.Builder) !void { // ----- // compile and install - const shell = b.addExecutable("browsercore-shell", "src/main_shell.zig"); - try common(shell, mode, target, options); - try jsruntime_pkgs.add_shell(shell, mode); + const shell = b.addExecutable(.{ + .name = "browsercore-shell", + .root_source_file = .{ .path = "src/main_shell.zig" }, + .target = target, + .optimize = mode, + }); + try common(shell, options); + try jsruntime_pkgs.add_shell(shell); // do not install shell binary - shell.install(); + b.installArtifact(shell); // run - const shell_cmd = shell.run(); + const shell_cmd = b.addRunArtifact(shell); shell_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { shell_cmd.addArgs(args); @@ -54,8 +64,8 @@ pub fn build(b: *std.build.Builder) !void { // ---- // compile - const exe_tests = b.addTest("src/run_tests.zig"); - try common(exe_tests, mode, target, options); + const exe_tests = b.addTest(.{ .root_source_file = .{ .path = "src/run_tests.zig" } }); + try common(exe_tests, options); // step const test_step = b.step("test", "Run unit tests"); @@ -63,20 +73,16 @@ pub fn build(b: *std.build.Builder) !void { } fn common( - step: *std.build.LibExeObjStep, - mode: std.builtin.Mode, - target: std.zig.CrossTarget, + step: *std.Build.CompileStep, options: jsruntime.Options, ) !void { - step.setTarget(target); - step.setBuildMode(mode); - try jsruntime_pkgs.add(step, mode, options); + try jsruntime_pkgs.add(step, options); linkLexbor(step); } fn linkLexbor(step: *std.build.LibExeObjStep) void { // cmake . -DLEXBOR_BUILD_SHARED=OFF const lib_path = "vendor/lexbor/liblexbor_static.a"; - step.addObjectFile(lib_path); - step.addIncludePath("vendor/lexbor-src/source"); + step.addObjectFile(.{ .path = lib_path }); + step.addIncludePath(.{ .path = "vendor/lexbor-src/source" }); }