From f6c43eaf9c598914507b0bb3027a4b2a95b045c5 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 15 Apr 2025 15:03:22 +0800 Subject: [PATCH] Fix dockerfile (hopefully) Add dummy --json stats output to tests Comment typos fixed Add make get-v8, build-v8 and build-v8-dev make targets --- .gitignore | 2 +- Dockerfile | 4 ++-- Makefile | 15 ++++++++++++++- README.md | 6 ++++-- src/runtime/js.zig | 7 +++---- src/test_runner.zig | 44 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 16c98921..ad9ae7b4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ zig-out /vendor/netsurf/out /vendor/libiconv/ lightpanda.id -v8/ +/v8/ diff --git a/Dockerfile b/Dockerfile index 7c0095d6..539dfdc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,8 +61,8 @@ RUN make install-libiconv && \ # download and install v8 RUN curl --fail -L -o libc_v8.a https://github.com/lightpanda-io/zig-v8-fork/releases/download/${ZIG_V8}/libc_v8_${V8}_linux_${ARCH}.a && \ - mkdir -p vendor/zig-js-runtime/vendor/v8/${ARCH}-linux/release && \ - mv libc_v8.a vendor/zig-js-runtime/vendor/v8/${ARCH}-linux/release/libc_v8.a + mkdir -p v8/build/${ARCH}-linux/release/ninja/obj/zig/ && \ + mv libc_v8.a v8/build/${ARCH}-linux/release/ninja/obj/zig/libc_v8.a # build release RUN make build diff --git a/Makefile b/Makefile index c588f82e..309bbb42 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ help: # $(ZIG) commands # ------------ -.PHONY: build build-dev run run-release shell test bench download-zig wpt data +.PHONY: build build-dev run run-release shell test bench download-zig wpt data get-v8 build-v8 build-v8-dev zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2) @@ -94,6 +94,19 @@ wpt-summary: test: @TEST_FILTER='${F}' $(ZIG) build test -freference-trace --summary all +## v8 +get-v8: + @printf "\e[36mGetting v8 source...\e[0m\n" + @$(ZIG) build get-v8 + +build-v8-dev: + @printf "\e[36mBuilding v8 (dev)...\e[0m\n" + @$(ZIG) build build-v8 + +build-v8: + @printf "\e[36mBuilding v8...\e[0m\n" + @$(ZIG) build -Doptimize=ReleaseSafe build-v8 + # Install and build required dependencies commands # ------------ .PHONY: install-submodule diff --git a/README.md b/README.md index f44fbaf3..06994548 100644 --- a/README.md +++ b/README.md @@ -221,15 +221,17 @@ env var `MIMALLOC_SHOW_STATS=1`. See First, get the tools necessary for building V8, as well as the V8 source code: ``` -zig build get-v8 +make get-v8 ``` Next, build v8. This build task is very long and cpu consuming, as you will build v8 from sources. ``` -zig build build-v8 +make build-v8-dev ``` +For dev env, use `make build-v8-dev`. + ## Test ### Unit Tests diff --git a/src/runtime/js.zig b/src/runtime/js.zig index 87d4cb48..caf9f2ec 100644 --- a/src/runtime/js.zig +++ b/src/runtime/js.zig @@ -129,7 +129,6 @@ pub fn Env(comptime S: type, comptime types: anytype) type { var prototype_index = i; const Struct = @field(types, s.name); if (@hasDecl(Struct, "prototype")) { - prototype_index = 1; const TI = @typeInfo(Struct.prototype); const proto_name = @typeName(Receiver(TI.pointer.child)); prototype_index = @field(TYPE_LOOKUP, proto_name); @@ -776,8 +775,8 @@ pub fn Env(comptime S: type, comptime types: anytype) type { scope_arena: ArenaAllocator, // When we need to load a resource (i.e. an external script), we call - // this function to get the source. This is always a refernece to the - // Browser Session's fetchModuleSource, but we use a funciton pointer + // this function to get the source. This is always a reference to the + // Browser Session's fetchModuleSource, but we use a function pointer // since this js module is decoupled from the browser implementation. module_loader: ModuleLoader, @@ -931,7 +930,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type { // To turn a Zig instance into a v8 object, we need to do a number of things. // First, if it's a struct, we need to put it on the heap - // Second, if we've alrady returned this instance, we should return + // Second, if we've already returned this instance, we should return // the same object. Hence, our executor maintains a map of Zig objects // to v8.PersistentObject (the "identity_map"). // Finally, if this is the first time we've seen this instance, we need to: diff --git a/src/test_runner.zig b/src/test_runner.zig index 07323ba4..bc456844 100644 --- a/src/test_runner.zig +++ b/src/test_runner.zig @@ -46,6 +46,19 @@ pub fn main() !void { var slowest = SlowTracker.init(allocator, 5); defer slowest.deinit(); + var args = try std.process.argsWithAllocator(allocator); + defer args.deinit(); + + // ignore the exec name. + _ = args.next(); + var json_stats = false; + while (args.next()) |arg| { + if (std.mem.eql(u8, "--json", arg)) { + json_stats = true; + continue; + } + } + var pass: usize = 0; var fail: usize = 0; var skip: usize = 0; @@ -155,6 +168,37 @@ pub fn main() !void { printer.fmt("\n", .{}); try slowest.display(printer); printer.fmt("\n", .{}); + + // TODO: at the very least, `browser` should return real stats + if (json_stats) { + try std.json.stringify(&.{ + .{ .name = "browser", .bench = .{ + .duration = 3180096049, + .alloc_nb = 6, + .realloc_nb = 278, + .alloc_size = 24711226, + } }, + .{ .name = "libdom", .bench = .{ + .duration = 3180096049, + .alloc_nb = 0, + .realloc_nb = 0, + .alloc_size = 0, + } }, + .{ .name = "v8", .bench = .{ + .duration = 3180096049, + .alloc_nb = 0, + .realloc_nb = 0, + .alloc_size = 0, + } }, + .{ .name = "main", .bench = .{ + .duration = 3180096049, + .alloc_nb = 0, + .realloc_nb = 0, + .alloc_size = 0, + } }, + }, .{ .whitespace = .indent_2 }, std.io.getStdOut().writer()); + } + std.posix.exit(if (fail == 0) 0 else 1); }