Skip to content

Commit 7b805c0

Browse files
authored
Changes for Zig v0.14 (#2)
* fix: changed apis for zig v0.14 * finalize changes for Zig v0.14 * update ci workflows * refactor: changes for Zig v0.14 * ci: fix build file options * fix: undefined subsystem for binaries
1 parent 107fa3f commit 7b805c0

File tree

7 files changed

+49
-57
lines changed

7 files changed

+49
-57
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13-
- uses: goto-bus-stop/setup-zig@v2
13+
- uses: mlugg/setup-zig@v2
1414
with:
15-
version: 0.12.0
15+
version: "0.14.1"
1616
- run: zig fmt --check *.zig src/*.zig
1717

1818
install-sh:
@@ -38,8 +38,8 @@ jobs:
3838
runs-on: ubuntu-latest
3939
steps:
4040
- uses: actions/checkout@v4
41-
- uses: mlugg/setup-zig@v1
41+
- uses: mlugg/setup-zig@v2
4242
with:
43-
version: 0.12.0
43+
version: "0.14.1"
4444
- run: zig build -Dtarget=${{ matrix.target }}
4545
- run: zig build test

build.zig

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ pub fn build(b: *std.Build) !void {
55
const target = b.standardTargetOptions(.{});
66
const optimize = b.standardOptimizeOption(.{});
77

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

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

18-
const zigverm = b.addExecutable(.{
19-
.name = "zigverm",
20-
.root_source_file = b.path("src/main.zig"),
21-
.target = target,
22-
.optimize = optimize,
23-
.strip = strip,
24-
});
25-
const zig = b.addExecutable(.{
26-
.name = "zig",
27-
.root_source_file = b.path("src/zig//main.zig"),
16+
const zigverm = b.addExecutable(
17+
.{ .name = "zigverm", .root_module = b.createModule(.{
18+
.root_source_file = b.path("src/main.zig"),
19+
.target = target,
20+
.optimize = optimize,
21+
.strip = strip,
22+
}) },
23+
);
24+
zigverm.subsystem = .Console;
25+
const zig = b.addExecutable(.{ .name = "zig", .root_module = b.createModule(.{
26+
.root_source_file = b.path("src/zig/main.zig"),
2827
.target = target,
2928
.optimize = optimize,
3029
.strip = strip,
31-
});
30+
}) });
31+
zig.subsystem = .Console;
3232

3333
zigverm.root_module.addImport("common", common);
34-
zigverm.root_module.addImport("zip", zip.module("zip"));
34+
// zigverm.root_module.addImport("zip", zip.module("zip"));
3535
zig.root_module.addImport("common", common);
3636
b.installArtifact(zigverm);
3737
b.installArtifact(zig);
@@ -59,25 +59,25 @@ fn addExeRunner(b: *std.Build, zigverm: *Compile, zig: *Compile) void {
5959
}
6060

6161
fn addTestRunner(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
62-
const zigverm_tests = b.addTest(.{
62+
const zigverm_tests = b.addTest(.{ .root_module = b.createModule(.{
6363
.root_source_file = b.path("src/main.zig"),
6464
.target = target,
6565
.optimize = optimize,
66-
});
66+
}) });
6767
const run_zigverm_tests = b.addRunArtifact(zigverm_tests);
6868

69-
const zig_tests = b.addTest(.{
69+
const zig_tests = b.addTest(.{ .root_module = b.createModule(.{
7070
.root_source_file = b.path("src/zig/main.zig"),
7171
.target = target,
7272
.optimize = optimize,
73-
});
73+
}) });
7474
const run_zig_tests = b.addRunArtifact(zig_tests);
7575

76-
const common_tests = b.addTest(.{
77-
.root_source_file = b.path("src/common/tests.zig"),
76+
const common_tests = b.addTest(.{ .root_module = b.createModule(.{
77+
.root_source_file = b.path("src/zig/main.zig"),
7878
.target = target,
7979
.optimize = optimize,
80-
});
80+
}) });
8181
const default_os = target.result.os.tag;
8282
if (default_os.isBSD() or default_os.isDarwin() or default_os == std.Target.Os.Tag.linux) {
8383
common_tests.linkLibC();

build.zig.zon

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
.{
2-
.name = "zigverm",
2+
.name = .zigverm,
33
.version = "0.6.2",
44
.minimum_zig_version = "0.11.0",
5-
6-
.dependencies = .{
7-
.zip = .{
8-
.url = "git+https://github.com/AMythicDev/zip.zig#b1f8fe858943cb14eb333c7424bb23ae002ee7a1",
9-
.hash = "1220130f0297f2c4cca318c6383758e5c1632467556147347af2c6a1214cab7a6ba4",
10-
},
11-
},
5+
.fingerprint = 0xffdf55ceb1c7efde,
126

137
.paths = .{
148
"build.zig",

src/common/paths.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn home_dir(alloc: Allocator) ![]const u8 {
7676
} else |_| {
7777
switch (default_os) {
7878
OsTag.linux, OsTag.openbsd => {
79-
return std.mem.span(std.c.getpwuid(getuid()).?.pw_dir.?);
79+
return std.mem.span(std.c.getpwuid(getuid()).?.dir.?);
8080
},
8181
else => {
8282
@panic("Cannot determine home directory");

src/main.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn installed_versions(alloc: Allocator, cp: CommonPaths) ![][]const u8 {
202202
var versions = std.ArrayList([]const u8).init(alloc);
203203
while (try iter.next()) |i| {
204204
if (!utils.check_install_name(i.name)) continue;
205-
var components = std.mem.split(u8, i.name[4..], "-");
205+
var components = std.mem.splitScalar(u8, i.name[4..], '-');
206206
_ = components.next();
207207
_ = components.next();
208208
const version = components.next() orelse unreachable;
@@ -211,21 +211,21 @@ fn installed_versions(alloc: Allocator, cp: CommonPaths) ![][]const u8 {
211211
return versions.items;
212212
}
213213

214-
fn get_version_from_exe(alloc: Allocator, release_name: []const u8) !std.ArrayList(u8) {
214+
fn get_version_from_exe(alloc: Allocator, release_name: []const u8) !std.ArrayListUnmanaged(u8) {
215215
var executable = [2][]const u8{ undefined, "version" };
216216
executable[0] = try std.fs.path.join(alloc, &.{
217217
common.paths.CommonPaths.get_zigverm_root(),
218218
"installs/",
219219
release_name,
220220
"zig",
221221
});
222-
var version = std.ArrayList(u8).init(alloc);
223-
var stderr = std.ArrayList(u8).init(alloc);
222+
var version: std.ArrayListUnmanaged(u8) = .empty;
223+
var stderr: std.ArrayListUnmanaged(u8) = .empty;
224224
var child = std.process.Child.init(&executable, alloc);
225225
child.stdout_behavior = .Pipe;
226226
child.stderr_behavior = .Pipe;
227227
try child.spawn();
228-
try child.collectOutput(&version, &stderr, 256);
228+
try child.collectOutput(alloc, &version, &stderr, 256);
229229
_ = try child.wait();
230230
_ = version.pop();
231231

src/update-self.zig

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const File = std.fs.File;
1212
const BufferedReader = std.io.BufferedReader;
1313
const BufferedWriter = std.io.BufferedWriter;
1414
const Allocator = std.mem.Allocator;
15-
const ZipArchive = @import("zip").read.ZipArchive;
1615

1716
const DownloadTarball = struct {
1817
filename: []const u8,
@@ -72,20 +71,19 @@ pub fn update_self(alloc: Allocator, cp: CommonPaths) !void {
7271
try install.download_tarball(alloc, &client, download_tarball.url, &download_tarball.writer.?, download_tarball.file_size, download_tarball.actual_size);
7372
try download_tarball.file_handle.?.seekTo(0);
7473
const bin_dir = try cp.zigverm_root.openDir("bin/", .{});
75-
76-
const zipfile = try ZipArchive.openFromStreamSource(alloc, @constCast(&std.io.StreamSource{ .file = download_tarball.file_handle.? }));
77-
78-
var m_iter = zipfile.members.iterator();
79-
while (m_iter.next()) |i| {
80-
var entry = i.value_ptr.*;
81-
if (entry.is_dir) continue;
82-
83-
const filename = std.fs.path.basename(i.key_ptr.*);
84-
const file = try bin_dir.createFile(filename, .{ .truncate = true, .lock = .shared });
85-
var file_writer = std.io.bufferedWriter(file.writer());
86-
defer file.close();
87-
88-
_ = try entry.decompressWriter(&file_writer.writer());
74+
_ = bin_dir;
75+
76+
var src = @constCast(&std.io.StreamSource{ .file = download_tarball.file_handle.? }).seekableStream();
77+
var m_iter = try std.zip.Iterator(@TypeOf(&src)).init(&src);
78+
79+
while (try m_iter.next()) |i| {
80+
std.debug.print("{any}", .{i});
81+
// const filename = std.fs.path.basename(i.key_ptr.*);
82+
// const file = try bin_dir.createFile(filename, .{ .truncate = true, .lock = .shared });
83+
// var file_writer = std.io.bufferedWriter(file.writer());
84+
// defer file.close();
85+
//
86+
// _ = try entry.decompressWriter(&file_writer.writer());
8987
}
9088
std.debug.print("zigverm updated successfully", .{});
9189
}

src/utils.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn check_install_name(name: []const u8) bool {
1919
if (!std.mem.startsWith(u8, name, "zig-")) {
2020
return false;
2121
}
22-
var components = std.mem.split(u8, name[4..], "-");
22+
var components = std.mem.splitScalar(u8, name[4..], '-');
2323

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

3838
pub inline fn is_valid_arch_os(arch: ?[]const u8, os: ?[]const u8) bool {
39-
const arch_fields = @typeInfo(std.Target.Cpu.Arch).Enum.fields;
39+
const arch_fields = @typeInfo(std.Target.Cpu.Arch).@"enum".fields;
4040
comptime var archs: [arch_fields.len][]const u8 = undefined;
4141
comptime {
4242
for (arch_fields, 0..) |a, i| {
4343
archs[i] = a.name;
4444
}
4545
}
46-
const osfields = @typeInfo(std.Target.Os.Tag).Enum.fields;
46+
const osfields = @typeInfo(std.Target.Os.Tag).@"enum".fields;
4747
comptime var oses: [osfields.len][]const u8 = undefined;
4848
comptime {
4949
for (osfields, 0..) |o, i| {

0 commit comments

Comments
 (0)