From a6dbcffe2ce03f9571da693852181a785942ec4b Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 2 Apr 2023 21:47:15 +0300 Subject: 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. --- .gitmodules | 6 +++--- README.org | 2 +- build.zig | 12 ++++-------- libs/curl | 1 + libs/libarchive | 2 +- libs/zelda | 1 - src/Installation.zig | 18 ++++-------------- src/install.zig | 34 ++++++++++++++++++++-------------- src/main.zig | 4 ---- 9 files changed, 34 insertions(+), 46 deletions(-) create mode 160000 libs/curl delete mode 160000 libs/zelda diff --git a/.gitmodules b/.gitmodules index cfc92e7..a9df803 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,9 @@ [submodule "libs/xdg"] path = libs/xdg url = https://git.sr.ht/~ukko/zig-xdg +[submodule "libs/curl"] + path = libs/curl + url = https://git.sr.ht/~ukko/zig-curl [submodule "libs/libarchive"] path = libs/libarchive url = https://git.sr.ht/~ukko/zig-libarchive -[submodule "libs/zelda"] - path = libs/zelda - 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 @@ ** System libraries - libarchive -- libressl +- libcurl ** Zig version diff --git a/build.zig b/build.zig index bce3dcb..934e826 100644 --- a/build.zig +++ b/build.zig @@ -1,11 +1,10 @@ const builtin = @import("builtin"); const std = @import("std"); -const zelda = @import("libs/zelda/build.zig"); const Builder = std.build.Builder; const SemanticVersion = std.SemanticVersion; -pub fn build(b: *Builder) !void { +pub fn build(b: *Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); @@ -16,17 +15,14 @@ pub fn build(b: *Builder) !void { exe.setTarget(target); exe.setBuildMode(mode); exe.addOptions("zup-config", config); - // TODO[https://github.com/ziglang/zig/issues/13551]: Remove this - exe.linkSystemLibraryPkgConfigOnly("libcrypto"); - try zelda.link(b, exe, target, mode, true); exe.addPackagePath("clap", "libs/clap/clap.zig"); + exe.addPackagePath("curl", "libs/curl/curl.zig"); exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); exe.addPackagePath("zup", "src/main.zig"); exe.linkLibC(); - // TODO[https://github.com/ziglang/zig/issues/13551]: - // Replace this with linkSystemLibrary("archive") - exe.linkSystemLibraryPkgConfigOnly("libarchive"); + exe.linkSystemLibrary("libarchive"); + exe.linkSystemLibrary("libcurl"); exe.install(); const run_cmd = exe.run(); diff --git a/libs/curl b/libs/curl new file mode 160000 index 0000000..7f920ec --- /dev/null +++ b/libs/curl @@ -0,0 +1 @@ +Subproject commit 7f920ec5be3e4b336303e93bb164c33f1e440228 diff --git a/libs/libarchive b/libs/libarchive index 188925b..5074793 160000 --- a/libs/libarchive +++ b/libs/libarchive @@ -1 +1 @@ -Subproject commit 188925b4d595d49f5dbc735778bf0438953ce431 +Subproject commit 50747939555b62e3b830c1ec307f746e35b94ec6 diff --git a/libs/zelda b/libs/zelda deleted file mode 160000 index 0b01c87..0000000 --- a/libs/zelda +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0b01c87bc07e5214afee9a24be1a92ec8df2b4cb 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 @@ +const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); -const zelda = @import("zelda"); const zup = @import("zup"); const Allocator = std.mem.Allocator; @@ -135,23 +135,13 @@ pub fn isInstalled(allocator: Allocator, name: []const u8) !bool { pub fn getAvailableList(config: Config) !Installations { const allocator = config.allocator; - var response = try zelda.get(allocator, "https://ziglang.org/download/index.json"); - defer response.deinit(); - - if (response.status_code.group() != .success) { - std.log.err("HTTP Error while getting Zig download index.json: {}", .{response.status_code}); - return error.HttpError; - } - - if (response.body == null) { - std.log.err("No body response while getting Zig download index.json", .{}); - return error.HttpError; - } + var json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json"); + defer allocator.free(json_str); var parser = std.json.Parser.init(allocator, false); defer parser.deinit(); - var vt = try parser.parse(response.body.?); + var vt = try parser.parse(json_str); defer vt.deinit(); 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 @@ const libarchive = @import("libarchive"); +const curl = @import("curl"); const std = @import("std"); const xdg = @import("xdg"); -const zelda = @import("zelda"); const zup = @import("zup"); const Allocator = std.mem.Allocator; @@ -51,20 +51,26 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I defer allocator.free(installation_dir); std.log.info("Installing {s}, version {}", .{ name, installation.version }); - - std.log.info("Downloading from {s}...", .{installation.url.?}); - var response = try zelda.get(allocator, installation.url.?); - defer response.deinit(); - - if (response.status_code.group() != .success) { - std.log.err("HTTP Error: {}", .{response.status_code}); - return error.HttpError; + const filename = std.fs.path.basename(installation.url.?); + + // TODO: Platform-agnostic tempfile creation + var tmpname = try std.fmt.allocPrintZ(allocator, "/tmp/{s}", .{filename}); + defer allocator.free(tmpname); + + var tmpdir = try std.fs.openDirAbsolute(std.fs.path.dirname(tmpname).?, .{}); + defer tmpdir.close(); + + var tmpfile = try tmpdir.createFile(filename, .{}); + defer { + tmpfile.close(); + std.log.info("Deleting /tmp/{s}...", .{filename}); + tmpdir.deleteFile(filename) catch |err| { + std.log.warn("Failed to delete /tmp/{s}: {}", .{ filename, err }); + }; } - if (response.body == null) { - std.log.err("HTTP Error, no body received", .{}); - return error.HttpError; - } + std.log.info("Downloading to /tmp/{s}...", .{filename}); + try curl.easyDownloadToFile(&tmpfile, installation.url.?); std.log.info("Extracting...", .{}); var archive = try ArchiveRead.init(); @@ -72,7 +78,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I try archive.supportFilter(.all); try archive.supportFormat(.all); - try archive.openMemory(response.body.?); + try archive.openFilename(tmpname, 10240); while (try archive.nextHeader()) |entry_c| { 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")); pub const version = SubCommand(Version); const std = @import("std"); -const zelda = @import("zelda"); const zup_config = @import("zup-config"); const ArgIterator = std.process.ArgIterator; @@ -25,9 +24,6 @@ pub fn main() !void { const allocator = gpa.allocator(); defer _ = gpa.deinit(); - // TODO: Make an issue in zelda mentioning this - defer zelda.client.global_connection_cache.deinit(); - var config = try Config.init(allocator); defer config.deinit(); -- cgit v1.2.3