Hello,
I am trying to cross-compile for Windows, from Linux (with go1.12 linux/amd64, gcc version 7.4).
I have added the following to app/victoria-metrics/makefile:
victoria-metrics-amd64:
CGO_ENABLED=1 GOARCH=amd64 GO111MODULE=on go build -mod=vendor -ldflags "$(GO_BUILDINFO)" -o bin/victoria-metrics-amd64.exe ./app/victoria-metrics
I then ran GOOS=windows GOARCH=amd64 make victoria-metrics-amd64 with this result:
```CGO_ENABLED=1 GOARCH=amd64 GO111MODULE=on go build -mod=vendor -ldflags "-X 'github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo.Version=-20190620-092722-heads-master-0-ga78b3db-dirty-e01c54bc'" -o bin/victoria-metrics-amd64 ./app/victoria-metrics
gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?
lib/memory/memory.go:31:10: undefined: sysTotalMemory
app/victoria-metrics/Makefile:30: recipe for target 'victoria-metrics-amd64' failed
make: * [victoria-metrics-amd64] Error 2
```
I do not have enough experience to proceed. Maybe you can help? Also, knowing the archictecture, is it feasible to run vm single node on Windows?
Thank you.
Unfortunately VictoriaMetrics isn't intended to run under Windows. But it would be great if somebody will add missing bits for running under Windows. I added missing stubs, but there is remaining problem with gozstd. It would be great if somebody could solve it. gozstd should already support Windows, but it wasn't tested and is outdated now.
My project with fastcache/ZSTD dependency compiles on Windows machine and runs under Windows with:
CGO_ENABLED=0 GOOS=windows GO111MODULE=on go build -o my-project-with-zstd.exe
Build under Windows from Ubuntu 18 machine passes with a command:
$ sudo apt-get install gcc-mingw-w64-x86-64
$ CGO_ENABLED=1 GOARCH=amd64 GOOS=windows GO111MODULE=on go build -a -installsuffix cgo -tags netgo -ldflags '-w -s -extldflags "-static"' -o my-project-with-zstd.exe .
Unfortunately, this binary compiled under Windows from Ubuntu 18 won't run on my Windows 10.
I've tried to compile VictoriaMetrics under Windows today and got a error:
..\..\lib\fs\fs.go:341:12: undefined: unix.Flock
..\..\lib\fs\fs.go:341:41: undefined: unix.LOCK_EX
..\..\lib\fs\fs.go:341:54: undefined: unix.LOCK_NB
..\..\lib\fs\fs.go:356:11: undefined: unix.Statfs_t
..\..\lib\fs\fs.go:357:12: undefined: unix.Fstatfs
So it seems CreateFlockFile function needs adaptation for Windows builds.
Possibly, LockFile and LockFileEx functions seem enough to help.
UPD: This SO answer points to github.com/juju/fslock go library.
I will try to implement this feature for VM.
I tried with to build on Ubuntu 18.04 / go v1.14 with:
CGO_ENABLED=1:
gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?
With CGO_ENABLED=0:
# github.com/VictoriaMetrics/VictoriaMetrics/lib/fs
lib/fs/fs.go:291:12: undefined: unix.Flock
lib/fs/fs.go:291:41: undefined: unix.LOCK_EX
lib/fs/fs.go:291:54: undefined: unix.LOCK_NB
lib/fs/fs.go:306:11: undefined: unix.Statfs_t
lib/fs/fs.go:307:12: undefined: unix.Fstatfs
lib/fs/reader_at.go:60:13: undefined: unix.Munmap
lib/fs/reader_at.go:74:12: undefined: fadviseSequentialRead
lib/fs/reader_at.go:123:15: undefined: unix.Mmap
lib/fs/reader_at.go:123:52: undefined: unix.PROT_READ
lib/fs/reader_at.go:123:68: undefined: unix.MAP_SHARED
lib/fs/reader_at.go:123:68: too many errors
Full build command: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 GO111MODULE=on go build -mod=vendor -o bin/victoria-metrics-amd64.exe ./app/victoria-metrics
The same for vmagent.
Thanks for looking into this.
For file locking, this works under Windows: https://github.com/gofrs/flock
Most helpful comment
My project with fastcache/ZSTD dependency compiles on Windows machine and runs under Windows with:
CGO_ENABLED=0 GOOS=windows GO111MODULE=on go build -o my-project-with-zstd.exeBuild under Windows from Ubuntu 18 machine passes with a command:
Unfortunately, this binary compiled under Windows from Ubuntu 18 won't run on my Windows 10.
I've tried to compile VictoriaMetrics under Windows today and got a error:
So it seems
CreateFlockFilefunction needs adaptation for Windows builds.Possibly, LockFile and LockFileEx functions seem enough to help.
UPD: This SO answer points to github.com/juju/fslock go library.
I will try to implement this feature for VM.