Update to use @import("builtin") where required

This commit is contained in:
Lee Cannon 2021-10-07 12:34:14 +01:00
parent b63339e350
commit 90f8109639
4 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const zig_builtin = @import("builtin");
const build_options = @import("build_options"); const build_options = @import("build_options");
const Config = @import("./config.zig"); const Config = @import("./config.zig");
const DocumentStore = @import("./document_store.zig"); const DocumentStore = @import("./document_store.zig");
@ -29,7 +30,7 @@ const logger = std.log.scoped(.main);
// value in the definition below. // value in the definition below.
pub const log_level = .debug; 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, .Debug => .debug,
else => .notice, 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}); 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, .Debug => 10,
else => 0, else => 0,
}; };

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const zinput = @import("zinput"); const zinput = @import("zinput");
const known_folders = @import("known-folders"); 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}); print("Found zig executable '{s}' in PATH.\n", .{path});
} else { } else {
write("Could not find 'zig' in PATH\n"); 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? \\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), \\Note that due to a bug in zig (https://github.com/ziglang/zig/issues/6044),
\\your zig directory cannot contain the '/' character. \\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); 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}); const zig_exe = try std.fmt.allocPrint(allocator, "zig{s}", .{exe_extension});
defer allocator.free(zig_exe); defer allocator.free(zig_exe);
var it = std.mem.tokenize(u8, env_path, &[_]u8{std.fs.path.delimiter}); var it = std.mem.tokenize(u8, env_path, &[_]u8{std.fs.path.delimiter});
while (it.next()) |path| { while (it.next()) |path| {
if (std.builtin.os.tag == .windows) { if (builtin.os.tag == .windows) {
if (std.mem.indexOfScalar(u8, path, '/') != null) continue; if (std.mem.indexOfScalar(u8, path, '/') != null) continue;
} }
const full_path = try std.fs.path.join(allocator, &[_][]const u8{ path, zig_exe }); const full_path = try std.fs.path.join(allocator, &[_][]const u8{ path, zig_exe });

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
// http://tools.ietf.org/html/rfc3986#section-2.2 // http://tools.ietf.org/html/rfc3986#section-2.2
const reserved_chars = &[_]u8{ 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` /// 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 { pub fn fromPath(allocator: *std.mem.Allocator, path: []const u8) ![]const u8 {
if (path.len == 0) return ""; 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); var buf = std.ArrayList(u8).init(allocator);
try buf.appendSlice(prefix); 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. // 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 if (buf.items.len > prefix.len + 1 and
std.ascii.isAlpha(buf.items[prefix.len]) and std.ascii.isAlpha(buf.items[prefix.len]) and
std.mem.startsWith(u8, buf.items[prefix.len + 1 ..], "%3A")) std.mem.startsWith(u8, buf.items[prefix.len + 1 ..], "%3A"))

View File

@ -1,7 +1,8 @@
const std = @import("std"); const std = @import("std");
const headerPkg = @import("header"); 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 allocator = std.heap.page_allocator;
const initialize_msg = const initialize_msg =