zig · 28 types · zero deps
Detect a project's type in Zig.
The Zig port of projectdetect — inspect a directory to see what project type(s) it is, walk a tree for every project root, and resolve which project a file belongs to. 28 built-in types, zero dependencies.
MIT licensed · no third-party dependencies · Zig 0.16
const projectdetect = @import("projectdetect"); var reg = try projectdetect.Registry.initWithBuiltins(gpa); defer reg.deinit(); const matches = try reg.detect(gpa, "."); defer gpa.free(matches); for (matches) |m| std.debug.print("{s} (via {s})\n", .{ m.type, m.indicator });
what you get
Project detection, ported faithfully to Zig.
The same detection model as the Go original — indicators, multi-match, and root-finding — with zero third-party dependencies.
28 built-in types
go, node, rust, python, ruby, java-maven/gradle, dotnet, terraform, docker-compose, swift, php, scala, cmake, autotools, r, zig, perl, matlab, plus eight static-site generators.
Four core APIs
detect(dir) for a single directory, find(root, opts) to walk a tree, resolveForPath(file) / Resolver to map a file to its project, and collectBuildExcludes(root) for build-artefact dirs.
Multi-match
One directory can match several types at once — a Go module that also ships a docker-compose.yml matches both. You get every match, not just the first.
Three indicator kinds
has_file (case-insensitive), has_glob for file-basename patterns, and has_subdir_glob for directory markers like *.xcodeproj.
Zero dependencies
No third-party imports — including a small built-in YAML reader for loading custom project types from a config file.
Faithful Go-port parity
The same detection model as the Go original, with two deliberate differences: no CEL indicators, and limited user-wide config discovery on Zig 0.16.
usage
Detect a directory, wire up the module.
Initialise a registry with the built-ins, then ask what a directory is. Wiring the dependency into build.zig takes two lines.
// Detect what this directory is var reg = try projectdetect.Registry.initWithBuiltins(gpa); defer reg.deinit(); const matches = try reg.detect(gpa, "."); defer gpa.free(matches); for (matches) |m| std.debug.print("{s}\n", .{ m.type });
// build.zig — wire up the dependency const pd = b.dependency("projectdetect", .{ .target = target, .optimize = optimize, }); exe.root_module.addImport( "projectdetect", pd.module("projectdetect"), );
- detect(dir)
- find(root, opts)
- resolveForPath(file)
- Resolver
- collectBuildExcludes(root)
install
Add it to your build.
One zig fetch pulls it straight from GitHub into your build.zig.zon. Requires Zig 0.16.
zig fetch --save git+https://github.com/richardwooding/projectdetect-zig
There's no Zig package registry — fetch it straight from the GitHub repo. This is the Zig port of projectdetect (the Go original).