Zig Autodoc : exclude anonymous imports?

I was playing around with autodoc lately, and encountered an issue with anonymous imports, getting

error: error: ModuleNotFound

when calling a step that creates docs via getEmittedDocs(). The anonymous import is added to the module in the build.zig and works fine, also the autodoc generation works fine, just not the combination of the two :slight_smile:

  • is there a way to exclude imports from autodoc?
  • I know this feature is quiet new but is there some documentation on the autodoc feature in general?

Try to define a simple zig source for emitting docs. I am doing this mostly because I don’t want to wait for documentation generation when testing.

    // docs:
    const doc_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/root.zig" },
        .target = target,
        .optimize = optimize,
    const install_docs = b.addInstallDirectory(.{
        .source_dir = doc_tests.getEmittedDocs(),
        .install_dir = .prefix,
        .install_subdir = "docs",
    const docs_step = b.step("docs", "Generate documentation");

install_docs creates the directory zig-out/docs
for doc_tests don’t use your full module set, but a simpler zig source that includes the wanted documentation.


Right, this might be the better choice in my case, to only generate docs for specific parts of the module.

In general though, it might be good to have both options; to exclude specific parts (.zig files, imports etc.) as well.

1 Like

It’s been a while since I looked at the autodocs feature, it seems that a significant revision was done since last time. Anonymous modules do not seem to be a problem anymore.

What (kind of) worked in the past, that you could just open the index.html in your browser, now doesn’t work anymore. But you can run the docs on a local server, e.g. via

python -m http.server -b [some-unused-port] -d [your-docs-dir]/.