Skip to content

Commit b19de24

Browse files
committed
feat: windows installer properly bootstraps zigverm
1 parent 54299f8 commit b19de24

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/zigverm-setup/main.zig

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,27 @@ pub fn main() !void {
117117
var bin_dir = try zigverm_dir.openDir("bin", .{});
118118
defer bin_dir.close();
119119

120-
const path_in_zip = try std.mem.join(allocator, "/", &.{ dl_filename, "zigverm.exe" });
121-
122-
if (zipfile.getFileByName(path_in_zip)) |*entry| {
123-
const out_filename = std.fs.path.basename(path_in_zip);
124-
var file = try bin_dir.createFile(out_filename, .{ .truncate = true });
125-
var fwriter = file.writer(&.{});
126-
const writer = &fwriter.interface;
127-
defer file.close();
128-
129-
var entry_ptr = @constCast(entry);
130-
131-
// Fix for error: expected 'std.io.Writer(std.fs.File,std.os.WriteError,std.fs.File.write)', found 'std.fs.File.Writer'
132-
// The type returned by file.writer() is usually correct.
133-
// Let's check entry.decompressWriter signature.
134-
try entry_ptr.decompressWriter(writer);
135-
std.log.info("Extracted {s} to bin/", .{out_filename});
136-
} else {
137-
std.log.err("Could not find {s} in archive", .{path_in_zip});
138-
}
120+
const zigverm_path = try std.mem.join(allocator, "/", &.{ dl_filename, "zigverm.exe" });
121+
const zig_path = try std.mem.join(allocator, "/", &.{ dl_filename, "zig.exe" });
122+
123+
try writeFilesFromZip(bin_dir, zipfile, zigverm_path);
124+
try writeFilesFromZip(bin_dir, zipfile, zig_path);
125+
126+
std.log.info("Installed zigverm successfully", .{});
127+
}
128+
129+
fn writeFilesFromZip(bin_dir: std.fs.Dir, zipFile: ZipArchive, filename: []const u8) !void {
130+
const entry = zipFile.getFileByName(filename) orelse unreachable;
131+
const out_filename = std.fs.path.basename(filename);
132+
var file = try bin_dir.createFile(out_filename, .{ .truncate = true });
133+
var fwriter = file.writer(&.{});
134+
const writer = &fwriter.interface;
135+
defer file.close();
136+
var entry_ptr = @constCast(&entry);
137+
try entry_ptr.decompressWriter(writer);
139138
}
140139

141-
pub fn download_tarball(alloc: std.mem.Allocator, client: *Client, io: Io, tb_url: []const u8, tb_writer: *std.fs.File.Writer, tarball_size: u64, total_size: usize) !void {
140+
fn download_tarball(alloc: std.mem.Allocator, client: *Client, io: Io, tb_url: []const u8, tb_writer: *std.fs.File.Writer, tarball_size: u64, total_size: usize) !void {
142141
std.log.info("Downloading {s}", .{tb_url});
143142
const tarball_uri = try std.Uri.parse(tb_url);
144143

0 commit comments

Comments
 (0)