Update to jsruntime engine interface

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-08-29 20:13:15 +02:00
parent 2d71275a3c
commit 740b1a0d9c
4 changed files with 15 additions and 12 deletions

View File

@@ -22,12 +22,12 @@ help:
## Build in debug mode ## Build in debug mode
build: build:
@printf "\e[36mBuilding (debug)...\e[0m\n" @printf "\e[36mBuilding (debug)...\e[0m\n"
@zig build || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;) @zig build -Dengine=v8 || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;)
@printf "\e[33mBuild OK\e[0m\n" @printf "\e[33mBuild OK\e[0m\n"
build-release: build-release:
@printf "\e[36mBuilding (release safe)...\e[0m\n" @printf "\e[36mBuilding (release safe)...\e[0m\n"
@zig build -Drelease-safe || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;) @zig build -Drelease-safe -Dengine=v8 || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;)
@printf "\e[33mBuild OK\e[0m\n" @printf "\e[33mBuild OK\e[0m\n"
## Run the server ## Run the server
@@ -38,10 +38,10 @@ run: build
## Run a JS shell in release-safe mode ## Run a JS shell in release-safe mode
shell: shell:
@printf "\e[36mBuilding shell...\e[0m\n" @printf "\e[36mBuilding shell...\e[0m\n"
@zig build shell || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;) @zig build shell -Dengine=v8 || (printf "\e[33mBuild ERROR\e[0m\n"; exit 1;)
## Test ## Test
test: test:
@printf "\e[36mTesting...\e[0m\n" @printf "\e[36mTesting...\e[0m\n"
@zig build test || (printf "\e[33mTest ERROR\e[0m\n"; exit 1;) @zig build test -Dengine=v8 || (printf "\e[33mTest ERROR\e[0m\n"; exit 1;)
@printf "\e[33mTest OK\e[0m\n" @printf "\e[33mTest OK\e[0m\n"

View File

@@ -1,18 +1,21 @@
const std = @import("std"); const std = @import("std");
const jsruntime_path: []const u8 = "vendor/jsruntime-lib/"; const jsruntime_path = "vendor/jsruntime-lib/";
const jsruntime_pkgs = @import("vendor/jsruntime-lib/build.zig").packages(jsruntime_path); const jsruntime = @import("vendor/jsruntime-lib/build.zig");
const jsruntime_pkgs = jsruntime.packages(jsruntime_path);
pub fn build(b: *std.build.Builder) !void { pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const options = try jsruntime.buildOptions(b);
// browser // browser
// ------- // -------
// compile and install // compile and install
const exe = b.addExecutable("browsercore", "src/main.zig"); const exe = b.addExecutable("browsercore", "src/main.zig");
try common(exe, mode, target); try common(exe, mode, target, options);
exe.install(); exe.install();
// run // run
@@ -31,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {
// compile and install // compile and install
const shell = b.addExecutable("browsercore-shell", "src/main_shell.zig"); const shell = b.addExecutable("browsercore-shell", "src/main_shell.zig");
try common(shell, mode, target); try common(shell, mode, target, options);
try jsruntime_pkgs.add_shell(shell, mode); try jsruntime_pkgs.add_shell(shell, mode);
// do not install shell binary // do not install shell binary
shell.install(); shell.install();
@@ -52,7 +55,7 @@ pub fn build(b: *std.build.Builder) !void {
// compile // compile
const exe_tests = b.addTest("src/run_tests.zig"); const exe_tests = b.addTest("src/run_tests.zig");
try common(exe_tests, mode, target); try common(exe_tests, mode, target, options);
// step // step
const test_step = b.step("test", "Run unit tests"); const test_step = b.step("test", "Run unit tests");
@@ -63,10 +66,11 @@ fn common(
step: *std.build.LibExeObjStep, step: *std.build.LibExeObjStep,
mode: std.builtin.Mode, mode: std.builtin.Mode,
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
options: jsruntime.Options,
) !void { ) !void {
step.setTarget(target); step.setTarget(target);
step.setBuildMode(mode); step.setBuildMode(mode);
try jsruntime_pkgs.add(step, mode); try jsruntime_pkgs.add(step, mode, options);
linkLexbor(step); linkLexbor(step);
} }

View File

@@ -1,7 +1,6 @@
const std = @import("std"); const std = @import("std");
const jsruntime = @import("jsruntime"); const jsruntime = @import("jsruntime");
const Console = @import("jsruntime").Console;
const parser = @import("parser.zig"); const parser = @import("parser.zig");
const DOM = @import("dom.zig"); const DOM = @import("dom.zig");

View File

@@ -18,7 +18,7 @@ fn testsExecFn(
) !void { ) !void {
// start JS env // start JS env
js_env.start(); js_env.start(apis);
defer js_env.stop(); defer js_env.stop();
// add document object // add document object