This page covers the setup of a development environment for contributing to Syncthing. It explains how to obtain the source code, install prerequisites, build the project, and run tests. For information about contribution guidelines and code style, see Code Contribution Guidelines. For details on the testing infrastructure, see Testing.
Syncthing development requires the following tools to be installed:
| Tool | Minimum Version | Purpose |
|---|---|---|
| Go | As specified in go.mod | Compilation and testing |
| Git | Any recent version | Source code management |
Additional tools are needed for specific development tasks:
| Tool | Purpose | When Required |
|---|---|---|
buf | Protocol buffer generation | When modifying .proto files (see build.go860-864) |
goversioninfo | Windows resource file generation | When building for Windows (see build.go686-742) |
fpm | Debian package creation | When building .deb packages (see build.go595-662) |
Sources: build.go860-864 build.go686-742 build.go595-662
Clone the Syncthing repository from GitHub:
For contributors planning to submit pull requests, fork the repository first on GitHub, then clone your fork and add the upstream remote:
Sources: README.md76-81 CONTRIBUTING.md56-58
Syncthing uses a custom Go-based build system implemented in build.go This script provides a unified interface for building, testing, and packaging across all platforms.
Build System Components
The build script defines multiple target configurations in build.go83-174 each specifying:
buildPkgs: Go packages to compile build.go69archiveFiles: Files to include in distribution archives build.go71installationFiles: Files for package installations (e.g., systemd units, man pages) build.go73debdeps: Debian package dependencies build.go66Sources: build.go63-174 build.sh1-37
The simplest way to build all Syncthing components:
When invoked with no arguments, the build script defaults to install all. This builds all packages found in cmd/* and places binaries in the bin/ directory. This is the recommended command during development as it provides maximum error checking across the entire codebase.
To build only the main Syncthing application:
Available targets as defined in build.go83-174:
syncthing: Main synchronization application build.go88stdiscosrv: Discovery server build.go133strelaysrv: Relay server build.go159The built binary will be placed in bin/syncthing (or bin/syncthing.exe on Windows).
Sources: build.go88-174 README.md76-81
Wrapper Script Features
./build.sh test which sets LOGGER_DISCARD=1 to reduce test output noise build.sh17prerelease command in build.sh24-31 runs multiple scripts to prepare for a release, including updating authors build.sh25 copyrights build.sh26 and translations via weblate build.sh27Sources: build.sh1-37 build.go10-40
Run the test suite across all packages:
This command:
-short flag by default.-long flag) build.go58Run the integration test suite:
The integration tests:
test/ directory.Run performance benchmarks:
This is often run via the wrapper to discard logs: ./build.sh bench build.sh21
Sources: build.go58-59 build.sh16-22
GUI assets must be regenerated when files in gui/ change:
The build system automatically checks if assets need regeneration by comparing modification times during normal builds.
When modifying .proto files in the proto/ directory:
This runs buf generate as specified in the build logic.
Generate mock implementations for testing:
Sources: build.go7-10
The build script supports numerous flags:
| Flag | Description |
|---|---|
-goos | Target operating system build.go42 |
-goarch | Target architecture build.go41 |
-no-upgrade | Disable upgrade functionality build.go43 |
-version | Set version string build.go44 |
-race | Enable race detector build.go46 |
-debug-binary | Create unoptimized binary for debugging build.go55 |
The build system determines the version using:
version flag build.go44"unknown-dev".Sources: build.go40-61
Key Points
Signed-off-by line CONTRIBUTING.md75-117go fmt and follow standard Go review comments CONTRIBUTING.md132-143Sources: CONTRIBUTING.md75-164 build.go10-40
The build process creates several files and directories listed in .gitignore:
| Path | Description |
|---|---|
bin/ | Compiled binaries .gitignore11 |
syncthing | Main binary (Unix) .gitignore1 |
stdiscosrv | Discovery server binary .gitignore2 |
*.tar.gz, *.zip | Distribution archives .gitignore3-4 |
coverage.out | Test coverage output .gitignore9 |
Create distribution archives:
The targets for these archives are defined in the targets map in build.go83
Sources: .gitignore1-21 build.go83-174
| Variable | Purpose |
|---|---|
BUILDDEBUG | Enable debug output in the build script build.go47 |
| Variable | Purpose |
|---|---|
LOGGER_DISCARD | Disable log output during tests build.sh17 |
Sources: build.go47 build.sh17
Create a .deb package:
The package configuration (dependencies, descriptions, and file mappings) is defined in the target struct for syncthing build.go88-131 and stdiscosrv build.go133-158
The syncthing target includes:
/usr/bin/syncthing build.go105.desktop files and icons build.go123-130Refresh this wiki