summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2023-04-02 21:47:15 +0300
committerGravatar Uko Kokņevičs2023-04-02 21:50:01 +0300
commita6dbcffe2ce03f9571da693852181a785942ec4b (patch)
treeab5eb4b7591c104fd04758c32039dda03b67f3ea
parentRelease 0.2.1 (diff)
downloadzup-a6dbcffe2ce03f9571da693852181a785942ec4b.tar.gz
zup-a6dbcffe2ce03f9571da693852181a785942ec4b.tar.xz
zup-a6dbcffe2ce03f9571da693852181a785942ec4b.zip
Actually use my zig-curl instead of zelda.
I'll wait until zelda & zig get more stable and get more contributors. Also, zelda has been archived on April 1st, perhaps a joke, perhaps not. This reverts commit 081e79c3fa385c662a5a6b7faf717ec370b398c8. This reverts commit 33226c20c41e3fe2de3330b6692c90bc4818b119. This reverts commit 3b3baf375be63acfd293b1b47a5f49aab4b06a70.
-rw-r--r--.gitmodules6
-rw-r--r--README.org2
-rw-r--r--build.zig12
m---------libs/curl0
m---------libs/libarchive0
m---------libs/zelda0
-rw-r--r--src/Installation.zig18
-rw-r--r--src/install.zig34
-rw-r--r--src/main.zig4
9 files changed, 32 insertions, 44 deletions
diff --git a/.gitmodules b/.gitmodules
index cfc92e7..a9df803 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,9 +4,9 @@
4[submodule "libs/xdg"] 4[submodule "libs/xdg"]
5 path = libs/xdg 5 path = libs/xdg
6 url = https://git.sr.ht/~ukko/zig-xdg 6 url = https://git.sr.ht/~ukko/zig-xdg
7[submodule "libs/curl"]
8 path = libs/curl
9 url = https://git.sr.ht/~ukko/zig-curl
7[submodule "libs/libarchive"] 10[submodule "libs/libarchive"]
8 path = libs/libarchive 11 path = libs/libarchive
9 url = https://git.sr.ht/~ukko/zig-libarchive 12 url = https://git.sr.ht/~ukko/zig-libarchive
10[submodule "libs/zelda"]
11 path = libs/zelda
12 url = https://github.com/haze/zelda.git
diff --git a/README.org b/README.org
index 3571a36..8a7fa42 100644
--- a/README.org
+++ b/README.org
@@ -9,7 +9,7 @@
9** System libraries 9** System libraries
10 10
11- libarchive 11- libarchive
12- libressl 12- libcurl
13 13
14** Zig version 14** Zig version
15 15
diff --git a/build.zig b/build.zig
index bce3dcb..934e826 100644
--- a/build.zig
+++ b/build.zig
@@ -1,11 +1,10 @@
1const builtin = @import("builtin"); 1const builtin = @import("builtin");
2const std = @import("std"); 2const std = @import("std");
3const zelda = @import("libs/zelda/build.zig");
4 3
5const Builder = std.build.Builder; 4const Builder = std.build.Builder;
6const SemanticVersion = std.SemanticVersion; 5const SemanticVersion = std.SemanticVersion;
7 6
8pub fn build(b: *Builder) !void { 7pub fn build(b: *Builder) void {
9 const target = b.standardTargetOptions(.{}); 8 const target = b.standardTargetOptions(.{});
10 const mode = b.standardReleaseOptions(); 9 const mode = b.standardReleaseOptions();
11 10
@@ -16,17 +15,14 @@ pub fn build(b: *Builder) !void {
16 exe.setTarget(target); 15 exe.setTarget(target);
17 exe.setBuildMode(mode); 16 exe.setBuildMode(mode);
18 exe.addOptions("zup-config", config); 17 exe.addOptions("zup-config", config);
19 // TODO[https://github.com/ziglang/zig/issues/13551]: Remove this
20 exe.linkSystemLibraryPkgConfigOnly("libcrypto");
21 try zelda.link(b, exe, target, mode, true);
22 exe.addPackagePath("clap", "libs/clap/clap.zig"); 18 exe.addPackagePath("clap", "libs/clap/clap.zig");
19 exe.addPackagePath("curl", "libs/curl/curl.zig");
23 exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); 20 exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig");
24 exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); 21 exe.addPackagePath("xdg", "libs/xdg/xdg.zig");
25 exe.addPackagePath("zup", "src/main.zig"); 22 exe.addPackagePath("zup", "src/main.zig");
26 exe.linkLibC(); 23 exe.linkLibC();
27 // TODO[https://github.com/ziglang/zig/issues/13551]: 24 exe.linkSystemLibrary("libarchive");
28 // Replace this with linkSystemLibrary("archive") 25 exe.linkSystemLibrary("libcurl");
29 exe.linkSystemLibraryPkgConfigOnly("libarchive");
30 exe.install(); 26 exe.install();
31 27
32 const run_cmd = exe.run(); 28 const run_cmd = exe.run();
diff --git a/libs/curl b/libs/curl
new file mode 160000
Subproject 7f920ec5be3e4b336303e93bb164c33f1e44022
diff --git a/libs/libarchive b/libs/libarchive
Subproject 188925b4d595d49f5dbc735778bf0438953ce43 Subproject 50747939555b62e3b830c1ec307f746e35b94ec
diff --git a/libs/zelda b/libs/zelda
deleted file mode 160000
Subproject 0b01c87bc07e5214afee9a24be1a92ec8df2b4c
diff --git a/src/Installation.zig b/src/Installation.zig
index 3c056b9..4f7a48d 100644
--- a/src/Installation.zig
+++ b/src/Installation.zig
@@ -1,6 +1,6 @@
1const curl = @import("curl");
1const std = @import("std"); 2const std = @import("std");
2const xdg = @import("xdg"); 3const xdg = @import("xdg");
3const zelda = @import("zelda");
4const zup = @import("zup"); 4const zup = @import("zup");
5 5
6const Allocator = std.mem.Allocator; 6const Allocator = std.mem.Allocator;
@@ -135,23 +135,13 @@ pub fn isInstalled(allocator: Allocator, name: []const u8) !bool {
135pub fn getAvailableList(config: Config) !Installations { 135pub fn getAvailableList(config: Config) !Installations {
136 const allocator = config.allocator; 136 const allocator = config.allocator;
137 137
138 var response = try zelda.get(allocator, "https://ziglang.org/download/index.json"); 138 var json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json");
139 defer response.deinit(); 139 defer allocator.free(json_str);
140
141 if (response.status_code.group() != .success) {
142 std.log.err("HTTP Error while getting Zig download index.json: {}", .{response.status_code});
143 return error.HttpError;
144 }
145
146 if (response.body == null) {
147 std.log.err("No body response while getting Zig download index.json", .{});
148 return error.HttpError;
149 }
150 140
151 var parser = std.json.Parser.init(allocator, false); 141 var parser = std.json.Parser.init(allocator, false);
152 defer parser.deinit(); 142 defer parser.deinit();
153 143
154 var vt = try parser.parse(response.body.?); 144 var vt = try parser.parse(json_str);
155 defer vt.deinit(); 145 defer vt.deinit();
156 146
157 if (vt.root != .Object) { 147 if (vt.root != .Object) {
diff --git a/src/install.zig b/src/install.zig
index 5eb5a29..27db4bb 100644
--- a/src/install.zig
+++ b/src/install.zig
@@ -1,7 +1,7 @@
1const libarchive = @import("libarchive"); 1const libarchive = @import("libarchive");
2const curl = @import("curl");
2const std = @import("std"); 3const std = @import("std");
3const xdg = @import("xdg"); 4const xdg = @import("xdg");
4const zelda = @import("zelda");
5const zup = @import("zup"); 5const zup = @import("zup");
6 6
7const Allocator = std.mem.Allocator; 7const Allocator = std.mem.Allocator;
@@ -51,20 +51,26 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I
51 defer allocator.free(installation_dir); 51 defer allocator.free(installation_dir);
52 52
53 std.log.info("Installing {s}, version {}", .{ name, installation.version }); 53 std.log.info("Installing {s}, version {}", .{ name, installation.version });
54 54 const filename = std.fs.path.basename(installation.url.?);
55 std.log.info("Downloading from {s}...", .{installation.url.?}); 55
56 var response = try zelda.get(allocator, installation.url.?); 56 // TODO: Platform-agnostic tempfile creation
57 defer response.deinit(); 57 var tmpname = try std.fmt.allocPrintZ(allocator, "/tmp/{s}", .{filename});
58 58 defer allocator.free(tmpname);
59 if (response.status_code.group() != .success) { 59
60 std.log.err("HTTP Error: {}", .{response.status_code}); 60 var tmpdir = try std.fs.openDirAbsolute(std.fs.path.dirname(tmpname).?, .{});
61 return error.HttpError; 61 defer tmpdir.close();
62
63 var tmpfile = try tmpdir.createFile(filename, .{});
64 defer {
65 tmpfile.close();
66 std.log.info("Deleting /tmp/{s}...", .{filename});
67 tmpdir.deleteFile(filename) catch |err| {
68 std.log.warn("Failed to delete /tmp/{s}: {}", .{ filename, err });
69 };
62 } 70 }
63 71
64 if (response.body == null) { 72 std.log.info("Downloading to /tmp/{s}...", .{filename});
65 std.log.err("HTTP Error, no body received", .{}); 73 try curl.easyDownloadToFile(&tmpfile, installation.url.?);
66 return error.HttpError;
67 }
68 74
69 std.log.info("Extracting...", .{}); 75 std.log.info("Extracting...", .{});
70 var archive = try ArchiveRead.init(); 76 var archive = try ArchiveRead.init();
@@ -72,7 +78,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I
72 78
73 try archive.supportFilter(.all); 79 try archive.supportFilter(.all);
74 try archive.supportFormat(.all); 80 try archive.supportFormat(.all);
75 try archive.openMemory(response.body.?); 81 try archive.openFilename(tmpname, 10240);
76 82
77 while (try archive.nextHeader()) |entry_c| { 83 while (try archive.nextHeader()) |entry_c| {
78 var entry = entry_c; 84 var entry = entry_c;
diff --git a/src/main.zig b/src/main.zig
index 11aae8f..197a224 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -12,7 +12,6 @@ pub const update = SubCommand(@import("update.zig"));
12pub const version = SubCommand(Version); 12pub const version = SubCommand(Version);
13 13
14const std = @import("std"); 14const std = @import("std");
15const zelda = @import("zelda");
16const zup_config = @import("zup-config"); 15const zup_config = @import("zup-config");
17 16
18const ArgIterator = std.process.ArgIterator; 17const ArgIterator = std.process.ArgIterator;
@@ -25,9 +24,6 @@ pub fn main() !void {
25 const allocator = gpa.allocator(); 24 const allocator = gpa.allocator();
26 defer _ = gpa.deinit(); 25 defer _ = gpa.deinit();
27 26
28 // TODO: Make an issue in zelda mentioning this
29 defer zelda.client.global_connection_cache.deinit();
30
31 var config = try Config.init(allocator); 27 var config = try Config.init(allocator);
32 defer config.deinit(); 28 defer config.deinit();
33 29