Skip to content

Commit c04f209

Browse files
committed
tk: update to the new WIP branch
1 parent bed514c commit c04f209

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn addLlama(b: *std.Build, exe: anytype) !void {
8585
.windows => ".",
8686
else => "bin",
8787
}));
88+
// TODO: can we somehow favor a locally pulled llama.cpp over the one which is installed via brew?
8889
exe.linkSystemLibrary("llama");
8990

9091
exe.root_module.addImport("llama_cpp", llama_cpp.createModule());

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
.hash = "N-V-__8AAFXpCgDf9CFaoMSic23MgE7_O01X9Nz6JGTh2AY3",
3030
},
3131
.tokamak = .{
32-
.url = "git+https://github.com/cztomsik/tokamak?ref=main#5a29143a0c1fabea38baf3613a4691979b6e09c0",
33-
.hash = "tokamak-2.0.0-FbnSed8qAgCBLRx8zc19crztQ7tfnS0wvGAUnQJ55qql",
32+
.url = "git+https://github.com/cztomsik/tokamak?ref=feat/ct2#7e404eb1de48e95f2ea417785bfbf0a1e05d4c32",
33+
.hash = "tokamak-2.0.0-FbnSeUBSBAAbhtYy1ATTE4SibbbRv48L4NuyDk_81PrZ",
3434
},
3535
.fridge = .{
3636
.url = "git+https://github.com/cztomsik/fridge?ref=main#11305fd8c3ee58512494c2412e9a84ab92aa82a2",

src/app.zig

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,34 @@ pub const App = struct {
116116

117117
const CONFIG_FILE = "config.json";
118118

119-
pub fn initConfig(target: *std.json.Parsed(Config), home: *Home, ct: *tk.Container) !void {
120-
target.* = try ct.injector.call(readConfig, .{});
121-
target.value.db.dir = target.value.db.dir orelse home.path;
119+
pub fn configure(bundle: *tk.Bundle) void {
120+
// We can't use `routes: [] = ...` field default because we need to reference api again for swagger
121+
bundle.addInstance([]const tk.Route, .value(routes));
122122

123-
try ct.register(&target.value);
124-
inline for (std.meta.fields(Config)) |f| try ct.register(&@field(target.value, f.name));
123+
// TODO: Maybe the default for fields should be .anyhow?
124+
bundle.addOverride(std.json.Parsed(Config), .factory(readConfig));
125+
126+
// Make all config.xxx fields available for injection
127+
bundle.addFieldRef(std.json.Parsed(Config), "value");
128+
inline for (std.meta.fields(Config)) |f| bundle.addFieldRef(Config, f.name);
129+
130+
bundle.addInitHook(setDefaultDbPath);
131+
bundle.addInitHook(migrateDb);
132+
bundle.addInitHook(loadCerts);
125133
}
126134

127-
pub fn initServer(target: *tk.Server, allocator: std.mem.Allocator, cfg: @FieldType(Config, "server"), injector: *tk.Injector) !void {
128-
target.* = try tk.Server.init(allocator, routes, .{
129-
.listen = cfg,
130-
.injector = injector,
131-
});
135+
fn setDefaultDbPath(db_opts: *fr.SQLite3.Options, home: *Home) !void {
136+
db_opts.dir = db_opts.dir orelse home.path;
132137
}
133138

134-
pub fn afterAppInit(allocator: std.mem.Allocator, db_pool: *fr.Pool(fr.SQLite3), client: *std.http.Client) !void {
139+
fn migrateDb(allocator: std.mem.Allocator, db_pool: *fr.Pool(fr.SQLite3)) !void {
135140
var db = try db_pool.getSession(allocator);
136141
defer db.deinit();
137142

138-
try fr.migrate(db, @embedFile("db_schema.sql"));
143+
try fr.migrate(&db, @embedFile("db_schema.sql"));
144+
}
139145

146+
fn loadCerts(allocator: std.mem.Allocator, client: *std.http.Client) !void {
140147
if (comptime builtin.target.os.tag == .windows) {
141148
try client.ca_bundle.rescan(allocator);
142149
const start = client.ca_bundle.bytes.items.len;

0 commit comments

Comments
 (0)