build: use path() func

This commit is contained in:
Pierre Tachoire
2024-06-17 14:56:06 +02:00
parent ef364f83c8
commit 68c8372493

View File

@@ -53,11 +53,11 @@ pub fn build(b: *std.Build) !void {
// compile and install // compile and install
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "browsercore", .name = "browsercore",
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = mode, .optimize = mode,
}); });
try common(exe, options); try common(b, exe, options);
b.installArtifact(exe); b.installArtifact(exe);
// run // run
@@ -76,11 +76,11 @@ pub fn build(b: *std.Build) !void {
// compile and install // compile and install
const shell = b.addExecutable(.{ const shell = b.addExecutable(.{
.name = "browsercore-shell", .name = "browsercore-shell",
.root_source_file = .{ .path = "src/main_shell.zig" }, .root_source_file = b.path("src/main_shell.zig"),
.target = target, .target = target,
.optimize = mode, .optimize = mode,
}); });
try common(shell, options); try common(b, shell, options);
try jsruntime_pkgs.add_shell(shell); try jsruntime_pkgs.add_shell(shell);
// run // run
@@ -98,15 +98,16 @@ pub fn build(b: *std.Build) !void {
// compile // compile
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_source_file = .{ .path = "src/run_tests.zig" }, .root_source_file = b.path("src/run_tests.zig"),
.test_runner = .{ .path = "src/test_runner.zig" }, .test_runner = b.path("src/test_runner.zig"),
.single_threaded = true, .target = target,
.optimize = mode,
}); });
try common(tests, options); try common(b, tests, options);
// add jsruntime pretty deps // add jsruntime pretty deps
tests.root_module.addAnonymousImport("pretty", .{ tests.root_module.addAnonymousImport("pretty", .{
.root_source_file = .{ .path = "vendor/zig-js-runtime/src/pretty.zig" }, .root_source_file = b.path("vendor/zig-js-runtime/src/pretty.zig"),
}); });
const run_tests = b.addRunArtifact(tests); const run_tests = b.addRunArtifact(tests);
@@ -124,12 +125,11 @@ pub fn build(b: *std.Build) !void {
// compile and install // compile and install
const wpt = b.addExecutable(.{ const wpt = b.addExecutable(.{
.name = "browsercore-wpt", .name = "browsercore-wpt",
.root_source_file = .{ .path = "src/main_wpt.zig" }, .root_source_file = b.path("src/main_wpt.zig"),
.target = target, .target = target,
.optimize = mode, .optimize = mode,
}); });
try common(wpt, options); try common(b, wpt, options);
b.installArtifact(wpt);
// run // run
const wpt_cmd = b.addRunArtifact(wpt); const wpt_cmd = b.addRunArtifact(wpt);
@@ -146,11 +146,11 @@ pub fn build(b: *std.Build) !void {
// compile and install // compile and install
const get = b.addExecutable(.{ const get = b.addExecutable(.{
.name = "browsercore-get", .name = "browsercore-get",
.root_source_file = .{ .path = "src/main_get.zig" }, .root_source_file = b.path("src/main_get.zig"),
.target = target, .target = target,
.optimize = mode, .optimize = mode,
}); });
try common(get, options); try common(b, get, options);
b.installArtifact(get); b.installArtifact(get);
// run // run
@@ -164,25 +164,27 @@ pub fn build(b: *std.Build) !void {
} }
fn common( fn common(
b: *std.Build,
step: *std.Build.Step.Compile, step: *std.Build.Step.Compile,
options: jsruntime.Options, options: jsruntime.Options,
) !void { ) !void {
try jsruntime_pkgs.add(step, options); try jsruntime_pkgs.add(step, options);
linkNetSurf(step); linkNetSurf(b, step);
// link mimalloc // link mimalloc
step.addObjectFile(.{ .path = "vendor/mimalloc/out/libmimalloc.a" }); step.addObjectFile(b.path("vendor/mimalloc/out/libmimalloc.a"));
step.addIncludePath(.{ .path = "vendor/mimalloc/out/include" }); step.addIncludePath(b.path("vendor/mimalloc/out/include"));
} }
fn linkNetSurf(step: *std.Build.Step.Compile) void { fn linkNetSurf(b: *std.Build, step: *std.Build.Step.Compile) void {
// iconv // iconv
step.addObjectFile(.{ .path = "vendor/libiconv/lib/libiconv.a" }); step.addObjectFile(b.path("vendor/libiconv/lib/libiconv.a"));
step.addIncludePath(.{ .path = "vendor/libiconv/include" }); step.addIncludePath(b.path("vendor/libiconv/include"));
// netsurf libs // netsurf libs
const ns = "vendor/netsurf"; const ns = "vendor/netsurf";
step.addIncludePath(b.path(ns ++ "/include"));
const libs: [4][]const u8 = .{ const libs: [4][]const u8 = .{
"libdom", "libdom",
"libhubbub", "libhubbub",
@@ -190,8 +192,7 @@ fn linkNetSurf(step: *std.Build.Step.Compile) void {
"libwapcaplet", "libwapcaplet",
}; };
inline for (libs) |lib| { inline for (libs) |lib| {
step.addObjectFile(.{ .path = ns ++ "/lib/" ++ lib ++ ".a" }); step.addObjectFile(b.path(ns ++ "/lib/" ++ lib ++ ".a"));
step.addIncludePath(.{ .path = ns ++ "/" ++ lib ++ "/src" }); step.addIncludePath(b.path(ns ++ "/" ++ lib ++ "/src"));
} }
step.addIncludePath(.{ .path = ns ++ "/include" });
} }