1414
1515const std = @import ("std" );
1616const builtin = @import ("builtin" );
17+ const EngineType = @import ("src/api.zig" ).EngineType ;
1718
1819const pkgs = packages ("" );
1920
@@ -40,7 +41,7 @@ pub fn build(b: *std.Build) !void {
4041
4142 // TODO: install only bench or shell with zig build <cmd>
4243
43- const options = try buildOptions (b );
44+ const options = buildOptions (b );
4445
4546 // bench
4647 // -----
@@ -132,31 +133,16 @@ pub fn build(b: *std.Build) !void {
132133 test_step .dependOn (& run_tests .step );
133134}
134135
135- const Engine = enum {
136- v8 ,
137- };
138-
139136pub const Options = struct {
140- engine : Engine ,
137+ engine : EngineType ,
141138 opts : * std.Build.Step.Options ,
142139};
143140
144- pub fn buildOptions (b : * std.Build ) ! Options {
141+ pub fn buildOptions (b : * std.Build ) Options {
142+ const engine = b .option (EngineType , "engine" , "JS engine (v8)" ) orelse .v8 ;
145143 const options = b .addOptions ();
146- const engine = b .option ([]const u8 , "engine" , "JS engine (v8)" );
147- var eng : Engine = undefined ;
148- if (engine == null ) {
149- // default
150- eng = .v8 ;
151- } else {
152- if (std .mem .eql (u8 , engine .? , "v8" )) {
153- eng = .v8 ;
154- } else {
155- return error .EngineUnknown ;
156- }
157- }
158- options .addOption (? []const u8 , "engine" , engine );
159- return .{ .engine = eng , .opts = options };
144+ options .addOption (EngineType , "engine" , engine );
145+ return .{ .engine = engine , .opts = options };
160146}
161147
162148fn common (
@@ -166,9 +152,11 @@ fn common(
166152) ! void {
167153 m .addOptions ("jsruntime_build_options" , options .opts );
168154 m .addImport ("tigerbeetle-io" , pkgs .tigerbeetle_io (b ));
169- if (options .engine == .v8 ) {
170- try pkgs .v8 (m );
171- m .addImport ("v8" , pkgs .zig_v8 (b ));
155+ switch (options .engine ) {
156+ .v8 = > {
157+ try pkgs .v8 (m );
158+ m .addImport ("v8" , pkgs .zig_v8 (b ));
159+ },
172160 }
173161}
174162
0 commit comments