diff options
| -rw-r--r-- | build.zig | 12 | ||||
| -rw-r--r-- | build.zig.zon | 13 | ||||
| -rw-r--r-- | src/Config.zig | 13 | ||||
| -rw-r--r-- | src/EasyHttp.zig | 4 | ||||
| -rw-r--r-- | src/Installation.zig | 18 | ||||
| -rw-r--r-- | src/install.zig | 2 | ||||
| -rw-r--r-- | src/main.zig | 2 |
7 files changed, 29 insertions, 35 deletions
| @@ -24,12 +24,10 @@ pub fn build(b: *Build) void { | |||
| 24 | .target = target, | 24 | .target = target, |
| 25 | .optimize = optimize, | 25 | .optimize = optimize, |
| 26 | }); | 26 | }); |
| 27 | exe.addOptions("zup-config", config); | 27 | exe.root_module.addOptions("zup-config", config); |
| 28 | exe.addModule("clap", clap.module("clap")); | 28 | exe.root_module.addImport("clap", clap.module("clap")); |
| 29 | exe.addModule("libarchive", libarchive.module("libarchive")); | 29 | exe.root_module.addImport("libarchive", libarchive.module("libarchive")); |
| 30 | exe.addModule("xdg", xdg.module("xdg")); | 30 | exe.root_module.addImport("xdg", xdg.module("xdg")); |
| 31 | exe.linkLibC(); | ||
| 32 | exe.linkSystemLibrary("libarchive"); | ||
| 33 | b.installArtifact(exe); | 31 | b.installArtifact(exe); |
| 34 | 32 | ||
| 35 | const run_cmd = b.addRunArtifact(exe); | 33 | const run_cmd = b.addRunArtifact(exe); |
| @@ -55,7 +53,7 @@ const default_version = SemanticVersion.parse("0.2.1") catch unreachable; | |||
| 55 | 53 | ||
| 56 | fn getVersion(b: *Build) SemanticVersion { | 54 | fn getVersion(b: *Build) SemanticVersion { |
| 57 | var out_code: u8 = undefined; | 55 | var out_code: u8 = undefined; |
| 58 | const untrimmed = b.execAllowFail( | 56 | const untrimmed = b.runAllowFail( |
| 59 | &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" }, | 57 | &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" }, |
| 60 | &out_code, | 58 | &out_code, |
| 61 | .Ignore, | 59 | .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 @@ | |||
| 2 | .{ | 2 | .{ |
| 3 | .name = "zup", | 3 | .name = "zup", |
| 4 | .version = "0.2.1", | 4 | .version = "0.2.1", |
| 5 | .paths = .{""}, | ||
| 5 | .dependencies = .{ | 6 | .dependencies = .{ |
| 6 | .clap = .{ | 7 | .clap = .{ |
| 7 | .url = "https://github.com/Hejsil/zig-clap/archive/0.7.0.tar.gz", | 8 | .url = "https://github.com/Hejsil/zig-clap/archive/4267b0b60ef6f87cccf3ee6ed481e6d0759180c6.tar.gz", |
| 8 | .hash = "1220f48518ce22882e102255ed3bcdb7aeeb4891f50b2cdd3bd74b5b2e24d3149ba2", | 9 | .hash = "12202fa30d679d821292bcd953458b9e76097a5d16999489125a206db63a53392833", |
| 9 | }, | 10 | }, |
| 10 | .libarchive = .{ | 11 | .libarchive = .{ |
| 11 | .url = "https://git.sr.ht/~ukko/zig-libarchive/archive/0.2.0.tar.gz", | 12 | .url = "https://git.sr.ht/~ukko/zig-libarchive/archive/7d3a63d5e05787847e5a199ffdd5bad99e7dbd7a.tar.gz", |
| 12 | .hash = "12206a8120d9a7550112f2fcc908c46900d6882c95156f900d5e0b39fcdb6a64a065", | 13 | .hash = "1220d8262d35559168d67d60797829a36958320556b277cd0e701a34eb00880461ab", |
| 13 | }, | 14 | }, |
| 14 | .xdg = .{ | 15 | .xdg = .{ |
| 15 | .url = "https://git.sr.ht/~ukko/zig-xdg/archive/0.2.1.tar.gz", | 16 | .url = "https://git.sr.ht/~ukko/zig-xdg/archive/1e925ee081a4880ad895c3976bd6e1d1061a4040.tar.gz", |
| 16 | .hash = "122012e83994a01a6faede69260f30bf25d3c7b9c2a6ef5226ce9b3e7ccd13b54898", | 17 | .hash = "122022d632b2ca6fd959b31748b3a4a7404d391abfae9b297bb3ce29045ae27e5568", |
| 17 | }, | 18 | }, |
| 18 | }, | 19 | }, |
| 19 | } | 20 | } |
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; | |||
| 6 | const ArenaAllocator = std.heap.ArenaAllocator; | 6 | const ArenaAllocator = std.heap.ArenaAllocator; |
| 7 | const ArrayList = std.ArrayList; | 7 | const ArrayList = std.ArrayList; |
| 8 | const Config = @This(); | 8 | const Config = @This(); |
| 9 | const CrossTarget = std.zig.CrossTarget; | ||
| 10 | const File = std.fs.File; | 9 | const File = std.fs.File; |
| 11 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; | ||
| 12 | const Target = std.Target; | 10 | const Target = std.Target; |
| 13 | 11 | ||
| 14 | allocator: Allocator, | 12 | allocator: Allocator, |
| @@ -81,7 +79,7 @@ fn readConfig(self: *Config, file: File) !void { | |||
| 81 | try self.supported_targets.ensureUnusedCapacity(parsed.supported_targets.len); | 79 | try self.supported_targets.ensureUnusedCapacity(parsed.supported_targets.len); |
| 82 | 80 | ||
| 83 | for (parsed.supported_targets) |target| { | 81 | for (parsed.supported_targets) |target| { |
| 84 | const ct = CrossTarget.parse(.{ | 82 | const query = Target.Query.parse(.{ |
| 85 | .arch_os_abi = target, | 83 | .arch_os_abi = target, |
| 86 | }) catch |e| { | 84 | }) catch |e| { |
| 87 | std.log.warn( | 85 | std.log.warn( |
| @@ -91,14 +89,11 @@ fn readConfig(self: *Config, file: File) !void { | |||
| 91 | continue; | 89 | continue; |
| 92 | }; | 90 | }; |
| 93 | 91 | ||
| 94 | const nti = NativeTargetInfo.detect(ct) catch |e| { | 92 | const resolved = std.zig.system.resolveTargetQuery(query) catch |e| { |
| 95 | std.log.warn( | 93 | std.log.warn("Failed to resolve '{s}' as a target: {}", .{ target, e}); |
| 96 | "Failed to detect NativeTargetInfo from '{s}': {}", | ||
| 97 | .{ target, e }, | ||
| 98 | ); | ||
| 99 | continue; | 94 | continue; |
| 100 | }; | 95 | }; |
| 101 | 96 | ||
| 102 | self.supported_targets.appendAssumeCapacity(nti.target); | 97 | self.supported_targets.appendAssumeCapacity(resolved); |
| 103 | } | 98 | } |
| 104 | } | 99 | } |
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 { | |||
| 22 | var headers = Headers.init(allocator); | 22 | var headers = Headers.init(allocator); |
| 23 | defer headers.deinit(); | 23 | defer headers.deinit(); |
| 24 | 24 | ||
| 25 | var request = try client.request(.GET, uri, headers, .{}); | 25 | var request = try client.open(.GET, uri, headers, .{}); |
| 26 | defer request.deinit(); | 26 | defer request.deinit(); |
| 27 | 27 | ||
| 28 | try request.start(); | 28 | try request.send(.{}); |
| 29 | try request.wait(); | 29 | try request.wait(); |
| 30 | 30 | ||
| 31 | return request.reader().readAllAlloc(parent_allocator, std.math.maxInt(usize)); | 31 | 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 { | |||
| 54 | } | 54 | } |
| 55 | }; | 55 | }; |
| 56 | 56 | ||
| 57 | var linkpath = try bin_home.realpathAlloc(allocator, linkname); | 57 | const linkpath = try bin_home.realpathAlloc(allocator, linkname); |
| 58 | defer allocator.free(linkpath); | 58 | defer allocator.free(linkpath); |
| 59 | 59 | ||
| 60 | var zup_dir = try xdg.getDataHome(allocator, "zup"); | 60 | const zup_dir = try xdg.getDataHome(allocator, "zup"); |
| 61 | defer allocator.free(zup_dir); | 61 | defer allocator.free(zup_dir); |
| 62 | 62 | ||
| 63 | const rel_path = try std.fs.path.relative(allocator, zup_dir, linkpath); | 63 | const rel_path = try std.fs.path.relative(allocator, zup_dir, linkpath); |
| @@ -79,7 +79,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 79 | var zup_data = try xdg.openDataHome(allocator, "zup"); | 79 | var zup_data = try xdg.openDataHome(allocator, "zup"); |
| 80 | defer zup_data.close(); | 80 | defer zup_data.close(); |
| 81 | 81 | ||
| 82 | var zup_data_iterable = try zup_data.openIterableDir(".", .{}); | 82 | var zup_data_iterable = try zup_data.openDir(".", .{ .iterate = true }); |
| 83 | defer zup_data_iterable.close(); | 83 | defer zup_data_iterable.close(); |
| 84 | 84 | ||
| 85 | var installations = Installations.init(allocator); | 85 | var installations = Installations.init(allocator); |
| @@ -94,7 +94,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 94 | var inst_dir = try zup_data.openDir(item.name, .{}); | 94 | var inst_dir = try zup_data.openDir(item.name, .{}); |
| 95 | defer inst_dir.close(); | 95 | defer inst_dir.close(); |
| 96 | 96 | ||
| 97 | var zig_exe = inst_dir.realpathAlloc(allocator, "zig") catch |err| { | 97 | const zig_exe = inst_dir.realpathAlloc(allocator, "zig") catch |err| { |
| 98 | if (err == error.FileNotFound) { | 98 | if (err == error.FileNotFound) { |
| 99 | continue; | 99 | continue; |
| 100 | } | 100 | } |
| @@ -102,7 +102,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 102 | }; | 102 | }; |
| 103 | defer allocator.free(zig_exe); | 103 | defer allocator.free(zig_exe); |
| 104 | 104 | ||
| 105 | const res = try ChildProcess.exec(.{ .allocator = allocator, .argv = &.{ zig_exe, "version" } }); | 105 | const res = try ChildProcess.run(.{ .allocator = allocator, .argv = &.{ zig_exe, "version" } }); |
| 106 | errdefer allocator.free(res.stdout); | 106 | errdefer allocator.free(res.stdout); |
| 107 | allocator.free(res.stderr); | 107 | allocator.free(res.stderr); |
| 108 | 108 | ||
| @@ -144,7 +144,7 @@ pub fn getAvailableList(config: Config) !Installations { | |||
| 144 | 144 | ||
| 145 | const allocator = arena.allocator(); | 145 | const allocator = arena.allocator(); |
| 146 | 146 | ||
| 147 | var data = try EasyHttp.get(allocator, index_json_uri); | 147 | const data = try EasyHttp.get(allocator, index_json_uri); |
| 148 | defer allocator.free(data); | 148 | defer allocator.free(data); |
| 149 | 149 | ||
| 150 | const parsed = try std.json.parseFromSliceLeaky( | 150 | const parsed = try std.json.parseFromSliceLeaky( |
| @@ -167,7 +167,7 @@ pub fn getAvailableList(config: Config) !Installations { | |||
| 167 | if (installation_opt) |*installation| { | 167 | if (installation_opt) |*installation| { |
| 168 | errdefer installation.deinit(); | 168 | errdefer installation.deinit(); |
| 169 | 169 | ||
| 170 | var name = try config.allocator.dupe(u8, kv.key_ptr.*); | 170 | const name = try config.allocator.dupe(u8, kv.key_ptr.*); |
| 171 | errdefer config.allocator.free(name); | 171 | errdefer config.allocator.free(name); |
| 172 | 172 | ||
| 173 | try installations.putNoClobber(name, installation.*); | 173 | try installations.putNoClobber(name, installation.*); |
| @@ -209,7 +209,7 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta | |||
| 209 | if (url_src != .string) { | 209 | if (url_src != .string) { |
| 210 | return error.JsonSchema; | 210 | return error.JsonSchema; |
| 211 | } | 211 | } |
| 212 | var url_str = try allocator.dupe(u8, url_src.string); | 212 | const url_str = try allocator.dupe(u8, url_src.string); |
| 213 | errdefer allocator.free(url_str); | 213 | errdefer allocator.free(url_str); |
| 214 | const url = try Uri.parse(url_str); | 214 | const url = try Uri.parse(url_str); |
| 215 | 215 | ||
| @@ -222,7 +222,7 @@ fn parseInstallation(config: Config, name: []const u8, value: JsonValue) !?Insta | |||
| 222 | } else blk: { | 222 | } else blk: { |
| 223 | break :blk name; | 223 | break :blk name; |
| 224 | }; | 224 | }; |
| 225 | var ver_str = try allocator.dupe(u8, version_src); | 225 | const ver_str = try allocator.dupe(u8, version_src); |
| 226 | errdefer allocator.free(ver_str); | 226 | errdefer allocator.free(ver_str); |
| 227 | const version = try SemanticVersion.parse(ver_str); | 227 | const version = try SemanticVersion.parse(ver_str); |
| 228 | 228 | ||
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 | |||
| 55 | 55 | ||
| 56 | std.log.info("Downloading from {s}...", .{installation.url_str.?}); | 56 | std.log.info("Downloading from {s}...", .{installation.url_str.?}); |
| 57 | 57 | ||
| 58 | var data = try EasyHttp.get(allocator, installation.url.?); | 58 | const data = try EasyHttp.get(allocator, installation.url.?); |
| 59 | defer allocator.free(data); | 59 | defer allocator.free(data); |
| 60 | 60 | ||
| 61 | std.log.info("Extracting...", .{}); | 61 | 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: { | |||
| 60 | map_data[0] = .{ "--help", .help }; | 60 | map_data[0] = .{ "--help", .help }; |
| 61 | map_data[1] = .{ "--version", .version }; | 61 | map_data[1] = .{ "--version", .version }; |
| 62 | var idx: usize = 2; | 62 | var idx: usize = 2; |
| 63 | inline for (commands) |command| { | 63 | for (commands) |command| { |
| 64 | map_data[idx] = .{ command.name, @as(Command, @enumFromInt(command.value)) }; | 64 | map_data[idx] = .{ command.name, @as(Command, @enumFromInt(command.value)) }; |
| 65 | idx += 1; | 65 | idx += 1; |
| 66 | } | 66 | } |