Synthing uses 'git version' command even for a tarball

I’m trying to write a ebuild for syncthing in Gentoo. The problem is the ebuild downloads a tarball (not a git master), and build.go tries to run ‘git version’ in version() function. Which fails, since there is no local git repository. And which fails the entire build.

Yes. Building from the git repo is the only “supported” way. That said, if you only use tarballs of official releases, you can easily build it yourself. The build process basically does the following.

Make sure GOPATH is set so that the source is checked out into $GOPATH/src/github.com/syncthing/syncthing.

Grab the godep dependency (there are more, but they are for test coverage and things like that you probably don’t need to care about):

go get -v github.com/tools/godep

If you’re building without internet access, just make sure to have a working godep binary in your PATH and the rest can be skipped.

Then build the binary, while stamping it with the variables figured out from git;

godep go build -ldflags "-w -X main.Version v0.9.8+9-gfaf519a \
  -X main.BuildStamp 1408971319 -X main.BuildUser jb \
  -X main.BuildHost jborg-mbp.local -X main.BuildEnv default" \
  -tags noupgrade ./cmd/syncthing

(split for clarity)

In reality the entire string -w ... default is one argument to -ldflags.

Set BuildVersion to whatever you downloaded (in that format, with initial v), BuildStamp to the current time in epoch seconds (real build uses time of last commit for reproducability, but whatever), BuildUser and BuildHost to sensible values, BuildEnv to default and off you go.

If the presence of godep is a dealbreaker you can trivially simulate it with just a manual tweak to GOPATH, so let me know in that case.

Edit: Added -tags noupgrade to disable the built in upgrading mechanism.

Thanks a lot! -tags option does not work for me in the 0.9.8 version

It certainly does for me. Show me what happens?

Sorry, I added that to the ldflags string instead of a new argument. Now works.

1 Like