Skip to content

Commit

Permalink
Merge pull request #41 from hendriknielaender/0.13.0
Browse files Browse the repository at this point in the history
build: upgrade to zig 0.13.0
  • Loading branch information
hendriknielaender authored Jun 8, 2024
2 parents 6bb24a2 + ac26da9 commit c6ab2c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ zvm --version # Display zvm version
### Compatibility Notes
Zig is in active development and the APIs can change frequently, making it challenging to support every dev build. This project currently aims to be compatible with stable, non-development builds to provide a consistent experience for the users.

***Supported Version***: As of now, zvm is tested and supported on Zig version ***0.12.0***.
***Supported Version***: As of now, zvm is tested and supported on Zig version ***0.13.0***.

### Contributing
Contributions, issues, and feature requests are welcome!
Expand Down
8 changes: 4 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CrossTargetInfo = struct {
// Semantic version of your application
const version = std.SemanticVersion{ .major = 0, .minor = 3, .patch = 3 };

const min_zig_string = "0.12.0";
const min_zig_string = "0.13.0";

const Build = blk: {
const current_zig = builtin.zig_version;
Expand All @@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {

const exe = b.addExecutable(.{
.name = "zvm",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.target = target,
.optimize = .ReleaseFast,
.version = version,
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn build(b: *std.Build) void {
const t = resolved_target.result;
const rel_exe = b.addExecutable(.{
.name = "zvm",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.target = resolved_target,
.optimize = .ReleaseSafe,
.strip = true,
Expand All @@ -94,7 +94,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/main.zig" } },
.target = target,
.optimize = optimize,
});
Expand Down
2 changes: 1 addition & 1 deletion src/alias.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn retrieveZigVersion(allocator: std.mem.Allocator) ![]u8 {
const symlinkPath = try std.fs.path.join(allocator, &[_][]const u8{ userHome, ".zm", "current" });
defer allocator.free(symlinkPath);

var childProcess = std.ChildProcess.init(&[_][]const u8{ "zig", "version" }, allocator);
var childProcess = std.process.Child.init(&[_][]const u8{ "zig", "version" }, allocator);

childProcess.stdin_behavior = .Close;
childProcess.stdout_behavior = .Pipe;
Expand Down
19 changes: 6 additions & 13 deletions src/download.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ fn getZvmPathSegment(segment: []const u8) ![]u8 {

pub fn content(allocator: std.mem.Allocator, version: []const u8, url: []const u8) !?[32]u8 {
// Initialize the Progress structure
var progress = Progress{
.terminal = std.io.getStdErr(),
.supports_ansi_escape_codes = true,
};
const root_node = Progress.start(.{
.root_name = "",
.estimated_total_items = 4,
});

var root_node = progress.start("", 4);
defer root_node.end();

// Ensure version directory exists before any operation
Expand Down Expand Up @@ -70,11 +69,9 @@ pub fn content(allocator: std.mem.Allocator, version: []const u8, url: []const u
std.debug.print("→ Version {s} is not installed. Beginning download...\n", .{version});
}

const computedHash = try downloadAndExtract(allocator, uri, version_path, version, root_node, &progress);
const computedHash = try downloadAndExtract(allocator, uri, version_path, version, root_node);

var set_version_node = root_node.start("Setting Version", 1);
set_version_node.activate();
progress.refresh();
try alias.setZigVersion(version);
set_version_node.end();

Expand All @@ -94,7 +91,7 @@ fn confirmUserChoice() bool {
return std.ascii.toLower(buffer[0]) == 'y';
}

fn downloadAndExtract(allocator: std.mem.Allocator, uri: std.Uri, version_path: []const u8, version: []const u8, root_node: *std.Progress.Node, progress: *std.Progress) ![32]u8 {
fn downloadAndExtract(allocator: std.mem.Allocator, uri: std.Uri, version_path: []const u8, version: []const u8, root_node: std.Progress.Node) ![32]u8 {
var client = std.http.Client{ .allocator = allocator };
defer client.deinit();

Expand Down Expand Up @@ -124,7 +121,6 @@ fn downloadAndExtract(allocator: std.mem.Allocator, uri: std.Uri, version_path:
const downloadMessage = try std.fmt.allocPrint(allocator, "Downloading Zig version {s} for platform {s}...", .{ version, platform });
defer allocator.free(downloadMessage);
var download_node = root_node.start(downloadMessage, totalSize);
download_node.activate();

const file_stream = try zvm_dir.createFile(file_name, .{});
defer file_stream.close();
Expand All @@ -141,7 +137,6 @@ fn downloadAndExtract(allocator: std.mem.Allocator, uri: std.Uri, version_path:
downloadedBytes += bytes_read;

download_node.setCompletedItems(downloadedBytes);
progress.refresh();

sha256.update(buffer[0..bytes_read]);

Expand All @@ -151,8 +146,6 @@ fn downloadAndExtract(allocator: std.mem.Allocator, uri: std.Uri, version_path:
download_node.end();

var extract_node = root_node.start("Extracting", 1);
extract_node.activate();
progress.refresh();
const c_allocator = std.heap.c_allocator;

// ~/.zm/versions/zig-macos-x86_64-0.10.0.tar.xz
Expand Down

0 comments on commit c6ab2c6

Please sign in to comment.