@@ -28,7 +28,7 @@ const jsruntime_pkgs = jsruntime.packages(jsruntime_path);
28
28
/// which zig version to install.
29
29
const recommended_zig_version = jsruntime .recommended_zig_version ;
30
30
31
- pub fn build (b : * std.build.Builder ) ! void {
31
+ pub fn build (b : * std.Build ) ! void {
32
32
switch (comptime builtin .zig_version .order (std .SemanticVersion .parse (recommended_zig_version ) catch unreachable )) {
33
33
.eq = > {},
34
34
.lt = > {
@@ -53,11 +53,11 @@ pub fn build(b: *std.build.Builder) !void {
53
53
// compile and install
54
54
const exe = b .addExecutable (.{
55
55
.name = "browsercore" ,
56
- .root_source_file = .{ . path = "src/main.zig" } ,
56
+ .root_source_file = b . path ( "src/main.zig" ) ,
57
57
.target = target ,
58
58
.optimize = mode ,
59
59
});
60
- try common (exe , options );
60
+ try common (b , exe , options );
61
61
b .installArtifact (exe );
62
62
63
63
// run
@@ -76,11 +76,11 @@ pub fn build(b: *std.build.Builder) !void {
76
76
// compile and install
77
77
const shell = b .addExecutable (.{
78
78
.name = "browsercore-shell" ,
79
- .root_source_file = .{ . path = "src/main_shell.zig" } ,
79
+ .root_source_file = b . path ( "src/main_shell.zig" ) ,
80
80
.target = target ,
81
81
.optimize = mode ,
82
82
});
83
- try common (shell , options );
83
+ try common (b , shell , options );
84
84
try jsruntime_pkgs .add_shell (shell );
85
85
86
86
// run
@@ -98,17 +98,17 @@ pub fn build(b: *std.build.Builder) !void {
98
98
99
99
// compile
100
100
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 ,
104
105
});
105
- try common (tests , options );
106
+ try common (b , tests , options );
106
107
107
108
// 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" ) ,
110
111
});
111
- tests .addModule ("pretty" , pretty );
112
112
113
113
const run_tests = b .addRunArtifact (tests );
114
114
if (b .args ) | args | {
@@ -125,12 +125,11 @@ pub fn build(b: *std.build.Builder) !void {
125
125
// compile and install
126
126
const wpt = b .addExecutable (.{
127
127
.name = "browsercore-wpt" ,
128
- .root_source_file = .{ . path = "src/main_wpt.zig" } ,
128
+ .root_source_file = b . path ( "src/main_wpt.zig" ) ,
129
129
.target = target ,
130
130
.optimize = mode ,
131
131
});
132
- try common (wpt , options );
133
- b .installArtifact (wpt );
132
+ try common (b , wpt , options );
134
133
135
134
// run
136
135
const wpt_cmd = b .addRunArtifact (wpt );
@@ -147,11 +146,11 @@ pub fn build(b: *std.build.Builder) !void {
147
146
// compile and install
148
147
const get = b .addExecutable (.{
149
148
.name = "browsercore-get" ,
150
- .root_source_file = .{ . path = "src/main_get.zig" } ,
149
+ .root_source_file = b . path ( "src/main_get.zig" ) ,
151
150
.target = target ,
152
151
.optimize = mode ,
153
152
});
154
- try common (get , options );
153
+ try common (b , get , options );
155
154
b .installArtifact (get );
156
155
157
156
// run
@@ -165,34 +164,59 @@ pub fn build(b: *std.build.Builder) !void {
165
164
}
166
165
167
166
fn common (
167
+ b : * std.Build ,
168
168
step : * std.Build.Step.Compile ,
169
169
options : jsruntime.Options ,
170
170
) ! 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 );
177
182
}
178
183
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
+ });
181
188
// 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 ));
184
194
185
195
// netsurf libs
186
196
const ns = "vendor/netsurf" ;
197
+ mod .addIncludePath (b .path (ns ++ "/include" ));
198
+
187
199
const libs : [4 ][]const u8 = .{
188
200
"libdom" ,
189
201
"libhubbub" ,
190
202
"libparserutils" ,
191
203
"libwapcaplet" ,
192
204
};
193
205
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" ) );
196
208
}
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 ;
198
222
}
0 commit comments