Building juju-core on Windows

John Arbash Meinel john at arbash-meinel.com
Wed Mar 13 12:53:59 UTC 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I figured I'd write up a summary of where I got to today, trying to
get juju-core compiled on Windows.

Short summary, I can get a custom compiled 32-bit go tools using
mingw. Compile libyaml, tweak goyaml and get 'go test' to pass for
goyaml. I made some progress in getting 64-bit tools working, but I'm
currently blocked on getting 64-bit libpthread.

The main blocker is 'goyaml' needing 'libyaml', and using cgo. Which
means we can't just cross-compile, and just downloading and using the
Go binary distribution for Windows isn't quite enough.

I did try following instructions here:
   http://code.google.com/p/go-wiki/wiki/WindowsBuild#Build
Though they aren't quite complete.

1) Install the base Mingw 32-bit system:

http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/

That worked reasonably well, and the instructions are good.

2) hg clone, cd go\src; all.bat

Unfortunately under Mingw's terminal, you can't just run a bat file.
After a bit of googling, I found:
  cmd "/c all.bat"
Worked. The tools seem to build fine, though one 'file' test failed to
properly detect a .png file. I wasn't too worried about it for now.
(Line endings could be a problem given PNG has a \r\n in its header
explicitly to look for line-ending corruption)

3) After all that, you end up with a 32-bit GCC compiler, and the
32-bit go binaries. (Set GOROOT, etc seemed to work fine.)

4) It turns out that 'goyaml' really does need libyaml to be
installed, though I didn't see any flags like '-lyaml' in the source
tree. Given all the .c code I wasn't sure, but the linker certainly
told me it wasn't working. :)

5) libyaml doesn't like to be compiled under Mingw without a bit of
tweaking. Specifically, you need set "YAML_DECLARE_STATIC=1" which
forces makes sure it exports the functions in the same name-mangling
consistent with static linking.

6) There are also some tweaks for building on Win32 because of stuff
like 'make install' defaults to installing to /usr/local/lib which
doesn't seem to be on the default search path for the mingw tools, and
I wasn't 100% sure how to configure them.

So instead after building the static library, I just copy it into the
goyaml dir, and set the LDFLAGS to look for it there.


7) On Windows, 'strdup' is available as '_strdup', so you need a
workaround like:
+#ifdef WIN32
+#define strdup _strdup
+#endif

There are a lot more funcs like this, but goyaml isn't calling them
directly.

8) I also didn't see how goyaml knows to link against -lyaml, so I added:

 // #cgo LDFLAGS: -lm -lpthread
+// #cgo windows LDFLAGS: -L. -lyaml
+// #cgo windows CFLAGS: -DYAML_DECLARE_STATIC=1
 // #cgo CFLAGS: -I. -DHAVE_CONFIG_H=1

 lp:~jameinel/goyaml/windows

9) After all this, I had a working 32-bit go and goyaml, and I could
do 'go test' and have the test suite pass. (Note that 'go build'
doesn't notice that we don't have 'strdup' available, you have to
actually build an executable for that.)

However, you can easily download the 64-bit tools, and I've been told
previously not to trust juju-core on 32-bit anyway. So off I went to
see if I could get that to work.

10) The original link describes where you can get the binary 64-bit
Mingw compiler, and then you copy it into your Mingw directory.

I then did a bunch of:

 mv gcc.exe gcc-old.exe
 cp x86_64-w64-mingw32-gcc.exe gcc.exe

So that the 'gcc' application was the 64-bit one.

Off-hand I did:
 gcc, ranlib, nm, ld
There are another 10 or so tools, but that was enough for me.

11) I then re-ran 'CFLAGS=YAML_DECLARE_STATIC=1 ./configure
- --disable-shared, make' and rebuilt libyaml. Then copied the
'libyaml.a' back into the goyaml source tree.

12) I then switch to not using my custom-compiled go, and just used
the go 1.0.3 binaries (x64) binaries.

At this point, goyaml seems happy, but it would appear that the
pthread that comes with the step (1) install is 32-bit only, and the
compiler tools you get in step (10) don't include pthread. My
google-fu so far makes it looks like you grab the 32-bit pthread code,
apply a patch to it, and then compile it yourself.

It is unclear though as the docs I found here:
http://sourceforge.net/apps/trac/mingw-w64/wiki/Compile%20pthreads
hint that 64-bit support should be available in pthread 2.9.0 which is
what pthread.h indicates it is.
Even so, the mingw binaries linked above don't have them. There is
some hope that the Cygwin packaging actually can include
'mingw64-x86_64' toolchain, which *does* have a pthreads support.

Anyway, I'm done for now, but I'll be back to hit it again tomorrow.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlFAducACgkQJdeBCYSNAAMhnACfUKom3MN9CKxRXMDxduTo6yd1
Jc8An2ZR1fPjuCQhXXmGLhs1F5O4kgOf
=HurD
-----END PGP SIGNATURE-----



More information about the Juju-dev mailing list