But I am confused about what is the correct way to make a sharable static library. The basic examples always use a single .zig for a static library building. Can I have more than one file? Also, from the user’s point of view, how would using my library differ when using a static library versus just copying all the source files and using @import("Panel.zig"), etc?
Topic 2:
Also, I would like to provide nice documentation. Obviously, I would prefer this to be automatically generated. However, I do not want to generate documentation for my test/example files, just the library itself. What is the correct magic that I have to add to the build.zig when my library is built on zig version 0.13.0?
Yes, you can have multiple files. Call const foo = @import("foo.zig"); from your root file to access pub functions, variables and constants in foo.zig.
You can expose your library as a package that have modules. The package is added as a dependency in the users build.zig.zon and your modules can be imported using: @import("terminal") where terminal is a module name. See: How to package a zig source module and how to use it
From a library or executable artifact call getEmittedDocs() to generate documentation. The following example code installs the documentation under zig-out/docs when running zig build docs.
/home/***/Documents/ZIG/simple-text-ui-for-zig/build.zig:38:30: error: no field or member function named 'getEmittedDocs' in 'Build.Module'
.source_dir = lib_tui.getEmittedDocs(),
~~~~~~~^~~~~~~~~~~~~~~
/home/***/bin/zig/lib/std/Build/Module.zig:1:1: note: struct declared here
The getEmittedDocs function works with a Compile instance, not a Module. You need to use the result of b.addExecutable, b.addStaticLibrary or b.addObject (recommanded if you don’t want to do anything else with it).
This got me closer, but no actual documentation is generated, just landing page for root and link to the src but no docs to the files that I thought it should generate… I tried even adding comptime _= ..., but that didn’t help either.
Interesting, if I click on the src in the root (top-level) view, and then click on any of the “modules” (?) such as TextLine
comptime {
...
_ = TextLine;
...
}
that opens a documentation for that file.
I was expecting that I would have some links or even side nav on the root page. It does not feel “natural” that I have to click on src to see documentation.
I’d actually very much like the ability to generate developer documentation, which includes all doc comments whether the commented item is public or not. Public-only is a reasonable default, but I quite like the Zig docs browser, and it would be rather nice to be able to use it as a reference when working on code, in addition to just using a library or what have you.