Published on

How to Build Windows Go Binaries on Mac

Authors

A GoLang project I work with had to be usable on Windows.

Luckily GoLang can and does compile to multiple platforms. But as far as I can tell you have to run the build on that platform.

My immediate knee jerk reaction in a situation like this is can I find a Windows docker image that I can use to build the project for me? There are images but there is one huge caveat:

Windows requires the host OS version to match the container OS version.

ಠ_ಠ

Ok, so a container won't work. The next obvious option in this line of thinking is a virtual machine. A quick Google later and I found there are vagrant files to provision Windows 10!

To do this I simply ran:

vagrant init vdelarosa/windows-10
vagrant up

Voila! I have Windows running with full admin rights. I then proceeded to install Go for Windows and built my project from there. I mounted a folder from my host machine and dropped the compiled exe there.

One caveat I found with using Windows from a Mac host is that for some reason the Mac keyboard layout is picked up incorrectly on Windows. I could not find an easy way to fix this. As a workaround, I used the on-screen keyboard on Windows to see where the keys I needed were. It was not perfect but it got the job done.