Zig Version: 0.13.0
I am working in WSL (Ubuntu 22.04.4 LTS) on a windows 11 machine.
I want to use the zig build system to generate documentation for my project. I followed the zig.guide page. Only the documentation for root.zig
populates on the webpage that is created from zig build docs
.
Whenever I try to import another file in root.zig
and expose it with pub
, the following error shows up when I open the webpage console:
error: can't index 'lib/WhateverFile.zig' because it has syntax errors
I have created a small reproducible example of my issue.
Directory is structured like:
src/
rank.zig
root.zig
build.zig
build.zig.zon
Here are the files:
rank.zig
//! Implementation of playing card ranks
/// This is a rank
pub const Rank = enum {
Nine,
};
root.zig
//! This module provides functions for dealing with spreadsheets.
const std = @import("std");
pub const Rank = @import("rank.zig").Rank;
/// A spreadsheet position
pub const Pos = struct {
/// (0-indexed) row
x: u32,
/// (0-indexed) column
y: u32,
/// The top-left position
pub const zero: Pos = .{ .x = 0, .y = 0 };
/// Illegal position
pub const invalid_pos: Pos = .{
.x = std.math.maxInt(u32),
.y = std.math.maxInt(u32),
};
};
build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "lib",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Install docs into zig-out/docs");
docs_step.dependOn(&install_docs.step);
}
build.zig.zon
.{
.name = "test_zig_docs",
.version = "0.0.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
Below is a screenshot of the error that appears when spinning up the webpage using python -m http.server 8000 -d docs/
as suggested by zig.guide.
Does anyone know what I am doing wrong? The rank.zig
file doesn’t have any syntax errors as I understand it.