Skip to content

Instantly share code, notes, and snippets.

@lantrix
Last active December 22, 2016 04:46
Show Gist options
  • Select an option

  • Save lantrix/a5706ed316c12640076a to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/a5706ed316c12640076a to your computer and use it in GitHub Desktop.
Cross compile packer for Windows from Mac or Linux

Packer Cross Compile Windows binaries

Setup GO

  • Setup Golang.
  • Install gox for cross platform compilation:
    • go get -u github.com/mitchellh/gox

Compile Packer

Get Source

Get packer source and download dependencies

git clone https://github.com/mitchellh/packer.git $GOPATH/src/github.com/mitchellh/packer
cd $GOPATH/src/github.com/mitchellh/packer
make updatedeps

Cross Compile

To cross compile packer in its entirety for Windows from linux or a mac:

cd $GOPATH/src/github.com/mitchellh/packer
gox -osarch="windows/amd64" -output="pkg/{{.OS}}_{{.Arch}}/{{.Dir}}"
gox -osarch="windows/amd64" -output="pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}" ./...
rm pkg/windows_amd64/packer-packer.exe

Binaries are now in the pkg folder

cd $GOPATH/src/github.com/mitchellh/packer/pkg/windows_amd64/
ls -l *.exe

Submodule only build

Build just a specific submodule of packer (e.g. only builder-vmware-iso). This is much faster than re-crosscompiling all the things.

cd $GOPATH/src/github.com/mitchellh/packer
gox -osarch="windows/amd64" -output="pkg/{{.OS}}_{{.Arch}}/{{.Dir}}"
gox -osarch="windows/amd64" -output="pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}" github.com/mitchellh/packer/plugin/builder-vmware-iso

Compile Packer Azure Plugins

Get Source

Get Azure Packer plugin source

git clone https://github.com/Azure/packer-azure.git $GOPATH/src/github.com/Azure/packer-azure

Cross Compile

cd $GOPATH/src/github.com/Azure/packer-azure
gox -osarch="windows/amd64" -output="pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}" github.com/Azure/packer-azure/packer/plugin/...

Binaries

Binaries are now in the pkg folder

cd $GOPATH/src/github.com/Azure/packer-azure/pkg/windows_amd64/
ls -l *.exe
@lantrix
Copy link
Author

lantrix commented Sep 29, 2015

Thanks @mefellows for the submodule only tip!

@nzspambot
Copy link

First hit on google not what I was after :/

@lantrix
Copy link
Author

lantrix commented Nov 13, 2015

@nzspambot I've updated it for Azure plugins 👍 but it's still compiling windows binaries on Mac/Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment