Installation¶
This guide covers every way to install Codefang and its companion UAST parser.
Prerequisites¶
Before you begin, make sure the following tools are available on your system:
| Requirement | Minimum Version | Notes |
|---|---|---|
| Go | 1.24+ | Required for go install and building from source |
| Git | 2.x | Used by history analyzers to walk repository objects |
| C compiler | GCC or Clang | CGO is required for libgit2 bindings |
| CMake | 3.14+ | Needed when building libgit2 from the vendored source |
| OpenSSL (dev headers) | 1.1+ | libgit2 HTTPS transport dependency |
CGO is required
Codefang links against libgit2 for high-performance Git repository access. The library is vendored and built automatically, but a working C toolchain and CGO_ENABLED=1 (the Go default) are mandatory.
Install from Source (Recommended)¶
The fastest way to get both binaries:
go install github.com/Sumatoshi-tech/codefang/cmd/codefang@latest
go install github.com/Sumatoshi-tech/codefang/cmd/uast@latest
This places codefang and uast in your $GOPATH/bin (or $GOBIN if set). Make sure that directory is on your $PATH:
Add to your shell profile
Append the export line above to your ~/.bashrc, ~/.zshrc, or equivalent so the binaries are always available.
Build from Source¶
For contributors or when you need a custom build:
git clone https://github.com/Sumatoshi-tech/codefang.git
cd codefang
make build # (1)!
make install # (2)!
- Builds libgit2, pre-compiles UAST mappings, then compiles both
uastandcodefangintobuild/bin/. - Copies the binaries to
~/.local/bin/. The Makefile will warn you if that directory is not on your$PATH.
What make build does¶
The build process has three stages:
graph LR
A[make libgit2] --> B[precompile UAST mappings]
B --> C[go build uast + codefang] - libgit2 -- The vendored C library in
third_party/libgit2is compiled as a static archive via CMake. This only happens once (subsequent builds skip it if the artifact already exists). - UAST mappings -- A code-generation step pre-compiles Tree-sitter language mappings into
pkg/uast/embedded_mappings.gen.gofor faster startup. - Go build -- Both binaries are compiled with version/commit metadata injected via
-ldflags.
Building libgit2 Separately¶
If you only need to rebuild the native library:
The static archive is installed to third_party/libgit2/install/. The Makefile automatically sets PKG_CONFIG_PATH, CGO_CFLAGS, and CGO_LDFLAGS so that subsequent Go builds find it.
Docker¶
A multi-stage Dockerfile is included at the repository root:
Run analysis on a local repository:
Run history analysis (the container needs the full .git directory):
Image size
The production image is built on a minimal base. The libgit2 static library and Tree-sitter grammars are embedded at build time, so no additional runtime dependencies are needed inside the container.
Verify Installation¶
After installing, confirm both binaries are working:
If either command is not found, verify that the installation directory is on your $PATH:
Platform Notes¶
Linux¶
Fully supported. Install build essentials if you do not already have a C compiler:
macOS¶
Fully supported. Xcode Command Line Tools provide the required C toolchain:
Apple Silicon
On ARM-based Macs you may need to point pkg-config at the Homebrew OpenSSL installation:
Windows¶
Not officially supported at this time. You can use WSL 2 with a Linux distribution and follow the Linux instructions above.
Next Steps¶
With both binaries installed, head to the Quick Start guide to run your first analysis.