Is it possible to render docs of both std and my dependencies and view them in a combined page?

Right now I have three different zig docs open in my browser. Would be nice if there was a way to combine them into just one, with a unified search bar.

2 Likes

I can’t say for sure regarding all dependencies, but I know std docs are built-in with your project’s auto docs. Tested with my library’s docs here, I can search through std or my project in the search bar.

2 Likes

I was just thinking it would be sweet if there was a command to automatically do this locally for one’s entire dependency tree. Like zig std but for all packages you depend on. Maybe even the web UI could let you select from a menu of all the compilations and pick one to look at the combined docs for.

22 Likes

It’s possible to get a documentation page with std, your dependencies (even the C ones), and your project all searchable by adding a step in build.zig to build the docs and then serving the resulting page with a local web server. Just trying to browse the file system directly from the browser doesn’t work for me with Firefox since the browser refuses to run the necessary Javascript.

  1. Add to build.zig something like this:
const exe_docs = b.addInstallDirectory(.{
    .source_dir = exe.getEmittedDocs(),
    .install_dir = .prefix,
    .install_subdir = "docs/<project-name>-exe",
});

const doc_step = b.step("docs", "Generate documentation");
doc_step.dependOn(&exe_docs.step);
  1. Run zig build docs
  2. Serve the documentation page with a web server
cd ./zig-out/docs/<project-name>-exe/
python3 -m http.server # Use whatever HTTP server you want

I agree it would be great to have this functionality built in. It’s so helpful to be able to search documentation for exactly the code you are using. It all works offline too!

1 Like

Modifying zig std to serve docs for multiple folders turned out to be pretty straightforward.
https://codeberg.org/ziglang/zig/pulls/36516
This small patch is enough to search symbols in dependencies – that’s enough for my use case now.
I have no expectation for this to be merged or looked at by anyone, this is my first zig code that actually does something.

4 Likes