Building Juju 2.5.0 on Windows


I’m trying to work out how we build Windows binaries. Is it just that we cross compile?

Reading through the build bot I see:

Which does:

  • export GOPATH=/var/lib/jenkins/workspace/BuildJuju-windows-amd64/_build
  • export GOARCH=amd64
  • export GOOS=windows
  • SERIES=win2012
  • go version
    go version go1.11.5 linux/amd64
  • go install
  • juju_exe=/var/lib/jenkins/workspace/BuildJuju-windows-amd64/_build/bin/windows_amd64/juju.exe
  • iss_dir=/var/lib/jenkins/workspace/BuildJuju-windows-amd64/_build/src/

That seems pretty clear that we are cross compiling.

The big issue is that it seems our new dependency on and are causing real problems for me to just go install

The first problem was:

$ go install -v
vendor\\coreos\pkg\dlopen\dlopen.go:21:11: fatal error: dlfcn.h: No such file or directory
 // #include <dlfcn.h>
compilation terminated.

Searching around on the web seems there are other coreos complaints about missing this file, but also turns up:

Which has Make targets for mingw and visual studio 12 targets. (Though the Visual Studio Community edition seems to be 2017?)

Anyway, downloading that, and then copying dlfcn.h and libdlfcn.a to the mingw64 lib and include dirs gets past the first issue, then gives:

$ time go install -v
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../lib/libdl.a(dlfcn.o):dlfcn.c:(.text+0x374): undefined reference to `EnumProcessModules'
collect2.exe: error: ld returned 1 exit status

However, that seems to be just that you need to add “-lpsapi” for dlfcn-win32. Now, that requires editing a “vendor” directory, which I’m not fond of, but it makes progress.

But after doing all that, I then get:

$ time go install -v
util\util_cgo.go:122:11: could not determine kind of name for C.my_sd_pid_get_owner_uid
util\util_cgo.go:121:10: could not determine kind of name for C.uid_t
gcc errors for preamble:
util\util_cgo.go:24:46: error: unknown type name 'uid_t'; did you mean 'pid_t'?
 // my_sd_pid_get_owner_uid(void *f, pid_t pid, uid_t *uid)

I haven’t found a definitive reason why we’re missing ‘uid_t’. AFAICT it is supposed to be defined in <sys/types.h> which is clearly being imported.

I feel like maybe the answer is that for jujud on windows we shouldn’t be including coreos. Because if we are, is it actually getting the right definitions that Windows needs for all of those header files, or is it compiling against the Linux definitions.



That sucks, we do have a windows box to play with on aws, I wonder if we could build on there instead?


I had a multitude of issues when I tried to run the Windows binaries related to external deps. If I have to work with Juju in Windows I always do so via WSL. Which works fine and dandy :slight_smile:


So it seems that in 2.5.0 we updated our dependency on the coreos package, (with ~60 new commits going but all in 2016).

The problematic commit seems to be:

commit 17b531ae5d2ab59869f63e42a84ea5d772cfb995
Author: Iago López Galeiras <>
Date:   Mon Feb 1 13:31:49 2016 +0100

    sdjournal: dlopen libsystemd instead of linking against it

    This allows not having to link users of the library to libsystemd,
    detect at runtime if it exists or not and react accordingly.

Of course, the claim there is that now it doesn’t actually depend on libsystemd. (with the particular caveat that now we do depend on dlopen/libdl.)

It feels like the best route forward would be to change the code in ‘service/*’ to not import anything related to systemd. service/agentconf.go has a valid comment at the top that everything in the file is systemd specific, discovery.go would be able to notice that we wouldn’t be able to call systemd.IsRunning() anyway, since there wouldn’t be a systemd bus on Windows. ‘service/service.go’ needs a bit more rework, as it is full of case statements, trying to be the abstraction for service implementations. But we could change it to more of a Registry based system, rather than hard-coded cases.