I am trying to compile Syncthing tools, and specifically stindex for Android ARM. There is no information on building the tools in the Docs, but I have found this forum post by @Catfriend1 and trying to use a similar command.
go run build.go -goos android -goarch arm build all
but there are no binaries after the compilation. I am building on Windows, if that matters. When I build Windows binaries, then a bunch of Windows executables are also placed in the bin folder, but there is nothing like that when building for Android.
I have both the NDK and the toolchain, and I can build the actual syncthing binary for Android, so this is not the issue. There are no visible errors, it is just that the bin folder is empty once the compiling has finished.
Anyhow, I have now tried using
go run build.go -goos linux -goarch arm build all
but there is nothing in bin after the compilation either.
I don’t think build all is a thing that works. It creates the appropriate command line for the go compiler, but it doesn’t appear to create binaries for the things. build otherwise puts the binaries in the current dir.
You can do the equivalent yourself, getting a binary that just lacks version tagging:
jb@kvin:../syncthing/syncthing % GOOS=linux GOARCH=arm go build ./cmd/stindex
jb@kvin:../syncthing/syncthing % ls -l stindex
-rwxr-xr-x 1 jb staff 14795445 Oct 13 17:27 stindex*
jb@kvin:../syncthing/syncthing % file stindex
stindex: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, Go BuildID=5V6OT0i4Bx-IMNEeWGGH/shFfFThDt9BcwDfpm1om/8ZsxJz5RxqfDXUW0oVQi/FGxD0AixP3GmgxOK7lQV, not stripped
jb@kvin:../syncthing/syncthing %
Giving go build more than one package on the same command line appears to not create any binaries at all.
It does, but it doesn’t seem to be possible to do cross-compiling for Android like that, does it? It only seems to work for building binaries for the host OS…
I do build Android binaries under Windows with
go run build.go -goos android -goarch arm zip
but this command builds only the syncthing binary, and not the other tools.
Edit: For the record,
go run build.go -goos android -goarch arm
fails with
runPrint: go install -v -tags purego -trimpath -ldflags -w -X github.com/syncthing/syncthing/lib/build.Version=v1.17.0-rc.3.dev.12.g0e52ce83 -X github.com/syncthing/syncthing/lib/build.Stamp=1621276987 -X github.com/syncthing/syncthing/lib/build.User=tomasz86 -X github.com/syncthing/syncthing/lib/build.Host=tomasz86 -X github.com/syncthing/syncthing/lib/build.Tags=purego,noupgrade github.com/syncthing/syncthing/cmd/stcompdirs github.com/syncthing/syncthing/cmd/stcrashreceiver github.com/syncthing/syncthing/cmd/stdisco github.com/syncthing/syncthing/cmd/stdiscosrv github.com/syncthing/syncthing/cmd/stevents github.com/syncthing/syncthing/cmd/stfileinfo github.com/syncthing/syncthing/cmd/stfinddevice github.com/syncthing/syncthing/cmd/stfindignored github.com/syncthing/syncthing/cmd/stgenfiles github.com/syncthing/syncthing/cmd/strelaypoolsrv github.com/syncthing/syncthing/cmd/strelaysrv github.com/syncthing/syncthing/cmd/stsigtool github.com/syncthing/syncthing/cmd/stvanity github.com/syncthing/syncthing/cmd/stwatchfile github.com/syncthing/syncthing/cmd/syncthing github.com/syncthing/syncthing/cmd/uraggregate github.com/syncthing/syncthing/cmd/ursrv
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
go install: cannot install cross-compiled binaries when GOBIN is set
exit status 1
exit status 1
while
go run build.go -goos android -goarch arm build
does work, but it builds only the syncthing binary without the tools (i.e. same as when using zip, etc.)
go run build.go -goos android -goarch arm build strelaysrv
Note the last argument. This works for build targets defined in build.go. strelaysrv is one of those; stindex isn’t because we’ve never distributed it.