-
Notifications
You must be signed in to change notification settings - Fork 0
feat(packs): exposes surface modules + depends_on wiring (#498 PR 4) #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,12 @@ pub const PackModule = struct { | |
| name: []const u8, | ||
| /// Sanitized `<pack>__` ident prefix (owned by the caller). | ||
| prefix: []const u8, | ||
| /// The manifest's `depends_on` (#498 PR 4): each entry that names a | ||
| /// sibling PACK gets that pack's `__surface.zig` module wired under | ||
| /// the dep's plain name; entries naming decl-module plugins are | ||
| /// already in the table; `contracts` is the implicit full-module | ||
| /// import. Aliases manifest-owned strings. | ||
| depends_on: []const []const u8 = &.{}, | ||
| }; | ||
|
|
||
| /// The implicit shared-contracts pack name (`pack_validate.IMPLICIT_DEPS`): | ||
|
|
@@ -150,6 +156,12 @@ pub fn renderPackRoot( | |
| try w.writeAll("};\n\n"); | ||
| } | ||
|
|
||
| // Verb surfaces (RFC §6, #498 PR 4): raw re-exports for the pack's | ||
| // OWN code; dependents get the `exposes`-narrowed `__surface.zig`. | ||
| if (pack.has_queries) try w.writeAll("pub const queries = @import(\"queries.zig\");\n"); | ||
| if (pack.has_commands) try w.writeAll("pub const commands = @import(\"commands.zig\");\n"); | ||
| if (pack.has_queries or pack.has_commands) try w.writeAll("\n"); | ||
|
|
||
| // ── Registry bridge (#498 PR 3) ──────────────────────────────── | ||
| var prefix_buf: [128]u8 = undefined; | ||
| const prefix = scan.packNamespacePrefix(pack.name, &prefix_buf); | ||
|
|
@@ -184,3 +196,66 @@ pub fn renderPackRoot( | |
| errdefer arr_list.deinit(allocator); | ||
| return arr_list.toOwnedSlice(allocator); | ||
| } | ||
|
|
||
| /// The `exposes` lists as the surface renderer consumes them — a | ||
| /// decoupled mirror of `plugin_manifest.PackExposes` so this module | ||
| /// never imports the manifest parser. | ||
| pub const SurfaceExposes = struct { | ||
| queries: []const []const u8 = &.{}, | ||
| commands: []const []const u8 = &.{}, | ||
| }; | ||
|
|
||
| /// Render the pack's `__surface.zig` — the ONLY thing a dependent pack | ||
| /// can import (`@import("<dep>")` maps here, #498 PR 4). Its sole | ||
| /// import is the pack module itself (`@import("pack")`), and it | ||
| /// re-exports EXACTLY the manifest's `exposes` lists: a listed-but- | ||
| /// missing verb fails compilation with an error pointing at this file; | ||
| /// a `null`/empty `exposes` yields a header-only module — dependents | ||
| /// can call nothing, the correct default. | ||
| pub fn renderSurface( | ||
| allocator: std.mem.Allocator, | ||
| pack_name: []const u8, | ||
| exposes: SurfaceExposes, | ||
| ) ![]const u8 { | ||
| var alloc_writer: std.Io.Writer.Allocating = .init(allocator); | ||
| errdefer alloc_writer.deinit(); | ||
| const w = &alloc_writer.writer; | ||
|
|
||
| try w.print( | ||
| \\//! Generated by labelle-assembler — DO NOT EDIT. | ||
| \\//! Public surface of pack '{s}' (`exposes`, RFC §6 / #498 PR 4). | ||
| \\//! | ||
| \\//! Dependent packs import THIS module under the pack's name; it | ||
| \\//! re-exports exactly the manifest's `exposes` lists. Anything | ||
| \\//! not listed here does not exist to dependents. | ||
| \\ | ||
| \\ | ||
| , .{pack_name}); | ||
|
|
||
| if (exposes.queries.len > 0 or exposes.commands.len > 0) { | ||
| try w.writeAll("const pack = @import(\"pack\");\n\n"); | ||
| } | ||
| if (exposes.queries.len > 0) { | ||
| try w.writeAll("pub const queries = struct {\n"); | ||
| for (exposes.queries) |name| { | ||
| // @"" escaping: a manifest may expose a verb whose name is a | ||
| // Zig keyword or needs escaping (declared as `pub fn @"…"`); | ||
| // the escaped form is valid for plain identifiers too. | ||
| try w.print(" pub const @\"{s}\" = pack.queries.@\"{s}\";\n", .{ name, name }); | ||
| } | ||
| try w.writeAll("};\n"); | ||
| } | ||
| if (exposes.commands.len > 0) { | ||
| if (exposes.queries.len > 0) try w.writeAll("\n"); | ||
| try w.writeAll("pub const commands = struct {\n"); | ||
| for (exposes.commands) |name| { | ||
| try w.print(" pub const @\"{s}\" = pack.commands.@\"{s}\";\n", .{ name, name }); | ||
| } | ||
|
Comment on lines
+251
to
+253
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exposed command names are directly interpolated as Zig identifiers in the generated
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied in 47e5c68 — see commit message for the specifics (escaped idents both sides / token-sequence scan / docs aligned with the header-only + targeted-diagnostic behavior). |
||
| try w.writeAll("};\n"); | ||
| } | ||
|
|
||
| var arr_list = alloc_writer.toArrayList(); | ||
| // Same reset-writer rationale as `renderPackRoot`. | ||
| errdefer arr_list.deinit(allocator); | ||
| return arr_list.toOwnedSlice(allocator); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exposed query names are directly interpolated as Zig identifiers in the generated
__surface.zigfile. If a manifest defines an exposed name that is a reserved Zig keyword (likeconstorfn) or contains special characters, the generated code will fail to compile. Using Zig's@""identifier escaping syntax ensures that any valid string can be safely re-exported without causing syntax errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in 47e5c68 — see commit message for the specifics (escaped idents both sides / token-sequence scan / docs aligned with the header-only + targeted-diagnostic behavior).