use an enum for zig version

This commit is contained in:
Meghan Denny 2021-10-01 22:37:11 -07:00
parent 94acedfde3
commit 8d46ceff07
3 changed files with 20 additions and 9 deletions

View File

@ -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" } });

View File

@ -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);

9
src/shared.zig Normal file
View File

@ -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",
};