@@ -28,7 +28,7 @@ const jsruntime_pkgs = jsruntime.packages(jsruntime_path);
2828/// which zig version to install.
2929const recommended_zig_version = jsruntime .recommended_zig_version ;
3030
31- pub fn build (b : * std.build.Builder ) ! void {
31+ pub fn build (b : * std.Build ) ! void {
3232 switch (comptime builtin .zig_version .order (std .SemanticVersion .parse (recommended_zig_version ) catch unreachable )) {
3333 .eq = > {},
3434 .lt = > {
@@ -53,11 +53,11 @@ pub fn build(b: *std.build.Builder) !void {
5353 // compile and install
5454 const exe = b .addExecutable (.{
5555 .name = "browsercore" ,
56- .root_source_file = .{ . path = "src/main.zig" } ,
56+ .root_source_file = b . path ( "src/main.zig" ) ,
5757 .target = target ,
5858 .optimize = mode ,
5959 });
60- try common (exe , options );
60+ try common (b , exe , options );
6161 b .installArtifact (exe );
6262
6363 // run
@@ -76,11 +76,11 @@ pub fn build(b: *std.build.Builder) !void {
7676 // compile and install
7777 const shell = b .addExecutable (.{
7878 .name = "browsercore-shell" ,
79- .root_source_file = .{ . path = "src/main_shell.zig" } ,
79+ .root_source_file = b . path ( "src/main_shell.zig" ) ,
8080 .target = target ,
8181 .optimize = mode ,
8282 });
83- try common (shell , options );
83+ try common (b , shell , options );
8484 try jsruntime_pkgs .add_shell (shell );
8585
8686 // run
@@ -98,17 +98,17 @@ pub fn build(b: *std.build.Builder) !void {
9898
9999 // compile
100100 const tests = b .addTest (.{
101- .root_source_file = .{ .path = "src/run_tests.zig" },
102- .test_runner = "src/test_runner.zig" ,
103- .single_threaded = true ,
101+ .root_source_file = b .path ("src/run_tests.zig" ),
102+ .test_runner = b .path ("src/test_runner.zig" ),
103+ .target = target ,
104+ .optimize = mode ,
104105 });
105- try common (tests , options );
106+ try common (b , tests , options );
106107
107108 // add jsruntime pretty deps
108- const pretty = tests .step . owner . createModule ( .{
109- .source_file = .{ . path = "vendor/zig-js-runtime/src/pretty.zig" } ,
109+ tests .root_module . addAnonymousImport ( "pretty" , .{
110+ .root_source_file = b . path ( "vendor/zig-js-runtime/src/pretty.zig" ) ,
110111 });
111- tests .addModule ("pretty" , pretty );
112112
113113 const run_tests = b .addRunArtifact (tests );
114114 if (b .args ) | args | {
@@ -125,12 +125,11 @@ pub fn build(b: *std.build.Builder) !void {
125125 // compile and install
126126 const wpt = b .addExecutable (.{
127127 .name = "browsercore-wpt" ,
128- .root_source_file = .{ . path = "src/main_wpt.zig" } ,
128+ .root_source_file = b . path ( "src/main_wpt.zig" ) ,
129129 .target = target ,
130130 .optimize = mode ,
131131 });
132- try common (wpt , options );
133- b .installArtifact (wpt );
132+ try common (b , wpt , options );
134133
135134 // run
136135 const wpt_cmd = b .addRunArtifact (wpt );
@@ -147,11 +146,11 @@ pub fn build(b: *std.build.Builder) !void {
147146 // compile and install
148147 const get = b .addExecutable (.{
149148 .name = "browsercore-get" ,
150- .root_source_file = .{ . path = "src/main_get.zig" } ,
149+ .root_source_file = b . path ( "src/main_get.zig" ) ,
151150 .target = target ,
152151 .optimize = mode ,
153152 });
154- try common (get , options );
153+ try common (b , get , options );
155154 b .installArtifact (get );
156155
157156 // run
@@ -165,34 +164,59 @@ pub fn build(b: *std.build.Builder) !void {
165164}
166165
167166fn common (
167+ b : * std.Build ,
168168 step : * std.Build.Step.Compile ,
169169 options : jsruntime.Options ,
170170) ! void {
171- try jsruntime_pkgs .add (step , options );
172- linkNetSurf (step );
173-
174- // link mimalloc
175- step .addObjectFile (.{ .path = "vendor/mimalloc/out/libmimalloc.a" });
176- step .addIncludePath (.{ .path = "vendor/mimalloc/out/include" });
171+ const jsruntimemod = try jsruntime_pkgs .module (
172+ b ,
173+ options ,
174+ step .root_module .optimize .? ,
175+ step .root_module .resolved_target .? ,
176+ );
177+ step .root_module .addImport ("jsruntime" , jsruntimemod );
178+
179+ const netsurf = moduleNetSurf (b );
180+ netsurf .addImport ("jsruntime" , jsruntimemod );
181+ step .root_module .addImport ("netsurf" , netsurf );
177182}
178183
179- fn linkNetSurf (step : * std.build.LibExeObjStep ) void {
180-
184+ fn moduleNetSurf (b : * std.Build ) * std.Build.Module {
185+ const mod = b .addModule ("netsurf" , .{
186+ .root_source_file = b .path ("src/netsurf/netsurf.zig" ),
187+ });
181188 // iconv
182- step .addObjectFile (.{ .path = "vendor/libiconv/lib/libiconv.a" });
183- step .addIncludePath (.{ .path = "vendor/libiconv/include" });
189+ mod .addObjectFile (b .path ("vendor/libiconv/lib/libiconv.a" ));
190+ mod .addIncludePath (b .path ("vendor/libiconv/include" ));
191+
192+ // mimalloc
193+ mod .addImport ("mimalloc" , moduleMimalloc (b ));
184194
185195 // netsurf libs
186196 const ns = "vendor/netsurf" ;
197+ mod .addIncludePath (b .path (ns ++ "/include" ));
198+
187199 const libs : [4 ][]const u8 = .{
188200 "libdom" ,
189201 "libhubbub" ,
190202 "libparserutils" ,
191203 "libwapcaplet" ,
192204 };
193205 inline for (libs ) | lib | {
194- step .addObjectFile (.{ . path = ns ++ "/lib/" ++ lib ++ ".a" } );
195- step .addIncludePath (.{ . path = ns ++ "/" ++ lib ++ "/src" } );
206+ mod .addObjectFile (b . path ( ns ++ "/lib/" ++ lib ++ ".a" ) );
207+ mod .addIncludePath (b . path ( ns ++ "/" ++ lib ++ "/src" ) );
196208 }
197- step .addIncludePath (.{ .path = ns ++ "/include" });
209+
210+ return mod ;
211+ }
212+
213+ fn moduleMimalloc (b : * std.Build ) * std.Build.Module {
214+ const mod = b .addModule ("mimalloc" , .{
215+ .root_source_file = b .path ("src/mimalloc/mimalloc.zig" ),
216+ });
217+
218+ mod .addObjectFile (b .path ("vendor/mimalloc/out/libmimalloc.a" ));
219+ mod .addIncludePath (b .path ("vendor/mimalloc/out/include" ));
220+
221+ return mod ;
198222}
0 commit comments