Error building Syncthing v2 on OpenBSD

Hi

I’m trying to upgrade the OpenBSD package to v2, but there’s a build error I don’t understand. Maybe someone with Go knowledge will know what it means.

lib/syncthing/globalmigrations.go:10:2: code in directory /usr/ports/pobj/syncthing-2.0.12/go/src/github.com/syncthing/syncthing/internal/db expects import "github.com/syncthing/syncthing/internal/db/sqlite"

The ongoing discussion on the ports mailing list can be found here.

Build log
+++ Tue Dec 23 11:01:03 -03 2025
===>  Patching for syncthing-2.0.12
===>   Applying OpenBSD patch patch-build_go
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Print build commands
|
|Index: build.go
|--- build.go.orig
|+++ build.go
--------------------------
Patching file build.go using Plan A...
Hunk #1 succeeded at 532.
done
===>   Applying OpenBSD patch patch-cmd_syncthing_main_go
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|use unveil(2) to limit execution to
|- restarting itself
|- xdg-open(1) aka. to open the web interface
|
|Index: cmd/syncthing/main.go
|--- cmd/syncthing/main.go.orig
|+++ cmd/syncthing/main.go
--------------------------
Patching file cmd/syncthing/main.go using Plan A...
Hunk #1 succeeded at 31.
Hunk #2 succeeded at 215.
done
===>   Applying OpenBSD patch patch-lib_build_build_go
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Disable phone-home calls / anonymous usage reporting
|
|Index: lib/build/build.go
|--- lib/build/build.go.orig
|+++ lib/build/build.go
--------------------------
Patching file lib/build/build.go using Plan A...
Hunk #1 succeeded at 83.
done
===>  Compiler link: clang -> /usr/bin/clang
===>  Compiler link: clang++ -> /usr/bin/clang++
===>  Compiler link: cc -> /usr/bin/cc
===>  Compiler link: c++ -> /usr/bin/c++
===>  Generating configure for syncthing-2.0.12
===>  Configuring for syncthing-2.0.12
===>  Building for syncthing-2.0.12
cd /usr/ports/pobj/syncthing-2.0.12/go/src/github.com/syncthing/syncthing && /usr/bin/env -i GOMAXPROCS=1 GO386=softfloat GOCACHE="/usr/ports/pobj/syncthing-2.0.12/go-cache" GOTOOLCHAIN=local TMPDIR="/usr/ports/pobj/syncthing-2.0.12/build-amd64" GOPROXY=invalid://ports.should.not.fetch.at.buildtime/ GO111MODULE=off GOPATH="/usr/ports/pobj/syncthing-2.0.12/go:/usr/local/go-pkg" PORTSDIR="/usr/ports" LIBTOOL="/usr/bin/libtool"  PATH='/usr/ports/pobj/syncthing-2.0.12/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin' PREFIX='/usr/local'  LOCALBASE='/usr/local' X11BASE='/usr/X11R6'  CFLAGS='-O2 -pipe'  TRUEPREFIX='/usr/local' DESTDIR=''  HOME='/syncthing-2.0.12_writes_to_HOME' PICFLAG="-fpic"  BINGRP=bin BINOWN=root BINMODE=755 NONBINMODE=644  DIRMODE=755  INSTALL_COPY=-c INSTALL_STRIP=  MANGRP=bin MANOWN=root MANMODE=644 BSD_INSTALL_PROGRAM="/usr/ports/pobj/syncthing-2.0.12/bin/install -c  -m 755"  BSD_INSTALL_SCRIPT="/usr/ports/pobj/syncthing-2.0.12/bin/install -c -m 755"  BSD_INSTALL_DATA="/usr/ports/pobj/syncthing-2.0.12/bin/install -c -m 644"  BSD_INSTALL_MAN="/usr/ports/pobj/syncthing-2.0.12/bin/install -c -m 644"  BSD_INSTALL_PROGRAM_DIR="/usr/ports/pobj/syncthing-2.0.12/bin/install -d -m 755"  BSD_INSTALL_SCRIPT_DIR="/usr/ports/pobj/syncthing-2.0.12/bin/install -d -m 755"  BSD_INSTALL_DATA_DIR="/usr/ports/pobj/syncthing-2.0.12/bin/install -d -m 755"  BSD_INSTALL_MAN_DIR="/usr/ports/pobj/syncthing-2.0.12/bin/install -d -m 755" go run build.go -version v2.0.12  -no-upgrade install syncthing
lib/syncthing/globalmigrations.go:10:2: code in directory /usr/ports/pobj/syncthing-2.0.12/go/src/github.com/syncthing/syncthing/internal/db expects import "github.com/syncthing/syncthing/internal/db/sqlite"
2025-12-23 11:01:41 INF exit status 1
exit status 1
*** Error 1 in . (Makefile:38 'do-build')
*** Error 2 in . (/usr/ports/infrastructure/mk/bsd.port.mk:3063 '/usr/ports/pobj/syncthing-2.0.12/build-amd64/.build_done': @cd /usr/ports/n...)
*** Error 2 in /usr/ports/net/syncthing (/usr/ports/infrastructure/mk/bsd.port.mk:2710 'build': @lock=syncthing-2.0.12;  export _LOCKS_HELD=...)
--- Tue Dec 23 11:01:42 -03 2025
Ports diff
Index: Makefile
===================================================================
RCS file: /cvs/ports/net/syncthing/Makefile,v
diff -u -p -r1.73 Makefile
--- Makefile	22 Jul 2025 20:20:25 -0000	1.73
+++ Makefile	23 Dec 2025 14:06:16 -0000
@@ -1,6 +1,6 @@
 COMMENT =	open decentralized synchronization utility

-V =		1.30.0
+V =		2.0.12
 DISTNAME =	syncthing-${V}
 DISTFILES =	syncthing-source-v${V}${EXTRACT_SUFX}

Index: distinfo
===================================================================
RCS file: /cvs/ports/net/syncthing/distinfo,v
diff -u -p -r1.50 distinfo
--- distinfo	4 Jul 2025 19:19:39 -0000	1.50
+++ distinfo	23 Dec 2025 14:06:16 -0000
@@ -1,2 +1,2 @@
-SHA256 (syncthing-source-v1.30.0.tar.gz) = 7xvnHGZ1PAQhKrHJxUjmeNRoutmNxUYeg1QKTvXC/Lo=
-SIZE (syncthing-source-v1.30.0.tar.gz) = 16142834
+SHA256 (syncthing-source-v2.0.12.tar.gz) = VgBK5tl0qjh8PGpzTrmKr9XWFZ/GV6H0xhjgsYFPra4=
+SIZE (syncthing-source-v2.0.12.tar.gz) = 62613260
Index: patches/patch-build_go
===================================================================
RCS file: /cvs/ports/net/syncthing/patches/patch-build_go,v
diff -u -p -r1.24 patch-build_go
--- patches/patch-build_go	4 Jun 2025 20:07:43 -0000	1.24
+++ patches/patch-build_go	23 Dec 2025 14:06:16 -0000
@@ -3,7 +3,7 @@ Print build commands
 Index: build.go
 --- build.go.orig
 +++ build.go
-@@ -549,7 +549,7 @@ func appendParameters(args []string, tags []string, pk
+@@ -532,7 +532,7 @@ func appendParameters(args []string, tags []string, pk

  	if !debugBinary {
  		// Regular binaries get version tagged and skip some debug symbols
Index: patches/patch-cmd_syncthing_main_go
===================================================================
RCS file: /cvs/ports/net/syncthing/patches/patch-cmd_syncthing_main_go,v
diff -u -p -r1.3 patch-cmd_syncthing_main_go
--- patches/patch-cmd_syncthing_main_go	15 Jun 2025 16:42:21 -0000	1.3
+++ patches/patch-cmd_syncthing_main_go	23 Dec 2025 14:06:16 -0000
@@ -5,8 +5,8 @@ use unveil(2) to limit execution to
 Index: cmd/syncthing/main.go
 --- cmd/syncthing/main.go.orig
 +++ cmd/syncthing/main.go
-@@ -29,6 +29,8 @@ import (
- 	"syscall"
+@@ -31,6 +31,8 @@ import (
+ 	"text/tabwriter"
  	"time"

 +	"golang.org/x/sys/unix"
@@ -14,23 +14,28 @@ Index: cmd/syncthing/main.go
  	"github.com/alecthomas/kong"
  	"github.com/gofrs/flock"
  	"github.com/thejerf/suture/v4"
-@@ -206,6 +208,19 @@ func defaultVars() kong.Vars {
- }
-
+@@ -213,6 +215,24 @@ func defaultVars() kong.Vars {
  func main() {
+ 	// Create a parser with an overridden help function to print our extra
+ 	// help info.
++
 +	if err := unix.Unveil("/", "rwc"); err != nil {
 +		panic(err)
 +	}
++
 +	if err := unix.Unveil("/usr/local/bin/syncthing", "rx"); err != nil {
 +		panic(err)
 +	}
++
 +	if err := unix.Unveil("/usr/local/bin/xdg-open", "rx"); err != nil {
 +		panic(err)
 +	}
++
 +	if err := unix.UnveilBlock(); err != nil {
 +		panic(err)
 +	}
 +
- 	// First some massaging of the raw command line to fit the new model.
- 	// Basically this means adding the default command at the front, and
- 	// converting -options to --options.
++
+ 	var entrypoint CLI
+ 	parser, err := kong.New(
+ 		&entrypoint,
Index: patches/patch-lib_build_build_go
===================================================================
RCS file: /cvs/ports/net/syncthing/patches/patch-lib_build_build_go,v
diff -u -p -r1.4 patch-lib_build_build_go
--- patches/patch-lib_build_build_go	28 Nov 2024 11:47:47 -0000	1.4
+++ patches/patch-lib_build_build_go	23 Dec 2025 14:06:16 -0000
@@ -3,7 +3,7 @@ Disable phone-home calls / anonymous usa
 Index: lib/build/build.go
 --- lib/build/build.go.orig
 +++ lib/build/build.go
-@@ -74,7 +74,7 @@ func setBuildData() {
+@@ -83,7 +83,7 @@ func setBuildData() {

  	exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z]+[\d\.]+)?$`)
  	IsRelease = exp.MatchString(Version)
Current Makefile
COMMENT =	open decentralized synchronization utility

V =		2.0.12
DISTNAME =	syncthing-${V}
DISTFILES =	syncthing-source-v${V}${EXTRACT_SUFX}

CATEGORIES =	net
HOMEPAGE =	https://syncthing.net/

MAINTAINER =	Edd Barrett <edd@openbsd.org>, \
		Klemens Nanni <kn@openbsd.org>

# MPL 2.0
PERMIT_PACKAGE = Yes

# uses unveil()
WANTLIB += c pthread

SITES = https://github.com/syncthing/syncthing/releases/download/v${V}/

WRKDIST =		${WRKDIR}/syncthing
WRKSRC =		${WRKDIR}/go/src/github.com/syncthing/syncthing

MODULES =		lang/go
MODGO_TYPE =		bin

# Syncthing contains a lot of stuff that end users wouldn't be interested in,
# so we package only these binaries.
ST_CMDS =	syncthing stdiscosrv strelaysrv

MAKE_ENV =	GOMAXPROCS=${MAKE_JOBS}

# If at any point quic is busted for our in-tree go version, then you can
# temporarily add `-tags noquic` to at least get syncthing building (albeit
# without quic support obviously). When you do that, some more tests will fail.
do-build:
.for cmd in ${ST_CMDS}
	cd ${WRKSRC} && ${MODGO_CMD} run build.go -version v${V} \
		-no-upgrade install ${cmd}
.endfor

# Connections test hangs and times out. This doesn't appear to interfere with
# day-to-day running of Syncthing though.
# https://github.com/syncthing/syncthing/issues/8421
do-test:
	cd ${WRKSRC} && ${MODGO_CMD} run build.go test

do-install:
.for cmd in ${ST_CMDS}
	${INSTALL_PROGRAM} ${WRKSRC}/bin/${cmd} ${PREFIX}/bin/
.endfor
.for sec in 1 5 7
	${INSTALL_MAN} ${WRKSRC}/man/*.${sec} ${PREFIX}/man/man${sec}/
.endfor

.include <bsd.port.mk>

syncthing.tar.gz (4.3 KB)

I don’t know, but you’re building in non-module mode with a GOPATH, which is not something most other people do since many years. I would suspect you have a bad checkout, strange patch, or mix of versions or something.

I’d start with just downloading our source tarball, unpacking, and running build.go. Does it fail the same way? Then we can troubleshoot. If not, figure out what difference causes the problem.

1 Like

This worked for me on a blank VM at least:

vultr# pkg_add go curl
quirks-7.147 signed on 2025-12-23T03:08:25Z
go-1.25.1: ok
curl-8.16.0:nghttp2-1.67.1: ok
curl-8.16.0:nghttp3-1.12.0: ok
curl-8.16.0:ngtcp2-1.16.0: ok
curl-8.16.0: ok
vultr# curl -sL https://github.com/syncthing/syncthing/releases/download/v2.0.12/syncthing-source-v2.0.12.tar.gz | tar zxf -
vultr# cd syncthing/
vultr# go run build.go
ok  	github.com/syncthing/syncthing/meta	0.017s [no tests to run]
vultr# ./bin/syncthing --version
syncthing v2.0.12 "Hafnium Hornet" (go1.25.1 openbsd-amd64) root@vultr.guest 2025-12-23 15:51:38 UTC
vultr# uname -a
OpenBSD vultr.guest 7.8 GENERIC.MP#1 amd64

You’re right, the build from source works here too (on real hardware).

I don’t know, but you’re building in non-module mode with a GOPATH, which is not something most other people do since many years.

Yeah, the v1 package was built like that, and I’m a new contributor so I tried to keep the changes minimal. But I’ll see if I can make it build in “module mode”. I know another Go package that does that.

What is the module name for v2? The Go package I’ve found only goes up to v1.30.0.

I got it to build by removing the canonical import path comment from the package internal/db/interface.go.

-package db // import "github.com/syncthing/syncthing/internal/db/sqlite"
+package db

It’s building, installing and running without issues.

Without a v2 import path, I cannot build it in module mode using the OpenBSD ports infrastructure.

2 Likes

I don’t know where that came from, but it’s obviously incorrect. I removed it, thanks for finding it.

2 Likes