Skip to content

Commit

Permalink
Merge pull request #50 from hendriknielaender/config
Browse files Browse the repository at this point in the history
chore: add zvm config file
  • Loading branch information
hendriknielaender authored Jul 23, 2024
2 parents 1ddb7fc + 09a4922 commit 14541d9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CrossTargetInfo = struct {
name: []const u8,
};
// Semantic version of your application
const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 3 };
const version = std.SemanticVersion{ .major = 0, .minor = 4, .patch = 4 };

const min_zig_string = "0.13.0";

Expand Down
1 change: 1 addition & 0 deletions src/config.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const download_manifest_url: []const u8 = "https://ziglang.org/download/index.json";
14 changes: 7 additions & 7 deletions src/extract.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ pub fn extract_zip_dir(out_dir: std.fs.Dir, file: std.fs.File) !void {

const allocator = arena.allocator();
const tmp_path = try tools.get_zvm_path_segment(allocator, "tmpdir");
defer std.fs.delete_dir_absolute(tmp_path) catch unreachable;
defer std.fs.deleteDirAbsolute(tmp_path) catch unreachable;

try std.fs.make_dir_absolute(tmp_path);
var tmp_dir = try std.fs.open_dir_absolute(tmp_path, .{ .iterate = true });
try std.fs.makeDirAbsolute(tmp_path);
var tmp_dir = try std.fs.openDirAbsolute(tmp_path, .{ .iterate = true });

try std.zip.extract(tmp_dir, file.seekable_stream(), .{});
try std.zip.extract(tmp_dir, file.seekableStream(), .{});

var iterate = tmp_dir.iterate();
var sub_dir = blk: {
const entry = try iterate.next() orelse return error.NotFound;
break :blk try tmp_dir.open_dir(entry.name, .{ .iterate = true });
break :blk try tmp_dir.openDir(entry.name, .{ .iterate = true });
};
defer sub_dir.close();

const sub_path = try sub_dir.realpath_alloc(allocator, "");
defer std.fs.delete_dir_absolute(sub_path) catch unreachable;
const sub_path = try sub_dir.realpathAlloc(allocator, "");
defer std.fs.deleteDirAbsolute(sub_path) catch unreachable;

var sub_iterate = sub_dir.iterate();
while (try sub_iterate.next()) |entry| {
Expand Down
5 changes: 2 additions & 3 deletions src/install.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const config = @import("config.zig");
const hash = @import("hash.zig");
const download = @import("download.zig");
const architecture = @import("architecture.zig");
Expand Down Expand Up @@ -28,10 +29,8 @@ const Error = error{
ContentMissing,
};

const url = "https://ziglang.org/download/index.json";

fn fetch_version_data(allocator: Allocator, requested_version: []const u8, sub_key: []const u8) !?Version {
const uri = std.Uri.parse(url) catch unreachable;
const uri = std.Uri.parse(config.download_manifest_url) catch unreachable;

var client = std.http.Client{ .allocator = allocator };
defer client.deinit();
Expand Down
6 changes: 2 additions & 4 deletions src/versions.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const std = @import("std");
const config = @import("config.zig");

// TODO: The URL should be stored in a separate config file.
const url = "https://ziglang.org/download/index.json";

const uri = std.Uri.parse(url) catch unreachable;
const uri = std.Uri.parse(config.download_manifest_url) catch unreachable;

pub const VersionList = struct {
const List = std.ArrayList([]const u8);
Expand Down

0 comments on commit 14541d9

Please sign in to comment.