Victoriametrics: Windows build

Created on 20 Jun 2019  Â·  4Comments  Â·  Source: VictoriaMetrics/VictoriaMetrics

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

runtime/cgo

gcc: error: unrecognized command line option ‘-mthreads’; did you mean ‘-pthread’?

github.com/VictoriaMetrics/VictoriaMetrics/lib/memory

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.

enhancement help wanted

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.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.

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WilliamDahlen picture WilliamDahlen  Â·  3Comments

pmitra43 picture pmitra43  Â·  3Comments

dima-vm picture dima-vm  Â·  3Comments

EricAntoni picture EricAntoni  Â·  3Comments

abualy picture abualy  Â·  3Comments