Skip to content

Commit be94e9d

Browse files
committed
fix: add known-folders
1 parent 8351f25 commit be94e9d

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

build.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn build(b: *std.Build) !void {
180180

181181
fn createImports(b: *std.Build, options: Options) []const Dep {
182182
var list: std.ArrayListUnmanaged(Dep) = .{};
183-
list.ensureTotalCapacity(b.allocator, 4) catch @panic("OOM");
183+
list.ensureTotalCapacity(b.allocator, 5) catch @panic("OOM");
184184

185185
const ziglua = b.dependency("ziglua", .{
186186
.target = options.target,
@@ -194,9 +194,11 @@ fn createImports(b: *std.Build, options: Options) []const Dep {
194194
.target = options.target,
195195
.optimize = options.optimize,
196196
});
197+
const @"known-folders" = b.dependency("known-folders", .{});
197198
list.appendAssumeCapacity(.{ .module = ziglua.module("ziglua"), .name = "ziglua" });
198199
list.appendAssumeCapacity(.{ .module = xev.module("xev"), .name = "xev" });
199200
list.appendAssumeCapacity(.{ .module = zosc.module("zosc"), .name = "zosc" });
201+
list.appendAssumeCapacity(.{ .module = @"known-folders".module("known-folders"), .name = "known-folders" });
200202

201203
return list.items;
202204
}

build.zig.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@
1919
.url = "git+https://github.com/robbielyman/EmbedFile.zig#b5ae28c2812a510de762b41cea489aad80bc039a",
2020
.hash = "1220633202df3bfbf2436d80dee0cf94b7eeab59177b4d777680f175a08fa8deaf41",
2121
},
22+
.@"known-folders" = .{
23+
.url = "git+https://github.com/ziglibs/known-folders#1cceeb70e77dec941a4178160ff6c8d05a74de6f",
24+
.hash = "12205f5e7505c96573f6fc5144592ec38942fb0a326d692f9cddc0c7dd38f9028f29",
25+
},
2226
},
2327
}

src/main.zig

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
pub fn main() !void {
2-
// logging
3-
const logfile = try std.fs.cwd().createFile("/tmp/seamstress.log", .{});
4-
var bw = std.io.bufferedWriter(logfile.writer());
5-
defer bw.flush() catch {};
6-
log_writer = bw.writer().any();
7-
82
// allocation
93
var gpa: if (builtin.mode == .Debug) std.heap.GeneralPurposeAllocator(.{
104
.stack_trace_frames = 20,
@@ -18,6 +12,19 @@ pub fn main() !void {
1812
};
1913
const allocator = if (builtin.mode == .Debug) gpa.allocator() else std.heap.c_allocator;
2014

15+
// logging
16+
var bw = blk: {
17+
const cache_base = try folders.open(allocator, .cache, .{}) orelse break :blk null;
18+
try cache_base.makePath("seamstress");
19+
const path = "seamstress" ++ std.fs.path.sep_str ++ "seamstress.log";
20+
const logfile = try cache_base.createFile(path, .{ .truncate = false });
21+
const end = try logfile.getEndPos();
22+
try logfile.seekTo(end);
23+
break :blk std.io.bufferedWriter(logfile.writer());
24+
};
25+
defer if (bw) |*w| w.flush() catch {};
26+
if (bw) |*w| log_writer = w.writer().any();
27+
2128
// arguments
2229
{
2330
const args = try std.process.argsAlloc(allocator);
@@ -83,7 +90,7 @@ pub fn main() !void {
8390

8491
try Seamstress.main(l);
8592
// flush any accumulated logs
86-
try bw.flush();
93+
if (bw) |*w| try w.flush();
8794
// in release modes, this calls `exit(0)`, saving us from having to wait for memory to be freed
8895
std.process.cleanExit();
8996
}
@@ -216,12 +223,18 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_
216223
@call(.always_inline, std.builtin.default_panic, .{ msg, error_return_trace, ret_addr });
217224
}
218225

226+
pub const known_folders_config: folders.KnownFolderConfig = .{
227+
.xdg_force_default = true,
228+
.xdg_on_mac = true,
229+
};
230+
219231
const std = @import("std");
220232
const builtin = @import("builtin");
221233
const Seamstress = @import("seamstress.zig");
222234
const ziglua = @import("ziglua");
223235
const Lua = ziglua.Lua;
224236
const lu = @import("lua_util.zig");
237+
const folders = @import("known-folders");
225238

226239
test "ref" {
227240
_ = Seamstress;

src/seamstress.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ test "lifecycle" {
347347
_ = r.timer catch unreachable;
348348
const boolean: *bool = @ptrCast(@alignCast(ud.?));
349349
const lua = lu.getLua(loop);
350-
for (modules.list.keys(), modules.list.values()) |key, @"fn"| {
351-
std.debug.print("{s}\n", .{key});
350+
for (modules.list.values()) |@"fn"| {
352351
lua.pushFunction(@"fn");
353352
lu.doCall(lua, 0, 0) catch {
354353
std.debug.print("{s}\n", .{lua.toString(-1) catch unreachable});

0 commit comments

Comments
 (0)