zig icon indicating copy to clipboard operation
zig copied to clipboard

emitting docs for a test tars `lib/compiler` instead of any user code

Open xdBronch opened this issue 11 months ago • 1 comments

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

xdBronch avatar Mar 23 '24 02:03 xdBronch

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

xdBronch avatar Mar 23 '24 16:03 xdBronch

I'm having this problem as well, I also can't even find my module inside the search.

RossComputerGuy avatar Mar 25 '24 04:03 RossComputerGuy

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);

dweiller avatar Mar 27 '24 23:03 dweiller