0.11: ugrade build.zig

This commit is contained in:
Pierre Tachoire
2023-09-19 15:54:30 +02:00
parent 5d5411e75e
commit 81b3aed888

View File

@@ -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" });
}