Skip to content

Commit 9e682e8

Browse files
committed
update to zig 0.11.0
1 parent 8f3d9cb commit 9e682e8

13 files changed

+62
-63
lines changed

build.zig

+15-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const EXECUTABLES = .{
1616

1717
fn addGraphicsMagick(thing: anytype) void {
1818
thing.linkLibC();
19-
thing.addIncludePath("/usr/include");
20-
thing.addIncludePath("/usr/include/GraphicsMagick");
19+
thing.addIncludePath(.{ .path = "/usr/include" });
20+
thing.addIncludePath(.{ .path = "/usr/include/GraphicsMagick" });
2121
}
2222

2323
pub fn build(b: *std.build.Builder) !void {
@@ -57,20 +57,22 @@ pub fn build(b: *std.build.Builder) !void {
5757

5858
deps.addAllTo(single_exe);
5959
addGraphicsMagick(single_exe);
60+
b.installArtifact(single_exe);
6061

6162
const hardlink_install = try b.allocator.create(CustomHardLinkStep);
63+
64+
var hardlink_step = std.build.Step.init(.{
65+
.id = .custom,
66+
.name = "link the utils",
67+
.owner = b,
68+
.makeFn = CustomHardLinkStep.make,
69+
});
6270
hardlink_install.* = .{
6371
.builder = b,
64-
.step = std.build.Step.init(.{
65-
.id = .custom,
66-
.name = "link the utils",
67-
.owner = b,
68-
.makeFn = CustomHardLinkStep.make,
69-
}),
72+
.step = hardlink_step,
7073
.exe = single_exe,
7174
};
7275
hardlink_install.step.dependOn(&single_exe.step);
73-
7476
b.getInstallStep().dependOn(&hardlink_install.step);
7577
} else {
7678
// release modes build all exes separately
@@ -87,7 +89,7 @@ pub fn build(b: *std.build.Builder) !void {
8789
},
8890
);
8991

90-
tool_exe.install();
92+
b.installArtifact(tool_exe);
9193
addGraphicsMagick(tool_exe);
9294
deps.addAllTo(tool_exe);
9395
}
@@ -106,18 +108,18 @@ const CustomHardLinkStep = struct {
106108
const self: *Self = @fieldParentPtr(Self, "step", step);
107109
const builder = self.builder;
108110

111+
const wrapmain_path = self.exe.getEmittedBin().getPath(builder);
109112
inline for (EXECUTABLES) |exec_decl| {
110113
const exec_name = exec_decl.@"0";
111114
const full_dest_path = builder.getInstallPath(.{ .bin = {} }, exec_name);
115+
std.debug.print("{s} -> {s}\n", .{ wrapmain_path, full_dest_path });
112116
_ = try std.fs.Dir.updateFile(
113117
std.fs.cwd(),
114-
self.exe.output_path_source.path.?,
118+
wrapmain_path,
115119
std.fs.cwd(),
116120
full_dest_path,
117121
.{},
118122
);
119-
120-
//try builder.updateFile(self.exe.output_path_source.path.?, full_dest_path);
121123
}
122124
}
123125
};

src/find_main.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ pub fn main() anyerror!void {
221221
std.mem.copy(u8, &tmp_path, PREFIX);
222222
var fill_here = tmp_path[PREFIX.len..];
223223

224-
const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp()));
224+
const seed = @as(u64, @truncate(@as(u128, @bitCast(std.time.nanoTimestamp()))));
225225
var r = std.rand.DefaultPrng.init(seed);
226226
for (fill_here) |*el| {
227-
const ascii_idx = @intCast(u8, r.random().uintLessThan(u5, 24));
227+
const ascii_idx = @as(u8, @intCast(r.random().uintLessThan(u5, 24)));
228228
const letter: u8 = @as(u8, 65) + ascii_idx;
229229
el.* = letter;
230230
}
@@ -445,7 +445,7 @@ pub const SqlGiver = struct {
445445
for (self.operators, 0..) |regex, current_regex_index| {
446446
logger.debug("try regex {d} on query '{s}'", .{ current_regex_index, query_slice });
447447
maybe_captures = try regex.captures(allocator, query_slice, .{});
448-
maybe_captured_regex_index = @intToEnum(CaptureType, current_regex_index);
448+
maybe_captured_regex_index = @as(CaptureType, @enumFromInt(current_regex_index));
449449
logger.debug("raw capture? {any}", .{maybe_captures});
450450
if (maybe_captures) |captures| {
451451
const capture = captures[0].?;

src/hydrus_api_main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn mainHandler(
164164
logger.info("{s} {s} {d}", .{
165165
methodString(request),
166166
request.path(),
167-
@enumToInt(response.status_code),
167+
@intFromEnum(response.status_code),
168168
});
169169
}
170170

src/id_migration.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn migrateFiles(self: *Context) !void {
4848
defer stmt.deinit();
4949

5050
var rng = std.rand.DefaultPrng.init(
51-
@truncate(u64, @intCast(u128, std.time.nanoTimestamp())),
51+
@as(u64, @truncate(@as(u128, @intCast(std.time.nanoTimestamp())))),
5252
);
5353
const random = rng.random();
5454

@@ -113,7 +113,7 @@ fn migrateFiles(self: *Context) !void {
113113

114114
fn migrateCores(self: *Context) !void {
115115
var rng = std.rand.DefaultPrng.init(
116-
@truncate(u64, @intCast(u128, std.time.nanoTimestamp())),
116+
@as(u64, @truncate(@as(u128, @intCast(std.time.nanoTimestamp())))),
117117
);
118118
const random = rng.random();
119119

@@ -262,7 +262,7 @@ fn migrateTagFiles(self: *Context) !void {
262262
}
263263

264264
fn migratePools(self: *Context) !void {
265-
var rng = std.rand.DefaultPrng.init(@truncate(u64, @intCast(u128, std.time.nanoTimestamp())));
265+
var rng = std.rand.DefaultPrng.init(@as(u64, @truncate(@as(u128, @intCast(std.time.nanoTimestamp())))));
266266
const random = rng.random();
267267

268268
var stmt = try self.db.prepare(

src/include_main.zig

+7-7
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn getGraphicsMagickApi() ?GraphicsMagickApi {
251251

252252
var api: GraphicsMagickApi = undefined;
253253
inline for (@typeInfo(GraphicsMagickApi).Struct.fields) |field_decl| {
254-
const name_cstr = std.cstr.addNullByte(alloc, field_decl.name) catch unreachable;
254+
const name_cstr = alloc.dupeZ(u8, field_decl.name) catch unreachable;
255255
defer fba.reset();
256256

257257
@field(api, field_decl.name) = gm_clib.lookup(field_decl.type, name_cstr).?;
@@ -338,7 +338,7 @@ const RegexTagInferrer = struct {
338338

339339
pub fn init(config: TagInferrerConfig, allocator: std.mem.Allocator) !RunContext {
340340
const regex_config = config.config.regex;
341-
const regex_cstr = try std.cstr.addNullByte(allocator, regex_config.text.?);
341+
const regex_cstr = try allocator.dupeZ(u8, regex_config.text.?);
342342
var gm_api = if (regex_config.use_exif) getGraphicsMagickApi().? else null;
343343
return RunContext{
344344
.allocator = allocator,
@@ -373,7 +373,7 @@ const RegexTagInferrer = struct {
373373
var buf: [std.os.PATH_MAX]u8 = undefined;
374374
var fba = std.heap.FixedBufferAllocator{ .end_index = 0, .buffer = &buf };
375375
var alloc = fba.allocator();
376-
const path_cstr = std.cstr.addNullByte(alloc, file.local_path) catch unreachable;
376+
const path_cstr = alloc.dupeZ(u8, file.local_path) catch unreachable;
377377

378378
gm_api.InitializeMagick(null);
379379
std.mem.copy(u8, &info.*.filename, path_cstr);
@@ -764,8 +764,8 @@ const MimeTagInferrer = struct {
764764
//
765765
// Only adding log statements made me even realize the error location
766766
if (config.config.mime.tag_for_all_video) |tag_for_all_video| {
767-
std.debug.assert(@ptrToInt(tag_for_all_video.ptr) ==
768-
@ptrToInt(self.config.tag_for_all_video.?.ptr));
767+
std.debug.assert(@intFromPtr(tag_for_all_video.ptr) ==
768+
@intFromPtr(self.config.tag_for_all_video.?.ptr));
769769
}
770770

771771
return self;
@@ -780,7 +780,7 @@ const MimeTagInferrer = struct {
780780
file: *const Context.File,
781781
tags_to_add: *std.ArrayList([]const u8),
782782
) !void {
783-
const path_cstr = try std.cstr.addNullByte(self.allocator, file.local_path);
783+
const path_cstr = try self.allocator.dupeZ(u8, file.local_path);
784784
defer self.allocator.free(path_cstr);
785785

786786
var mimetype = try self.cookie.inferFile(path_cstr);
@@ -1138,7 +1138,7 @@ pub fn main() anyerror!void {
11381138

11391139
while (try walker.next()) |entry| {
11401140
switch (entry.kind) {
1141-
.File, .SymLink => {
1141+
.file, .sym_link => {
11421142
logger.debug(
11431143
"adding child path '{s}{s}{s}'",
11441144
.{ path_to_include, std.fs.path.sep_str, entry.path },

src/ls_main.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ pub fn main() anyerror!void {
152152
while (try it.next()) |entry| {
153153
// TODO get stat?
154154
switch (entry.kind) {
155-
.File => try stdout.print("-", .{}),
156-
.Directory => try stdout.print("d", .{}),
155+
.file => try stdout.print("-", .{}),
156+
.directory => try stdout.print("d", .{}),
157157
else => try stdout.print("-", .{}),
158158
}
159159
try stdout.print(" {s}", .{entry.name});
160-
if (entry.kind == .File) {
160+
if (entry.kind == .file) {
161161
var realpath_buf: [std.os.PATH_MAX]u8 = undefined;
162162
const full_path = try dir.dir.realpath(entry.name, &realpath_buf);
163163
var maybe_inner_file = try ctx.fetchFileByPath(full_path);

src/main.zig

+16-19
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ pub const ID = struct {
345345

346346
pub fn generate() Self {
347347
var rng = std.rand.DefaultPrng.init(
348-
@truncate(u64, @intCast(u128, std.time.nanoTimestamp())),
348+
@as(u64, @truncate(@as(u128, @intCast(std.time.nanoTimestamp())))),
349349
);
350350
const rand = rng.random();
351351
const generated_ulid = ulidFromTimestamp(rand, std.time.milliTimestamp());
@@ -354,7 +354,7 @@ pub const ID = struct {
354354

355355
pub fn generateWithTimestamp(milliTimestamp: anytype) Self {
356356
var rng = std.rand.DefaultPrng.init(
357-
@truncate(u64, @intCast(u128, std.time.nanoTimestamp())),
357+
@as(u64, @truncate(@as(u128, @intCast(std.time.nanoTimestamp())))),
358358
);
359359
const rand = rng.random();
360360

@@ -442,7 +442,7 @@ pub fn loadDatabase(allocator: std.mem.Allocator, given_options: LoadDatabaseOpt
442442
options.home_path = home_path;
443443
}
444444

445-
const db_path_cstr = try std.cstr.addNullByte(allocator, options.db_path.?);
445+
const db_path_cstr = try allocator.dupeZ(u8, options.db_path.?);
446446
defer allocator.free(db_path_cstr);
447447

448448
var diags: sqlite.Diagnostics = undefined;
@@ -846,7 +846,7 @@ pub const Context = struct {
846846
/// Caller owns the returned memory.
847847
fn randomCoreData(self: *Self, core_output: []u8) void {
848848
_ = self;
849-
const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp()));
849+
const seed = @as(u64, @truncate(@as(u128, @bitCast(std.time.nanoTimestamp()))));
850850
var r = std.rand.DefaultPrng.init(seed);
851851
for (core_output, 0..) |_, index| {
852852
var random_byte = r.random().uintAtMost(u8, 255);
@@ -925,10 +925,7 @@ pub const Context = struct {
925925

926926
if (tag_name_regex) |tag_name_regex_string| {
927927
defer self.allocator.free(tag_name_regex_string);
928-
self.library_config.tag_name_regex_string = try std.cstr.addNullByte(
929-
self.allocator,
930-
tag_name_regex_string,
931-
);
928+
self.library_config.tag_name_regex_string = try self.allocator.dupeZ(u8, tag_name_regex_string);
932929

933930
self.library_config.tag_name_regex = try libpcre.Regex.compile(
934931
self.library_config.tag_name_regex_string.?,
@@ -941,7 +938,7 @@ pub const Context = struct {
941938
pub fn updateLibraryConfig(self: *Self, field: LibraryConfiguration.FieldUpdateRequest) !void {
942939
switch (field) {
943940
.tag_name_regex => |new_regex| {
944-
const new_regex_cstr = try std.cstr.addNullByte(self.allocator, new_regex);
941+
const new_regex_cstr = try self.allocator.dupeZ(u8, new_regex);
945942
defer self.allocator.free(new_regex_cstr);
946943
const regex = libpcre.Regex.compile(new_regex_cstr, DefaultRegexOptions) catch |err| {
947944
logger.err("failed to compile regex: {s}", .{@errorName(err)});
@@ -1072,7 +1069,7 @@ pub const Context = struct {
10721069
if (options.source) |source| {
10731070
if (options.parent_source_id) |parent_source_id| {
10741071
if (source.kind != TagSourceType.system) return error.InvalidSourceType;
1075-
if (source.id != @enumToInt(SystemTagSources.tag_parenting)) {
1072+
if (source.id != @intFromEnum(SystemTagSources.tag_parenting)) {
10761073
logger.err("expected tag parent source, got {}", .{source});
10771074
return error.InvalidSourceID;
10781075
}
@@ -1082,15 +1079,15 @@ pub const Context = struct {
10821079
\\values (?, ?, ?, ?, ?) on conflict do nothing
10831080
,
10841081
.{},
1085-
.{ core_hash.id.sql(), self.hash.id.sql(), @enumToInt(source.kind), source.id, parent_source_id },
1082+
.{ core_hash.id.sql(), self.hash.id.sql(), @intFromEnum(source.kind), source.id, parent_source_id },
10861083
);
10871084
} else {
10881085
try self.ctx.db.exec(
10891086
\\insert into tag_files (core_hash, file_hash, tag_source_type, tag_source_id)
10901087
\\values (?, ?, ?, ?) on conflict do nothing
10911088
,
10921089
.{},
1093-
.{ core_hash.id.sql(), self.hash.id.sql(), @enumToInt(source.kind), source.id },
1090+
.{ core_hash.id.sql(), self.hash.id.sql(), @intFromEnum(source.kind), source.id },
10941091
);
10951092
}
10961093
} else {
@@ -1159,7 +1156,7 @@ pub const Context = struct {
11591156
try self.ctx.db.exec(
11601157
"delete from tag_sources where type = ? and id = ?",
11611158
.{},
1162-
.{ @enumToInt(TagSourceType.external), self.id },
1159+
.{ @intFromEnum(TagSourceType.external), self.id },
11631160
);
11641161
}
11651162
};
@@ -1208,7 +1205,7 @@ pub const Context = struct {
12081205
.core = hash_with_blob.toRealHash(),
12091206
.source = Source{
12101207
.ctx = self.ctx,
1211-
.kind = @intToEnum(TagSourceType, row.tag_source_type),
1208+
.kind = @as(TagSourceType, @enumFromInt(row.tag_source_type)),
12121209
.id = row.tag_source_id,
12131210
},
12141211
.parent_source_id = row.parent_source_id,
@@ -1273,7 +1270,7 @@ pub const Context = struct {
12731270
try self.db.exec(
12741271
"insert into tag_sources (type, id, name) values (?, ?, ?)",
12751272
.{},
1276-
.{ @enumToInt(TagSourceType.external), source_id, name },
1273+
.{ @intFromEnum(TagSourceType.external), source_id, name },
12771274
);
12781275

12791276
return File.Source{ .ctx = self, .kind = .external, .id = source_id };
@@ -1292,7 +1289,7 @@ pub const Context = struct {
12921289
struct { type: i64, id: i64 },
12931290
"select type, id from tag_sources where type = ? and id = ?",
12941291
.{},
1295-
.{ @enumToInt(TagSourceType.external), id },
1292+
.{ @intFromEnum(TagSourceType.external), id },
12961293
);
12971294

12981295
if (maybe_row) |row| {
@@ -1657,7 +1654,7 @@ pub const Context = struct {
16571654
});
16581655

16591656
try file.addTag(.{ .id = tag_entry.tag_id, .hash_data = undefined }, .{
1660-
.source = try self.fetchTagSource(.system, @enumToInt(SystemTagSources.tag_parenting)),
1657+
.source = try self.fetchTagSource(.system, @intFromEnum(SystemTagSources.tag_parenting)),
16611658
.parent_source_id = tag_entry.parent_entry_id,
16621659
});
16631660
}
@@ -1977,7 +1974,7 @@ pub fn log(
19771974
comptime format: []const u8,
19781975
args: anytype,
19791976
) void {
1980-
if (@enumToInt(message_level) <= @enumToInt(@import("root").current_log_level)) {
1977+
if (@intFromEnum(message_level) <= @intFromEnum(@import("root").current_log_level)) {
19811978
std.log.defaultLog(message_level, scope, format, args);
19821979
}
19831980
}
@@ -2371,7 +2368,7 @@ test "tag parenting" {
23712368
for (file_tags) |file_tag| {
23722369
if (std.meta.eql(file_tag.core.id, parent_tag.core.id)) {
23732370
try std.testing.expectEqual(TagSourceType.system, file_tag.source.kind);
2374-
try std.testing.expectEqual(@as(i64, @enumToInt(SystemTagSources.tag_parenting)), file_tag.source.id);
2371+
try std.testing.expectEqual(@as(i64, @intFromEnum(SystemTagSources.tag_parenting)), file_tag.source.id);
23752372
try std.testing.expectEqual(tag_tree_entry_id, file_tag.parent_source_id.?);
23762373
saw_parent = true;
23772374
}

src/rename_watcher_main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pub fn main() anyerror!void {
605605

606606
const pidfd_rc = std.os.linux.pidfd_open(proc.id, 0);
607607
switch (std.os.errno(pidfd_rc)) {
608-
.SUCCESS => pidfd = @intCast(std.os.fd_t, pidfd_rc),
608+
.SUCCESS => pidfd = @as(std.os.fd_t, @intCast(pidfd_rc)),
609609
.INVAL => unreachable,
610610
.NFILE, .MFILE => return error.TooManyFileDescriptors,
611611
.NODEV => return error.NoDevice,

src/rm_main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn main() anyerror!void {
196196
defer walker.deinit();
197197

198198
while (try walker.next()) |entry| {
199-
if (entry.kind != .File) continue;
199+
if (entry.kind != .file) continue;
200200
logger.debug("checking path {s}", .{entry.path});
201201
var inner_realpath_buffer: [std.os.PATH_MAX]u8 = undefined;
202202
const inner_full_path = try entry.dir.realpath(entry.basename, &inner_realpath_buffer);

0 commit comments

Comments
 (0)