zig
zig copied to clipboard
emitting docs for a test tars `lib/compiler` instead of any user code
Zig Version
0.12.0-dev.3419+a2651cbc8
Steps to Reproduce and Observed Behavior
zig test -femit-docs any_file.zig
serve the docs with e.g. python -m http.server
instead of the users code a file from lib/compiler
will be the shown since this is where the real root file of zig test
is located.
Expected Behavior
if possible, tar the users code, otherwise -femit-docs
should probably be disallowed on tests
for context i believe people trying to emit docs from a test (step) comes from zig only libraries which only expose a module and no type of Step.Compile
. since standalone modules cant currently express any way to emit docs people turn to their test step.
i think the ideal solution here would be to disallow emitting docs for tests and adding a helper function to std.Build
that creates a dummy step for emitting a modules docs. something like b.emitModuleDocs
that returns a lazypath for use with e.g. b.addInstallDirectory
would be nice
I'm having this problem as well, I also can't even find my module inside the search.
Until a nicer solution is merged, you can generate documentation for individual modules compiling static libraries rather than tests, via zig build-lib -fno-emit-bin -femit-docs
on the CLI or using std.Build.addStaticLibrary
in the build system, something like:
const docs_dummy = b.addStaticLibrary(.{
.name = "name",
.root_source_file = .{ .path = "src/root.zig" },
.target = target,
.optimize = optimize,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = docs_dummy.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Bulid the documentation");
docs_step.dependOn(&install_docs.step);