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?
2 Likes

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");
    docs_step.dependOn(&install_docs.step);

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.

2 Likes

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