Porting Syncthing to OpenWrt


just recently OpenWrt got support to add Go packages to the official sources and now I’m trying to port syncthing.

Currently I have problems to generate the assets required for the web interface:

go build github.com/syncthing/syncthing/cmd/syncthing
# github.com/syncthing/syncthing/cmd/syncthing
src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:38:13: undefined: auto.Assets
src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:45:20: undefined: auto.Assets
src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:128:28: undefined: auto.Generated
src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:129:24: undefined: auto.Generated

I understand that before compiling go run build.go assets is required, but as far as I understand this manual fireing of go commands it not supported by the build system. On the other hand, go generate is supported but doesn’t seem to create the required assets, as I hoped.

Is it possible to automatically create the assets if missing or ignore them and use an external folder instead, as for development mode?

1 Like

Not really, no. We could however make go generate do the right thing. Even so, without going through the build script the resulting binary will have no version information and generally be “unsupported” from our point of view.

Here’s a branch where go generate should do what you need: https://github.com/calmh/syncthing/tree/gogen

Note that you probably don’t want to do go generate on the whole source tree, just on the on or two relevant packages. You can use the build script to show you what commands it does;

jb@kvin:~/s/g/s/syncthing $ BUILDDEBUG=1 go run build.go build syncthing
runError: git describe --always --dirty
... in 26.227163ms
runError: git branch -a --contains
... in 130.495707ms
runError: git show -s --format=%ct
... in 6.753972ms
runPrint: go generate github.com/syncthing/syncthing/lib/auto github.com/syncthing/syncthing/cmd/strelaypoolsrv/auto
... in 857.033196ms
rm -r syncthing
runPrint: go build -i -v -ldflags -w -X main.Version=v0.14.49-rc.2+7-gaed5c1a5-gogen -X main.BuildStamp=1529997922 -X main.BuildUser=jb -X main.BuildHost=kvin.kastelo.net github.com/syncthing/syncthing/cmd/syncthing
... in 1.463617588s
... build completed in 2.329006744s
jb@kvin:~/s/g/s/syncthing $

That is,

$ go generate github.com/syncthing/syncthing/lib/auto \

$ go build -i -v -ldflags "-w \
  -X main.Version=v0.14.49-rc.2+7-gaed5c1a5-gogen \
  -X main.BuildStamp=1529997922 \
  -X main.BuildUser=jb \
  -X main.BuildHost=kvin.kastelo.net" \

(With the right version etc for you.) Odd quoting because the whole thing after -ldflags up to the package name is actually the value for the -ldflags parameter (not visible in the build script debug output).

With the help of @jefferyto I was able to set the version info, resulting in the following:

root@v2:/tmp/lib/syncthing# syncthing -version
syncthing v0.14.48 "Dysprosium Dragonfly" (go1.10 linux-mipsle) openwrt@openwrt 2018-06-27 20:11:06 UTC

Are there any requirements (or suggestions) for BuildUser and BuildHost? This seems to be (optionally) uploaded to data.syncthing.net

Yeah, it’s mostly to identify where the binary is from. openwrt@openwrt is perfectly fine unless you want something more detailed (like if there are different openwrt distributions or something).