From 8d46ceff07ff92b82108a829cdf5a02285d45b35 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 1 Oct 2021 22:37:11 -0700 Subject: [PATCH] use an enum for zig version --- build.zig | 5 +++-- src/main.zig | 15 ++++++++------- src/shared.zig | 9 +++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/shared.zig diff --git a/build.zig b/build.zig index c4e2015..8b98a3a 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = std.builtin; +const shared = @import("./src/shared.zig"); pub fn build(b: *std.build.Builder) !void { const target = b.standardTargetOptions(.{}); @@ -10,9 +11,9 @@ pub fn build(b: *std.build.Builder) !void { exe.addOptions("build_options", exe_options); exe_options.addOption( - []const u8, + shared.ZigVersion, "data_version", - b.option([]const u8, "data_version", "The Zig version your compiler is.") orelse "master", + b.option(shared.ZigVersion, "data_version", "The Zig version your compiler is.") orelse .master, ); exe.addPackage(.{ .name = "known-folders", .path = .{ .path = "src/known-folders/known-folders.zig" } }); diff --git a/src/main.zig b/src/main.zig index 27555a4..86f05aa 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,15 +13,16 @@ const rename = @import("./rename.zig"); const offsets = @import("./offsets.zig"); const setup = @import("./setup.zig"); const semantic_tokens = @import("./semantic_tokens.zig"); +const shared = @import("./shared.zig"); const Ast = std.zig.Ast; const known_folders = @import("known-folders"); -const data = blk: { - if (std.mem.eql(u8, build_options.data_version, "0.7.0")) break :blk @import("data/0.7.0.zig"); - if (std.mem.eql(u8, build_options.data_version, "0.7.1")) break :blk @import("data/0.7.1.zig"); - if (std.mem.eql(u8, build_options.data_version, "0.8.0")) break :blk @import("data/0.8.0.zig"); - if (std.mem.eql(u8, build_options.data_version, "0.8.1")) break :blk @import("data/0.8.1.zig"); - if (std.mem.eql(u8, build_options.data_version, "master")) break :blk @import("data/master.zig"); - @compileError("invalid data_version provided"); + +const data = switch (build_options.data_version) { + .master => @import("data/master.zig"), + .@"0.7.0" => @import("data/0.7.0.zig"), + .@"0.7.1" => @import("data/0.7.1.zig"), + .@"0.8.0" => @import("data/0.8.0.zig"), + .@"0.8.1" => @import("data/0.8.1.zig"), }; const logger = std.log.scoped(.main); diff --git a/src/shared.zig b/src/shared.zig new file mode 100644 index 0000000..c5feded --- /dev/null +++ b/src/shared.zig @@ -0,0 +1,9 @@ +//! Specifically shared between both build.zig and main app code. + +pub const ZigVersion = enum { + master, + @"0.7.0", + @"0.7.1", + @"0.8.0", + @"0.8.1", +};