summaryrefslogtreecommitdiff
path: root/src/source_manifest.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/source_manifest.zig')
-rw-r--r--src/source_manifest.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/source_manifest.zig b/src/source_manifest.zig
new file mode 100644
index 00000000..5de560ac
--- /dev/null
+++ b/src/source_manifest.zig
@@ -0,0 +1,44 @@
+//! The virtual filesystem: pardes's own source, embedded, as an ALLOWLIST.
+//!
+//! This is the default filesystem — what a host that implements no file method
+//! reads and writes, and the only one the browser has ever had. It replaced a
+//! build-time generator that embedded every tracked `.zig` file: 64 files and
+//! 2.4 MB of generated Zig, rediscovered on every consumer build because the
+//! tracked set can change without any known input changing.
+//!
+//! An allowlist instead, for the reason the generator's own comment gave away:
+//! nothing needs all of them. What earns a place here is a file that explains
+//! how pardes works to someone reading it inside pardes — the core, the host
+//! seam, the keymap, the build. `src/pardes.zig` alone is 722 KB of the total,
+//! and it is the one file worth that: it IS the program.
+//!
+//! Paths are as a user would type them, repo-root-relative, which is what
+//! `look` resolves a click against.
+
+pub const Source = struct { path: []const u8, contents: []const u8 };
+
+pub const all = [_]Source{
+ .{ .path = "build.zig", .contents = @embedFile("root-build.zig") },
+ .{ .path = "build.zig.zon", .contents = @embedFile("root-build.zig.zon") },
+ .{ .path = "src/pardes.zig", .contents = @embedFile("pardes.zig") },
+ .{ .path = "src/host.zig", .contents = @embedFile("host.zig") },
+ .{ .path = "src/config.zig", .contents = @embedFile("config.zig") },
+ .{ .path = "src/main.zig", .contents = @embedFile("main.zig") },
+ .{ .path = "src/builtins.zig", .contents = @embedFile("builtins.zig") },
+ .{ .path = "src/grammar_manifest.zig", .contents = @embedFile("grammar_manifest.zig") },
+ .{ .path = "src/source_manifest.zig", .contents = @embedFile("source_manifest.zig") },
+ .{ .path = "src/CHANGELOG.md", .contents = @embedFile("CHANGELOG.md") },
+};
+
+/// The written-file override wins, then the allowlist. Callers own no memory
+/// here: every byte is static or lives in the Fallback that answered.
+pub fn find(path: []const u8) ?[]const u8 {
+ for (all) |s| if (eql(s.path, path)) return s.contents;
+ return null;
+}
+
+fn eql(a: []const u8, b: []const u8) bool {
+ if (a.len != b.len) return false;
+ for (a, b) |x, y| if (x != y) return false;
+ return true;
+}