Added dependencies to plugin's (By name... for now ig, might wanna change so that it takes build function from plugin tho, safer)

This commit is contained in:
abux 2026-07-25 18:45:06 +01:00
parent 5ab65e1b67
commit 3342f6ad6f
3 changed files with 51 additions and 2 deletions

View file

@ -8,6 +8,7 @@ const stage = @import("stage.zig");
pub const plugin: App.plugin.Plugin = .{ pub const plugin: App.plugin.Plugin = .{
.name = "Simple", .name = "Simple",
.description = "Simple plugin example", .description = "Simple plugin example",
.dependencies = &.{},
.build = build, .build = build,
}; };

View file

@ -7,6 +7,7 @@ const Self = @This();
// --- ID --- // --- ID ---
name: []const u8, name: []const u8,
dependencies: []const []const u8 = &.{},
description: []const u8 = "", description: []const u8 = "",
version: [3]u8 = .{ 0, 0, 0 }, version: [3]u8 = .{ 0, 0, 0 },

View file

@ -55,7 +55,54 @@ pub fn build(
self: *Self, self: *Self,
ctx: Context, ctx: Context,
) !void { ) !void {
for (self.data.items) |*plugin| { // --- # ---
try plugin.build(plugin, ctx); var built: std.StringHashMap(void) = .init(self.alloc);
defer built.deinit();
// --- # ---
var progress = true;
while (progress) {
progress = false;
for (self.data.items) |*plugin| {
// --- SKIP SELF ---
if (built.contains(plugin.name)) continue;
// --- CHECK IF DEP ARE [READY OR NOT]
var ready: bool = true;
for (plugin.dependencies) |dep| {
if (!built.contains(dep)) {
ready = false;
break;
}
}
// --- IF YE, BUILD ---
if (ready) {
try plugin.build(plugin, ctx);
try built.put(plugin.name, {});
progress = true;
}
}
}
// --- # ---
var missing = false;
for (self.data.items) |plugin| {
if (!built.contains(plugin.name)) {
std.debug.print("[PLUGIN] Failed to build \"{s}\". Missing dependencies:\n", .{plugin.name});
for (plugin.dependencies) |dep| {
if (!built.contains(dep)) {
std.debug.print(" - {s}\n", .{dep});
}
}
missing = true;
}
}
// --- # ---
if (missing) {
return error.PluginDependencyError;
} }
} }