Bug 1253668 - Create cross build for windows amd64
Create cross build for windows amd64
Product: Fedora
Classification: Fedora
Component: golang (Show other bugs)
Unspecified Linux
unspecified Severity unspecified
: ---
: ---
Assigned To: Vincent Batts
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2015-08-14 08:18 EDT by Viacheslav Dubrovskiy
Modified: 2015-09-03 09:58 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2015-09-03 09:58:50 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Viacheslav Dubrovskiy 2015-08-14 08:18:35 EDT
Description of problem:
Some time need build binaries for windows on linux host. It would be very convenient to do so could golang.

Version-Release number of selected component (if applicable):

How reproducible:
GOOS=windows GOARCH=amd64 go build

Steps to Reproduce:
1. install golang
2. GOOS=windows GOARCH=amd64 go build

Expected results:
The binaries for windows.

diff --git a/golang.spec b/golang.spec
index 8ea0170..2fdd3da 100644
--- a/golang.spec
+++ b/golang.spec
@@ -49,7 +49,7 @@ URL:            http://golang.org/
 Source0:        https://storage.googleapis.com/golang/go%{go_version}.src.tar.gz
 # go1.5 bootstrapping. The compiler is written in golang.
-BuildRequires:  golang > 1.4
+BuildRequires:  golang > 1.4 mingw64-gcc-c++ mingw64-gcc
 # use the arch dependent path in the bootstrap
 Patch212:       ./golang-1.5-bootstrap-binary-path.patch
@@ -236,6 +236,14 @@ CC_FOR_TARGET="gcc" \
 GOOS=linux \
 GOARCH=%{gohostarch} \
        ./make.bash --no-clean
+CC="gcc" \
+CC_FOR_TARGET="gcc" \
+GOOS=windows \
+GOARCH=amd64 \
+       ./make.bash --no-clean
Comment 1 Vincent Batts 2015-08-25 14:05:23 EDT
but with go1.5, this bootstrapping is not needed. just `dnf install golang`, then `GOOS=windows GOARCH=amd64 go build <yourcode>` and it will produce <yourcode>.exe

What is the issue here?
Comment 2 Vincent Batts 2015-09-03 09:58:50 EDT
Closing as mingw is not needed for the compiler to produce windows binaries. That feature is a part of the compiler.

vbatts@valse ~/x (master) $ cat hello.go 
package main

import "fmt"

func main() {
        fmt.Println("hello world!")
vbatts@valse ~/x (master) $ rpm -q golang
vbatts@valse ~/x (master) $ go version
go version go1.5 linux/amd64
vbatts@valse ~/x (master) $ GOOS=windows GOARCH=amd64 go build hello.go 
vbatts@valse ~/x (master) $ GOOS=darwin GOARCH=amd64 go build -o hello.darwin hello.go 
vbatts@valse ~/x (master) $ GOOS=freebsd GOARCH=386 go build -o hello.freebsd hello.go 
vbatts@valse ~/x (master) $ GOOS=linux GOARCH=arm go build -o hello.linux hello.go 
vbatts@valse ~/x (master) $ file hello*
hello.darwin:  Mach-O 64-bit x86_64 executable
hello.exe:     PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows
hello.freebsd: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), statically linked, not stripped
hello.go:      C source, ASCII text
hello.linux:   ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped

Note You need to log in before you can comment on or make changes to this bug.