@@ -19,7 +19,7 @@ const pkgs = packages("");
19
19
20
20
/// Do not rename this constant. It is scanned by some scripts to determine
21
21
/// which zig version to install.
22
- pub const recommended_zig_version = "0.12.0-dev.1773+8a8fd47d2 " ;
22
+ pub const recommended_zig_version = "0.12.1 " ;
23
23
24
24
pub fn build (b : * std.Build ) ! void {
25
25
switch (comptime builtin .zig_version .order (std .SemanticVersion .parse (recommended_zig_version ) catch unreachable )) {
@@ -48,17 +48,17 @@ pub fn build(b: *std.Build) !void {
48
48
// compile and install
49
49
const bench = b .addExecutable (.{
50
50
.name = "zig-js-runtime-bench" ,
51
- .root_source_file = .{ . path = "src/main_bench.zig" } ,
51
+ .root_source_file = b . path ( "src/main_bench.zig" ) ,
52
52
.single_threaded = true ,
53
53
.target = target ,
54
54
.optimize = mode ,
55
55
});
56
56
57
- try common (bench , mode , options );
57
+ try common (b , & bench . root_module , options );
58
58
if (mode == .ReleaseSafe ) {
59
59
// remove debug info
60
60
// TODO: check if mandatory in release-safe
61
- bench .strip = true ;
61
+ bench .root_module . strip = true ;
62
62
}
63
63
b .installArtifact (bench );
64
64
@@ -78,16 +78,16 @@ pub fn build(b: *std.Build) !void {
78
78
// compile and install
79
79
const shell = b .addExecutable (.{
80
80
.name = "zig-js-runtime-shell" ,
81
- .root_source_file = .{ . path = "src/main_shell.zig" } ,
81
+ .root_source_file = b . path ( "src/main_shell.zig" ) ,
82
82
.target = target ,
83
83
.optimize = mode ,
84
84
});
85
- try common (shell , mode , options );
85
+ try common (b , & shell . root_module , options );
86
86
try pkgs .add_shell (shell );
87
87
if (mode == .ReleaseSafe ) {
88
88
// remove debug info
89
89
// TODO: check if mandatory in release-safe
90
- shell .strip = true ;
90
+ shell .root_module . strip = true ;
91
91
}
92
92
// do not install shell binary
93
93
// b.installArtifact(shell);
@@ -107,13 +107,13 @@ pub fn build(b: *std.Build) !void {
107
107
108
108
// compile
109
109
const tests = b .addTest (.{
110
- .root_source_file = .{ . path = "src/run_tests.zig" } ,
110
+ .root_source_file = b . path ( "src/run_tests.zig" ) ,
111
111
.target = target ,
112
112
.optimize = mode ,
113
113
});
114
- try common (tests , mode , options );
115
- tests .single_threaded = true ;
116
- tests .test_runner = "src/test_runner.zig" ;
114
+ try common (b , & tests . root_module , options );
115
+ tests .root_module . single_threaded = true ;
116
+ tests .test_runner = b . path ( "src/test_runner.zig" ) ;
117
117
const run_tests = b .addRunArtifact (tests );
118
118
119
119
// step
@@ -149,15 +149,15 @@ pub fn buildOptions(b: *std.Build) !Options {
149
149
}
150
150
151
151
fn common (
152
- step : * std.Build.Step.Compile ,
153
- mode : std.builtin.Mode ,
152
+ b : * std.Build ,
153
+ m : * std.Build.Module ,
154
154
options : Options ,
155
155
) ! void {
156
- step .addOptions ("jsruntime_build_options" , options .opts );
157
- step . addModule ("tigerbeetle-io" , pkgs .tigerbeetle_io (step ));
156
+ m .addOptions ("jsruntime_build_options" , options .opts );
157
+ m . addImport ("tigerbeetle-io" , pkgs .tigerbeetle_io (b ));
158
158
if (options .engine == .v8 ) {
159
- try pkgs .v8 (step , mode );
160
- step . addModule ("v8" , pkgs .zig_v8 (step ));
159
+ try pkgs .v8 (m );
160
+ m . addImport ("v8" , pkgs .zig_v8 (b ));
161
161
}
162
162
}
163
163
@@ -167,33 +167,35 @@ pub fn packages(comptime vendor_path: []const u8) type {
167
167
168
168
const vendor = vendor_path ++ "vendor" ;
169
169
170
- fn tigerbeetle_io (step : * std.Build.Step.Compile ) * std.Build.Module {
171
- return step . step . owner .createModule (.{
172
- .source_file = .{ . path = vendor ++ "/tigerbeetle-io/io.zig" } ,
170
+ fn tigerbeetle_io (b : * std.Build ) * std.Build.Module {
171
+ return b .createModule (.{
172
+ .root_source_file = b . path ( vendor ++ "/tigerbeetle-io/io.zig" ) ,
173
173
});
174
174
}
175
175
176
- fn zig_v8 (step : * std.Build.Step.Compile ) * std.Build.Module {
177
- step . addIncludePath (.{ . path = vendor ++ "/zig-v8/src" });
178
-
179
- return step . step . owner . createModule (.{
180
- .source_file = .{ . path = vendor ++ "/zig-v8/src/v8.zig" } ,
176
+ fn zig_v8 (b : * std.Build ) * std.Build.Module {
177
+ const mod = b . createModule (.{
178
+ . root_source_file = b . path ( vendor ++ "/zig-v8/src/v8.zig" ),
179
+ . link_libc = false ,
180
+ .link_libcpp = false ,
181
181
});
182
- }
183
182
184
- fn v8 (step : * std.Build.Step.Compile , mode : std.builtin.Mode ) ! void {
185
- const mode_str : []const u8 = if (mode == .Debug ) "debug" else "release" ;
186
- // step.linkLibC(); // TODO: do we need to link libc?
183
+ mod .addIncludePath (b .path (vendor ++ "/zig-v8/src" ));
184
+
185
+ return mod ;
186
+ }
187
187
188
+ fn v8 (mod : * std.Build.Module ) ! void {
189
+ const mode_str : []const u8 = if (mod .optimize .? == .Debug ) "debug" else "release" ;
188
190
// FIXME: we are tied to native v8 builds, currently:
189
191
// - aarch64-macos
190
192
// - x86_64-linux
191
- const os = step . target . getOsTag () ;
192
- const arch = step . target . getCpuArch () ;
193
+ const os = mod . resolved_target .? . result . os . tag ;
194
+ const arch = mod . resolved_target .? . result . cpu . arch ;
193
195
switch (os ) {
194
196
.linux = > blk : {
195
197
// TODO: why do we need it? It should be linked already when we built v8
196
- step . linkLibCpp () ;
198
+ mod . link_libcpp = true ;
197
199
break :blk ;
198
200
},
199
201
.macos = > blk : {
@@ -207,45 +209,49 @@ pub fn packages(comptime vendor_path: []const u8) type {
207
209
}
208
210
209
211
const lib_path = try std .fmt .allocPrint (
210
- step . step .owner .allocator ,
212
+ mod .owner .allocator ,
211
213
"{s}vendor/v8/{s}-{s}/{s}/libc_v8.a" ,
212
214
.{ vendor_path , @tagName (arch ), @tagName (os ), mode_str },
213
215
);
214
- step .addObjectFile (.{ .path = lib_path } );
216
+ mod .addObjectFile (mod . owner .path ( lib_path ) );
215
217
}
216
218
217
219
pub fn add_shell (step : * std.Build.Step.Compile ) ! void {
218
- step .addIncludePath (.{ . path = vendor ++ "/linenoise-mob" } );
220
+ step .addIncludePath (step . root_module . owner . path ( vendor ++ "/linenoise-mob" ) );
219
221
const lib = step .step .owner .addStaticLibrary (.{
220
222
.name = "linenoise" ,
221
- .target = step .target ,
222
- .optimize = step .optimize ,
223
+ .target = step .root_module . resolved_target .? ,
224
+ .optimize = step .root_module . optimize .? ,
223
225
.link_libc = true ,
224
226
});
225
227
// TODO: use mode to add debug/release flags
226
228
const cflags = &.{};
227
229
lib .addCSourceFile (.{
228
- .file = .{ . path = vendor ++ "/linenoise-mob/linenoise.c" } ,
230
+ .file = step . root_module . owner . path ( vendor ++ "/linenoise-mob/linenoise.c" ) ,
229
231
.flags = cflags ,
230
232
});
231
233
step .linkLibrary (lib );
232
234
}
233
235
234
- pub fn add (
235
- step : * std.build.Step.Compile ,
236
+ pub fn module (
237
+ b : * std.Build ,
236
238
options : Options ,
237
- ) ! void {
238
- const jsruntime_mod = step .step .owner .createModule (.{
239
- .source_file = .{ .path = vendor_path ++ "/src/api.zig" },
240
- .dependencies = &[_ ]std.build.ModuleDependency {
239
+ mode : std.builtin.Mode ,
240
+ target : std.Build.ResolvedTarget ,
241
+ ) ! * std.Build.Module {
242
+ const mod = b .createModule (.{
243
+ .root_source_file = b .path (vendor_path ++ "/src/api.zig" ),
244
+ .optimize = mode ,
245
+ .target = target ,
246
+ .imports = &[_ ]std.Build.Module.Import {
241
247
.{ .name = "jsruntime_build_options" , .module = options .opts .createModule () },
242
- .{ .name = "tigerbeetle-io" , .module = Self .tigerbeetle_io (step ) },
243
- .{ .name = "v8" , .module = Self .zig_v8 (step ) },
248
+ .{ .name = "tigerbeetle-io" , .module = Self .tigerbeetle_io (b ) },
249
+ .{ .name = "v8" , .module = Self .zig_v8 (b ) },
244
250
},
245
251
});
246
- try Self .v8 (step , step . optimize );
252
+ try Self .v8 (mod );
247
253
248
- step . addModule ( "jsruntime" , jsruntime_mod ) ;
254
+ return mod ;
249
255
}
250
256
};
251
257
}
0 commit comments