summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules6
-rw-r--r--README.org2
-rw-r--r--build.zig12
m---------libs/curl0
m---------libs/zelda0
-rw-r--r--src/Installation.zig18
-rw-r--r--src/http.zig23
-rw-r--r--src/install.zig4
-rw-r--r--src/main.zig5
9 files changed, 56 insertions, 14 deletions
diff --git a/.gitmodules b/.gitmodules
index a9df803..cfc92e7 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
10[submodule "libs/libarchive"] 7[submodule "libs/libarchive"]
11 path = libs/libarchive 8 path = libs/libarchive
12 url = https://git.sr.ht/~ukko/zig-libarchive 9 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 427631b..f922886 100644
--- a/README.org
+++ b/README.org
@@ -9,7 +9,7 @@
9** System libraries 9** System libraries
10 10
11- libarchive 11- libarchive
12- libcurl 12- libressl
13 13
14** Zig version 14** Zig version
15 15
diff --git a/build.zig b/build.zig
index fe092db..c99ce32 100644
--- a/build.zig
+++ b/build.zig
@@ -1,10 +1,11 @@
1const builtin = @import("builtin"); 1const builtin = @import("builtin");
2const std = @import("std"); 2const std = @import("std");
3const zelda = @import("libs/zelda/build.zig");
3 4
4const Builder = std.build.Builder; 5const Builder = std.build.Builder;
5const SemanticVersion = std.SemanticVersion; 6const SemanticVersion = std.SemanticVersion;
6 7
7pub fn build(b: *Builder) void { 8pub fn build(b: *Builder) !void {
8 const target = b.standardTargetOptions(.{}); 9 const target = b.standardTargetOptions(.{});
9 const mode = b.standardReleaseOptions(); 10 const mode = b.standardReleaseOptions();
10 11
@@ -15,14 +16,17 @@ pub fn build(b: *Builder) void {
15 exe.setTarget(target); 16 exe.setTarget(target);
16 exe.setBuildMode(mode); 17 exe.setBuildMode(mode);
17 exe.addOptions("zup-config", config); 18 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);
18 exe.addPackagePath("clap", "libs/clap/clap.zig"); 22 exe.addPackagePath("clap", "libs/clap/clap.zig");
19 exe.addPackagePath("curl", "libs/curl/curl.zig");
20 exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); 23 exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig");
21 exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); 24 exe.addPackagePath("xdg", "libs/xdg/xdg.zig");
22 exe.addPackagePath("zup", "src/main.zig"); 25 exe.addPackagePath("zup", "src/main.zig");
23 exe.linkLibC(); 26 exe.linkLibC();
24 exe.linkSystemLibrary("libarchive"); 27 // TODO[https://github.com/ziglang/zig/issues/13551]:
25 exe.linkSystemLibrary("libcurl"); 28 // Replace this with linkSystemLibrary("archive")
29 exe.linkSystemLibraryPkgConfigOnly("libarchive");
26 exe.install(); 30 exe.install();
27 31
28 const run_cmd = exe.run(); 32 const run_cmd = exe.run();
diff --git a/libs/curl b/libs/curl
deleted file mode 160000
Subproject 7f920ec5be3e4b336303e93bb164c33f1e44022
diff --git a/libs/zelda b/libs/zelda
new file mode 160000
Subproject 349513eedb83a69989f5ca0616e69f841cc516a
diff --git a/src/Installation.zig b/src/Installation.zig
index 4f7a48d..3c056b9 100644
--- a/src/Installation.zig
+++ b/src/Installation.zig
@@ -1,6 +1,6 @@
1const curl = @import("curl");
2const std = @import("std"); 1const std = @import("std");
3const xdg = @import("xdg"); 2const 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,13 +135,23 @@ 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 json_str = try curl.easyDownload(allocator, "https://ziglang.org/download/index.json"); 138 var response = try zelda.get(allocator, "https://ziglang.org/download/index.json");
139 defer allocator.free(json_str); 139 defer response.deinit();
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 }
140 150
141 var parser = std.json.Parser.init(allocator, false); 151 var parser = std.json.Parser.init(allocator, false);
142 defer parser.deinit(); 152 defer parser.deinit();
143 153
144 var vt = try parser.parse(json_str); 154 var vt = try parser.parse(response.body.?);
145 defer vt.deinit(); 155 defer vt.deinit();
146 156
147 if (vt.root != .Object) { 157 if (vt.root != .Object) {
diff --git a/src/http.zig b/src/http.zig
new file mode 100644
index 0000000..bb3b3ac
--- /dev/null
+++ b/src/http.zig
@@ -0,0 +1,23 @@
1const std = @import("std");
2const zelda = @import("zelda");
3
4const Allocator = std.mem.Allocator;
5const File = std.fs.File;
6
7// TODO: zelda should be able to do this internally so I wouldn't have to allocate memory for the
8// file
9pub fn downloadToFile(allocator: Allocator, file: *File, url: []const u8) !void {
10 var response = try zelda.get(allocator, url);
11 defer response.deinit();
12
13 if (response.status_code.group() != .success) {
14 std.log.err("HTTP Error: {}", .{response.status_code});
15 return error.HttpError;
16 }
17
18 if (response.body) |body| {
19 try file.writer().writeAll(body);
20 } else {
21 std.log.warn("Downloaded nothing from {s}...", .{url});
22 }
23}
diff --git a/src/install.zig b/src/install.zig
index 27db4bb..47b804c 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");
3const std = @import("std"); 2const std = @import("std");
4const xdg = @import("xdg"); 3const 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;
@@ -70,7 +70,7 @@ pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: I
70 } 70 }
71 71
72 std.log.info("Downloading to /tmp/{s}...", .{filename}); 72 std.log.info("Downloading to /tmp/{s}...", .{filename});
73 try curl.easyDownloadToFile(&tmpfile, installation.url.?); 73 try zup.http.downloadToFile(allocator, &tmpfile, installation.url.?);
74 74
75 std.log.info("Extracting...", .{}); 75 std.log.info("Extracting...", .{});
76 var archive = try ArchiveRead.init(); 76 var archive = try ArchiveRead.init();
diff --git a/src/main.zig b/src/main.zig
index 197a224..56b1b77 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2,6 +2,7 @@ pub const Config = @import("Config.zig");
2pub const Installation = @import("Installation.zig"); 2pub const Installation = @import("Installation.zig");
3pub const Installations = Installation.Installations; 3pub const Installations = Installation.Installations;
4pub const SubCommand = @import("subcommand.zig").SubCommand; 4pub const SubCommand = @import("subcommand.zig").SubCommand;
5pub const http = @import("http.zig");
5 6
6pub const help = SubCommand(Help); 7pub const help = SubCommand(Help);
7pub const install = SubCommand(@import("install.zig")); 8pub const install = SubCommand(@import("install.zig"));
@@ -12,6 +13,7 @@ pub const update = SubCommand(@import("update.zig"));
12pub const version = SubCommand(Version); 13pub const version = SubCommand(Version);
13 14
14const std = @import("std"); 15const std = @import("std");
16const zelda = @import("zelda");
15const zup_config = @import("zup-config"); 17const zup_config = @import("zup-config");
16 18
17const ArgIterator = std.process.ArgIterator; 19const ArgIterator = std.process.ArgIterator;
@@ -24,6 +26,9 @@ pub fn main() !void {
24 const allocator = gpa.allocator(); 26 const allocator = gpa.allocator();
25 defer _ = gpa.deinit(); 27 defer _ = gpa.deinit();
26 28
29 // TODO: Make an issue in zelda mentioning this
30 defer zelda.client.global_connection_cache.deinit();
31
27 var config = try Config.init(allocator); 32 var config = try Config.init(allocator);
28 defer config.deinit(); 33 defer config.deinit();
29 34