This document describes methods for building BirdNET-Go from source.
There are two primary approaches:
- Using the Devcontainer (Recommended for Development): Provides a consistent, pre-configured Docker environment with all dependencies installed. Ideal for contributing or making code changes.
- Building Locally (Using Task): Uses the
task
build tool (Taskfile.yml
) directly on your host machine. Requires manual installation of some prerequisites but is the standard way to build binaries.
For development work within VSCode, using the provided devcontainer is highly recommended.
- Open the project directory in VSCode.
- Ensure you have Docker installed and the Remote Development extension pack.
- Press
F1
orShift-Command-P
(Mac) /Ctrl+Shift+P
(Windows/Linux), typeReopen in Container
, and select it. - VSCode will build the container defined in
.devcontainer/devcontainer.json
and reopen the project inside it.
Inside the Devcontainer:
- All Go, CGO, TensorFlow, FFmpeg, and SoX dependencies are pre-installed.
- Your source code is mounted into the container.
- An
air
development server (.air.toml
) is automatically started. It watches for code changes (.go
,.html
,.css
,.js
, etc.) and triggers:- Tailwind CSS recompilation.
- Go application rebuild.
- Live reload of the running application.
- You can access the development web server at http://localhost:8080.
Devcontainer Notes:
- Dependency Changes: If you modify
.devcontainer/devcontainer.json
, use the "Rebuild Container" command in VSCode. - Docker Engine: Ensure your host has a full Docker engine installation (not just
docker.io
), asbuildx
support is needed for potential cross-compilation features within the container.
This project uses Task (Taskfile.yml
) as its build system. It simplifies building, testing, and managing dependencies.
- Go: Install the Go programming language (version 1.21 or later recommended). Follow the official Go installation guide.
- Task: Install the
task
executable. Follow the Task installation guide. - Git: Needed to clone repositories (BirdNET-Go and TensorFlow headers).
- wget/curl: Needed by
task
to download TFLite libraries. - Standard Build Tools: Ensure you have
gcc
,make
, etc. (build-essential
on Debian/Ubuntu). - (Optional)
air
: For live-reloading development server locally (if not using the Devcontainer). Install viago install github.com/cosmtrek/air@latest
. - (Optional) Node.js/npm: Required by
task generate-tailwindcss
andair
for Tailwind CSS generation. - (Optional) MinGW (for Windows Cross-Compilation): If building the Windows binary on Linux, install
mingw-w64
. On Debian/Ubuntu:sudo apt update sudo apt install mingw-w64-tools gcc-mingw-w64-x86-64
- TensorFlow Lite C Library:
task
will automatically download the correct pre-compiled library (from tphakala/tflite_c) for your target OS/architecture when you run a build task. It places the library in the expected system path (e.g.,/usr/lib
,/usr/local/lib
,/opt/homebrew/lib
, or/usr/x86_64-w64-mingw32/lib
for Windows cross-compile) and creates necessary symlinks. - TensorFlow Headers:
task
checks if TensorFlow source code (needed for C header files for CGO) is present in$HOME/src/tensorflow
. If not, it clones the specific tag ({{TFLITE_VERSION}}
) required.
Navigate to the cloned BirdNET-Go project directory in your terminal.
-
Build for your native OS/Architecture:
task build # Or simply 'task'
This automatically detects your OS and architecture and runs the appropriate build task (e.g.,
task linux_amd64
). The binary will be placed in thebin/
directory (e.g.,bin/birdnet-go
). -
Cross-Compile for a specific target:
# Example: Build for Windows AMD64 (requires MinGW on Linux host) task windows_amd64 # Example: Build for Linux ARM64 (might require cross-compiler tools if not on ARM64 host) task linux_arm64 # Example: Build for macOS ARM64 (Apple Silicon) task darwin_arm64
See
Taskfile.yml
for all available targets (linux_amd64
,linux_arm64
,windows_amd64
,darwin_amd64
,darwin_arm64
). Binaries appear inbin/
(e.g.,bin/birdnet-go.exe
). -
Clean Build Artifacts:
task clean
- Run all tests:
task test
- Run tests with verbose output:
task test-verbose
- Run tests with coverage report:
Coverage report will be generated in
task test-coverage
coverage/coverage.html
.
If you prefer local development with automatic rebuilding and restarting on changes (similar to the Devcontainer experience):
- Ensure
air
is installed (go install github.com/cosmtrek/air@latest
). - Ensure Node.js/npm is installed for Tailwind CSS generation.
- Prepare dependencies (TensorFlow headers/library) by running a build task once (e.g.,
task build
). - Start the
air
server:air
air
will use the configuration in.air.toml
to watch files, recompile Tailwind CSS, rebuild the Go binary, and restart the server on changes.