authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-28 02:17:50-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-03-28 02:17:50-07:00
log17053887d080bd125d2f5ccbb39238f23c706328
tree97ed7faba6053f50b668cd76bbfc5bbe5ebbbc89
parent9dac8db2df2332d6dd4aa52a0b524e5c88a9349b
parent3fb6bb144998de72d03b58e7c1daf134e2438373
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19458 from ianprime0509/all-module-docs

Autodoc: include all modules in output

2 files changed, 43 insertions(+), 2 deletions(-)

lib/compiler/std-docs.zig+20
......@@ -177,6 +177,26 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void {
177177 try w.writeFile(file);
178178 try w.writeByteNTimes(0, padding);
179179 }
180
181 {
182 // Since this command is JIT compiled, the builtin module available in
183 // this source file corresponds to the user's host system.
184 const builtin_zig = @embedFile("builtin");
185
186 var file_header = std.tar.output.Header.init();
187 file_header.typeflag = .regular;
188 try file_header.setPath("builtin", "builtin.zig");
189 try file_header.setSize(builtin_zig.len);
190 try file_header.updateChecksum();
191 try w.writeAll(std.mem.asBytes(&file_header));
192 try w.writeAll(builtin_zig);
193 const padding = p: {
194 const remainder = builtin_zig.len % 512;
195 break :p if (remainder > 0) 512 - remainder else 0;
196 };
197 try w.writeByteNTimes(0, padding);
198 }
199
180200 // intentionally omitting the pointless trailer
181201 //try w.writeByteNTimes(0, 512 * 2);
182202 try response.end();
src/Compilation.zig+23-2
......@@ -3693,6 +3693,9 @@ fn workerDocsCopy(comp: *Compilation, wg: *WaitGroup) void {
36933693}
36943694
36953695fn docsCopyFallible(comp: *Compilation) anyerror!void {
3696 const zcu = comp.module orelse
3697 return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{});
3698
36963699 const emit = comp.docs_emit.?;
36973700 var out_dir = emit.directory.handle.makeOpenPath(emit.sub_path, .{}) catch |err| {
36983701 return comp.lockAndSetMiscFailure(
......@@ -3723,7 +3726,25 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
37233726 };
37243727 defer tar_file.close();
37253728
3726 const root = comp.root_mod.root;
3729 var seen_table: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};
3730 defer seen_table.deinit(comp.gpa);
3731
3732 try seen_table.put(comp.gpa, zcu.main_mod, {});
3733 try seen_table.put(comp.gpa, zcu.std_mod, {});
3734
3735 var i: usize = 0;
3736 while (i < seen_table.count()) : (i += 1) {
3737 const mod = seen_table.keys()[i];
3738 try comp.docsCopyModule(mod, tar_file);
3739
3740 const deps = mod.deps.values();
3741 try seen_table.ensureUnusedCapacity(comp.gpa, deps.len);
3742 for (deps) |dep| seen_table.putAssumeCapacity(dep, {});
3743 }
3744}
3745
3746fn docsCopyModule(comp: *Compilation, module: *Package.Module, tar_file: std.fs.File) !void {
3747 const root = module.root;
37273748 const sub_path = if (root.sub_path.len == 0) "." else root.sub_path;
37283749 var mod_dir = root.root_dir.handle.openDir(sub_path, .{ .iterate = true }) catch |err| {
37293750 return comp.lockAndSetMiscFailure(.docs_copy, "unable to open directory '{}': {s}", .{
......@@ -3762,7 +3783,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
37623783
37633784 var file_header = std.tar.output.Header.init();
37643785 file_header.typeflag = .regular;
3765 try file_header.setPath(comp.root_name, entry.path);
3786 try file_header.setPath(module.fully_qualified_name, entry.path);
37663787 try file_header.setSize(stat.size);
37673788 try file_header.updateChecksum();
37683789