Skip to content

Changes for Zig v0.14 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: goto-bus-stop/setup-zig@v2
- uses: mlugg/setup-zig@v2
with:
version: 0.12.0
version: "0.14.1"
- run: zig fmt --check *.zig src/*.zig

install-sh:
Expand All @@ -38,8 +38,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v1
- uses: mlugg/setup-zig@v2
with:
version: 0.12.0
version: "0.14.1"
- run: zig build -Dtarget=${{ matrix.target }}
- run: zig build test
42 changes: 21 additions & 21 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const zip = b.dependency("zip", .{});

const common = b.createModule(.{ .root_source_file = b.path("src/common/root.zig") });
const default_os = target.result.os.tag;
if (default_os.isBSD() or default_os.isDarwin() or default_os == std.Target.Os.Tag.linux) {
Expand All @@ -15,23 +13,25 @@ pub fn build(b: *std.Build) !void {

const strip = if (optimize == std.builtin.OptimizeMode.ReleaseSafe) true else null;

const zigverm = b.addExecutable(.{
.name = "zigverm",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});
const zig = b.addExecutable(.{
.name = "zig",
.root_source_file = b.path("src/zig//main.zig"),
const zigverm = b.addExecutable(
.{ .name = "zigverm", .root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}) },
);
zigverm.subsystem = .Console;
const zig = b.addExecutable(.{ .name = "zig", .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
});
}) });
zig.subsystem = .Console;

zigverm.root_module.addImport("common", common);
zigverm.root_module.addImport("zip", zip.module("zip"));
// zigverm.root_module.addImport("zip", zip.module("zip"));
zig.root_module.addImport("common", common);
b.installArtifact(zigverm);
b.installArtifact(zig);
Expand Down Expand Up @@ -59,25 +59,25 @@ fn addExeRunner(b: *std.Build, zigverm: *Compile, zig: *Compile) void {
}

fn addTestRunner(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const zigverm_tests = b.addTest(.{
const zigverm_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
}) });
const run_zigverm_tests = b.addRunArtifact(zigverm_tests);

const zig_tests = b.addTest(.{
const zig_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
});
}) });
const run_zig_tests = b.addRunArtifact(zig_tests);

const common_tests = b.addTest(.{
.root_source_file = b.path("src/common/tests.zig"),
const common_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/zig/main.zig"),
.target = target,
.optimize = optimize,
});
}) });
const default_os = target.result.os.tag;
if (default_os.isBSD() or default_os.isDarwin() or default_os == std.Target.Os.Tag.linux) {
common_tests.linkLibC();
Expand Down
10 changes: 2 additions & 8 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
.{
.name = "zigverm",
.name = .zigverm,
.version = "0.6.2",
.minimum_zig_version = "0.11.0",

.dependencies = .{
.zip = .{
.url = "git+https://github.com/AMythicDev/zip.zig#b1f8fe858943cb14eb333c7424bb23ae002ee7a1",
.hash = "1220130f0297f2c4cca318c6383758e5c1632467556147347af2c6a1214cab7a6ba4",
},
},
.fingerprint = 0xffdf55ceb1c7efde,

.paths = .{
"build.zig",
Expand Down
2 changes: 1 addition & 1 deletion src/common/paths.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn home_dir(alloc: Allocator) ![]const u8 {
} else |_| {
switch (default_os) {
OsTag.linux, OsTag.openbsd => {
return std.mem.span(std.c.getpwuid(getuid()).?.pw_dir.?);
return std.mem.span(std.c.getpwuid(getuid()).?.dir.?);
},
else => {
@panic("Cannot determine home directory");
Expand Down
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn installed_versions(alloc: Allocator, cp: CommonPaths) ![][]const u8 {
var versions = std.ArrayList([]const u8).init(alloc);
while (try iter.next()) |i| {
if (!utils.check_install_name(i.name)) continue;
var components = std.mem.split(u8, i.name[4..], "-");
var components = std.mem.splitScalar(u8, i.name[4..], '-');
_ = components.next();
_ = components.next();
const version = components.next() orelse unreachable;
Expand All @@ -211,21 +211,21 @@ fn installed_versions(alloc: Allocator, cp: CommonPaths) ![][]const u8 {
return versions.items;
}

fn get_version_from_exe(alloc: Allocator, release_name: []const u8) !std.ArrayList(u8) {
fn get_version_from_exe(alloc: Allocator, release_name: []const u8) !std.ArrayListUnmanaged(u8) {
var executable = [2][]const u8{ undefined, "version" };
executable[0] = try std.fs.path.join(alloc, &.{
common.paths.CommonPaths.get_zigverm_root(),
"installs/",
release_name,
"zig",
});
var version = std.ArrayList(u8).init(alloc);
var stderr = std.ArrayList(u8).init(alloc);
var version: std.ArrayListUnmanaged(u8) = .empty;
var stderr: std.ArrayListUnmanaged(u8) = .empty;
var child = std.process.Child.init(&executable, alloc);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;
try child.spawn();
try child.collectOutput(&version, &stderr, 256);
try child.collectOutput(alloc, &version, &stderr, 256);
_ = try child.wait();
_ = version.pop();

Expand Down
28 changes: 13 additions & 15 deletions src/update-self.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const File = std.fs.File;
const BufferedReader = std.io.BufferedReader;
const BufferedWriter = std.io.BufferedWriter;
const Allocator = std.mem.Allocator;
const ZipArchive = @import("zip").read.ZipArchive;

const DownloadTarball = struct {
filename: []const u8,
Expand Down Expand Up @@ -72,20 +71,19 @@ pub fn update_self(alloc: Allocator, cp: CommonPaths) !void {
try install.download_tarball(alloc, &client, download_tarball.url, &download_tarball.writer.?, download_tarball.file_size, download_tarball.actual_size);
try download_tarball.file_handle.?.seekTo(0);
const bin_dir = try cp.zigverm_root.openDir("bin/", .{});

const zipfile = try ZipArchive.openFromStreamSource(alloc, @constCast(&std.io.StreamSource{ .file = download_tarball.file_handle.? }));

var m_iter = zipfile.members.iterator();
while (m_iter.next()) |i| {
var entry = i.value_ptr.*;
if (entry.is_dir) continue;

const filename = std.fs.path.basename(i.key_ptr.*);
const file = try bin_dir.createFile(filename, .{ .truncate = true, .lock = .shared });
var file_writer = std.io.bufferedWriter(file.writer());
defer file.close();

_ = try entry.decompressWriter(&file_writer.writer());
_ = bin_dir;

var src = @constCast(&std.io.StreamSource{ .file = download_tarball.file_handle.? }).seekableStream();
var m_iter = try std.zip.Iterator(@TypeOf(&src)).init(&src);

while (try m_iter.next()) |i| {
std.debug.print("{any}", .{i});
// const filename = std.fs.path.basename(i.key_ptr.*);
// const file = try bin_dir.createFile(filename, .{ .truncate = true, .lock = .shared });
// var file_writer = std.io.bufferedWriter(file.writer());
// defer file.close();
//
// _ = try entry.decompressWriter(&file_writer.writer());
}
std.debug.print("zigverm updated successfully", .{});
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn check_install_name(name: []const u8) bool {
if (!std.mem.startsWith(u8, name, "zig-")) {
return false;
}
var components = std.mem.split(u8, name[4..], "-");
var components = std.mem.splitScalar(u8, name[4..], '-');

const arch = components.next();
const os = components.next();
Expand All @@ -36,14 +36,14 @@ pub fn check_install_name(name: []const u8) bool {
}

pub inline fn is_valid_arch_os(arch: ?[]const u8, os: ?[]const u8) bool {
const arch_fields = @typeInfo(std.Target.Cpu.Arch).Enum.fields;
const arch_fields = @typeInfo(std.Target.Cpu.Arch).@"enum".fields;
comptime var archs: [arch_fields.len][]const u8 = undefined;
comptime {
for (arch_fields, 0..) |a, i| {
archs[i] = a.name;
}
}
const osfields = @typeInfo(std.Target.Os.Tag).Enum.fields;
const osfields = @typeInfo(std.Target.Os.Tag).@"enum".fields;
comptime var oses: [osfields.len][]const u8 = undefined;
comptime {
for (osfields, 0..) |o, i| {
Expand Down