From 90f8109639252c2b77c99b894690e19c71f4af77 Mon Sep 17 00:00:00 2001 From: Lee Cannon Date: Thu, 7 Oct 2021 12:34:14 +0100 Subject: [PATCH] Update to use @import("builtin") where required --- src/main.zig | 5 +++-- src/setup.zig | 7 ++++--- src/uri.zig | 5 +++-- tests/sessions.zig | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index f0bcba2..27555a4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const zig_builtin = @import("builtin"); const build_options = @import("build_options"); const Config = @import("./config.zig"); const DocumentStore = @import("./document_store.zig"); @@ -29,7 +30,7 @@ const logger = std.log.scoped(.main); // value in the definition below. pub const log_level = .debug; -var actual_log_level: std.log.Level = switch (std.builtin.mode) { +var actual_log_level: std.log.Level = switch (zig_builtin.mode) { .Debug => .debug, else => .notice, }; @@ -1654,7 +1655,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso logger.debug("Method without return value not implemented: {s}", .{method}); } -const stack_frames = switch (std.builtin.mode) { +const stack_frames = switch (zig_builtin.mode) { .Debug => 10, else => 0, }; diff --git a/src/setup.zig b/src/setup.zig index 3158b23..5c44d8d 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const zinput = @import("zinput"); const known_folders = @import("known-folders"); @@ -72,7 +73,7 @@ pub fn wizard(allocator: *std.mem.Allocator) !void { print("Found zig executable '{s}' in PATH.\n", .{path}); } else { write("Could not find 'zig' in PATH\n"); - zig_exe_path = try zinput.askString(allocator, if (std.builtin.os.tag == .windows) + zig_exe_path = try zinput.askString(allocator, if (builtin.os.tag == .windows) \\What is the path to the 'zig' executable you would like to use? \\Note that due to a bug in zig (https://github.com/ziglang/zig/issues/6044), \\your zig directory cannot contain the '/' character. @@ -221,13 +222,13 @@ pub fn findZig(allocator: *std.mem.Allocator) !?[]const u8 { }; defer allocator.free(env_path); - const exe_extension = std.Target.current.exeFileExt(); + const exe_extension = builtin.target.exeFileExt(); const zig_exe = try std.fmt.allocPrint(allocator, "zig{s}", .{exe_extension}); defer allocator.free(zig_exe); var it = std.mem.tokenize(u8, env_path, &[_]u8{std.fs.path.delimiter}); while (it.next()) |path| { - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { if (std.mem.indexOfScalar(u8, path, '/') != null) continue; } const full_path = try std.fs.path.join(allocator, &[_][]const u8{ path, zig_exe }); diff --git a/src/uri.zig b/src/uri.zig index f9ad498..e4a1ed1 100644 --- a/src/uri.zig +++ b/src/uri.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); // http://tools.ietf.org/html/rfc3986#section-2.2 const reserved_chars = &[_]u8{ @@ -20,7 +21,7 @@ const reserved_escapes = blk: { /// Returns a URI from a path, caller owns the memory allocated with `allocator` pub fn fromPath(allocator: *std.mem.Allocator, path: []const u8) ![]const u8 { if (path.len == 0) return ""; - const prefix = if (std.builtin.os.tag == .windows) "file:///" else "file://"; + const prefix = if (builtin.os.tag == .windows) "file:///" else "file://"; var buf = std.ArrayList(u8).init(allocator); try buf.appendSlice(prefix); @@ -36,7 +37,7 @@ pub fn fromPath(allocator: *std.mem.Allocator, path: []const u8) ![]const u8 { } // On windows, we need to lowercase the drive name. - if (std.builtin.os.tag == .windows) { + if (builtin.os.tag == .windows) { if (buf.items.len > prefix.len + 1 and std.ascii.isAlpha(buf.items[prefix.len]) and std.mem.startsWith(u8, buf.items[prefix.len + 1 ..], "%3A")) diff --git a/tests/sessions.zig b/tests/sessions.zig index 922572b..91db7aa 100644 --- a/tests/sessions.zig +++ b/tests/sessions.zig @@ -1,7 +1,8 @@ const std = @import("std"); const headerPkg = @import("header"); +const builtin = @import("builtin"); -const suffix = if (std.builtin.os.tag == .windows) ".exe" else ""; +const suffix = if (builtin.os.tag == .windows) ".exe" else ""; const allocator = std.heap.page_allocator; const initialize_msg =