From f0161ce3c4e86ea1c309b1db67ca77066bb02779 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Fri, 2 Feb 2024 17:59:21 +0200 Subject: Update for latest zig --- build.zig | 12 +++++------- build.zig.zon | 13 +++++++------ src/Config.zig | 13 ++++--------- src/EasyHttp.zig | 4 ++-- src/Installation.zig | 18 +++++++++--------- src/install.zig | 2 +- src/main.zig | 2 +- 7 files changed, 29 insertions(+), 35 deletions(-) diff --git a/build.zig b/build.zig index 762eb67..fc642a7 100644 --- a/build.zig +++ b/build.zig @@ -24,12 +24,10 @@ pub fn build(b: *Build) void { .target = target, .optimize = optimize, }); - exe.addOptions("zup-config", config); - exe.addModule("clap", clap.module("clap")); - exe.addModule("libarchive", libarchive.module("libarchive")); - exe.addModule("xdg", xdg.module("xdg")); - exe.linkLibC(); - exe.linkSystemLibrary("libarchive"); + exe.root_module.addOptions("zup-config", config); + exe.root_module.addImport("clap", clap.module("clap")); + exe.root_module.addImport("libarchive", libarchive.module("libarchive")); + exe.root_module.addImport("xdg", xdg.module("xdg")); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); @@ -55,7 +53,7 @@ const default_version = SemanticVersion.parse("0.2.1") catch unreachable; fn getVersion(b: *Build) SemanticVersion { var out_code: u8 = undefined; - const untrimmed = b.execAllowFail( + const untrimmed = b.runAllowFail( &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" }, &out_code, .Ignore, diff --git a/build.zig.zon b/build.zig.zon index fcd0f82..ba57f52 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,18 +2,19 @@ .{ .name = "zup", .version = "0.2.1", + .paths = .{""}, .dependencies = .{ .clap = .{ - .url = "https://github.com/Hejsil/zig-clap/archive/0.7.0.tar.gz", - .hash = "1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2", + .url = "https://github.com/Hejsil/zig-clap/archive/4267b0b60ef6f87cccf3ee6ed481e6d0759180c6.tar.gz", + .hash = "12202fa30d679d821292bcd953458b9e76097a5d16999489125a206db63a53392833", }, .libarchive = .{ - .url = "https://git.sr.ht/~ukko/zig-libarchive/archive/0.2.0.tar.gz", - .hash = "12206a8120d9a7550112f2fcc908c46900d6882c95156f900d5e0b39fcdb6a64a065", + .url = "https://git.sr.ht/~ukko/zig-libarchive/archive/7d3a63d5e05787847e5a199ffdd5bad99e7dbd7a.tar.gz", + .hash = "1220d8262d35559168d67d60797829a36958320556b277cd0e701a34eb00880461ab", }, .xdg = .{ - .url = "https://git.sr.ht/~ukko/zig-xdg/archive/0.2.1.tar.gz", - .hash = "122012e83994a01a6faede69260f30bf25d3c7b9c2a6ef5226ce9b3e7ccd13b54898", + .url = "https://git.sr.ht/~ukko/zig-xdg/archive/1e925ee081a4880ad895c3976bd6e1d1061a4040.tar.gz", + .hash = "122022d632b2ca6fd959b31748b3a4a7404d391abfae9b297bb3ce29045ae27e5568", }, }, } diff --git a/src/Config.zig b/src/Config.zig index e559cad..ba8f496 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -6,9 +6,7 @@ const Allocator = std.mem.Allocator; const ArenaAllocator = std.heap.ArenaAllocator; const ArrayList = std.ArrayList; const Config = @This(); -const CrossTarget = std.zig.CrossTarget; const File = std.fs.File; -const NativeTargetInfo = std.zig.system.NativeTargetInfo; const Target = std.Target; allocator: Allocator, @@ -81,7 +79,7 @@ fn readConfig(self: *Config, file: File) !void { try self.supported_targets.ensureUnusedCapacity(parsed.supported_targets.len); for (parsed.supported_targets) |target| { - const ct = CrossTarget.parse(.{ + const query = Target.Query.parse(.{ .arch_os_abi = target, }) catch |e| { std.log.warn( @@ -91,14 +89,11 @@ fn readConfig(self: *Config, file: File) !void { continue; }; - const nti = NativeTargetInfo.detect(ct) catch |e| { - std.log.warn( - "Failed to detect NativeTargetInfo from '{s}': {}", - .{ target, e }, - ); + const resolved = std.zig.system.resolveTargetQuery(query) catch |e| { + std.log.warn("Failed to resolve '{s}' as a target: {}", .{ target, e}); continue; }; - self.supported_targets.appendAssumeCapacity(nti.target); + self.supported_targets.appendAssumeCapacity(resolved); } } diff --git a/src/EasyHttp.zig b/src/EasyHttp.zig index 197cf9d..10dcd0c 100644 --- a/src/EasyHttp.zig +++ b/src/EasyHttp.zig @@ -22,10 +22,10 @@ pub fn get(parent_allocator: Allocator, uri: Uri) ![]u8 { var headers = Headers.init(allocator); defer headers.deinit(); - var request = try client.request(.GET, uri, headers, .{}); + var request = try client.open(.GET, uri, headers, .{}); defer request.deinit(); - try request.start(); + try request.send(.{}); try request.wait(); return request.reader().readAllAlloc(parent_allocator, std.math.maxInt(usize)); diff --git a/src/Installation.zig b/src/Installation.zig index 8218f23..6565263 100644 --- a/src/Installation.zig +++ b/src/Installation.zig @@ -54,10 +54,10 @@ pub fn getActiveName(allocator: Allocator) !?[]u8 { } }; - var linkpath = try bin_home.realpathAlloc(allocator, linkname); + const linkpath = try bin_home.realpathAlloc(allocator, linkname); defer allocator.free(linkpath); - var zup_dir = try xdg.getDataHome(allocator, "zup"); + const zup_dir = try xdg.getDataHome(allocator, "zup"); defer allocator.free(zup_dir); const rel_path = try std.fs.path.relative(allocator, zup_dir, linkpath); @@ -79,7 +79,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { var zup_data = try xdg.openDataHome(allocator, "zup"); defer zup_data.close(); - var zup_data_iterable = try zup_data.openIterableDir(".", .{}); + var zup_data_iterable = try zup_data.openDir(".", .{ .iterate = true }); defer zup_data_iterable.close(); var installations = Installations.init(allocator); @@ -94,7 +94,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { var inst_dir = try zup_data.openDir(item.name, .{}); defer inst_dir.close(); - var zig_exe = inst_dir.realpathAlloc(allocator, "zig") catch |err| { + const zig_exe = inst_dir.realpathAlloc(allocator, "zig") catch |err| { if (err == error.FileNotFound) { continue; } @@ -102,7 +102,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { }; defer allocator.free(zig_exe); - const res = try ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ zig_exe, "version" } }); + const res = try ChildProcess.run(.{ .allocator = allocator, .argv = &.{ zig_exe, "version" } }); errdefer allocator.free(res.stdout); allocator.free(res.stderr); @@ -144,7 +144,7 @@ pub fn getAvailableList(config: Config) !Installations { const allocator = arena.allocator(); - var data = try EasyHttp.get(allocator, index_json_uri); + const data = try EasyHttp.get(allocator, index_json_uri); defer allocator.free(data); const parsed = try std.json.parseFromSliceLeaky( @@ -167,7 +167,7 @@ pub fn getAvailableList(config: Config) !Installations { if (installation_opt) |*installation| { errdefer installation.deinit(); - var name = try config.allocator.dupe(u8, kv.key_ptr.*); + const name = try config.allocator.dupe(u8, kv.key_ptr.*); errdefer config.allocator.free(name); try installations.putNoClobber(name, installation.*); @@ -209,7 +209,7 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta if (url_src != .string) { return error.JsonSchema; } - var url_str = try allocator.dupe(u8, url_src.string); + const url_str = try allocator.dupe(u8, url_src.string); errdefer allocator.free(url_str); const url = try Uri.parse(url_str); @@ -222,7 +222,7 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta } else blk: { break :blk name; }; - var ver_str = try allocator.dupe(u8, version_src); + const ver_str = try allocator.dupe(u8, version_src); errdefer allocator.free(ver_str); const version = try SemanticVersion.parse(ver_str); diff --git a/src/install.zig b/src/install.zig index a459aa6..de6d8f0 100644 --- a/src/install.zig +++ b/src/install.zig @@ -55,7 +55,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I std.log.info("Downloading from {s}...", .{installation.url_str.?}); - var data = try EasyHttp.get(allocator, installation.url.?); + const data = try EasyHttp.get(allocator, installation.url.?); defer allocator.free(data); std.log.info("Extracting...", .{}); diff --git a/src/main.zig b/src/main.zig index 5522915..f5b6c1e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,7 +60,7 @@ const CommandMap = blk: { map_data[0] = .{ "--help", .help }; map_data[1] = .{ "--version", .version }; var idx: usize = 2; - inline for (commands) |command| { + for (commands) |command| { map_data[idx] = .{ command.name, @as(Command, @enumFromInt(command.value)) }; idx += 1; } -- cgit v1.2.3