Commit 0509727b authored by Russ Cox's avatar Russ Cox

build: fixes for Windows

* work around a linker/cgo bug
* do not run deps.bash on Windows unless we need it
  (cuts a full minute off the build time)
* add windows to the list of cgo-enabled targets

The gopack problem is issue 2601.

R=golang-dev, r, bradfitz
CC=golang-dev
https://golang.org/cl/5504062
parent ba9cb9dc
...@@ -452,7 +452,7 @@ func (b *builder) build(a *action) error { ...@@ -452,7 +452,7 @@ func (b *builder) build(a *action) error {
return err return err
} }
var gofiles, cfiles, sfiles, objects []string var gofiles, cfiles, sfiles, objects, cgoObjects []string
gofiles = append(gofiles, a.p.GoFiles...) gofiles = append(gofiles, a.p.GoFiles...)
cfiles = append(cfiles, a.p.CFiles...) cfiles = append(cfiles, a.p.CFiles...)
sfiles = append(sfiles, a.p.SFiles...) sfiles = append(sfiles, a.p.SFiles...)
...@@ -487,7 +487,7 @@ func (b *builder) build(a *action) error { ...@@ -487,7 +487,7 @@ func (b *builder) build(a *action) error {
if err != nil { if err != nil {
return err return err
} }
objects = append(objects, outObj...) cgoObjects = append(cgoObjects, outObj...)
gofiles = append(gofiles, outGo...) gofiles = append(gofiles, outGo...)
} }
...@@ -576,6 +576,12 @@ func (b *builder) build(a *action) error { ...@@ -576,6 +576,12 @@ func (b *builder) build(a *action) error {
objects = append(objects, out) objects = append(objects, out)
} }
// NOTE(rsc): On Windows, it is critically important that the
// gcc-compiled objects (cgoObjects) be listed after the ordinary
// objects in the archive. I do not know why this is.
// http://golang.org/issue/2601
objects = append(objects, cgoObjects...)
// pack into archive in obj directory // pack into archive in obj directory
if err := b.gopack(a.p, obj, a.objpkg, objects); err != nil { if err := b.gopack(a.p, obj, a.objpkg, objects); err != nil {
return err return err
...@@ -917,6 +923,8 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, ...@@ -917,6 +923,8 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo,
return nil, nil, errors.New("cannot use cgo when compiling for a different operating system") return nil, nil, errors.New("cannot use cgo when compiling for a different operating system")
} }
outObj = append(outObj, "") // for importObj, at end of function
// cgo // cgo
// TODO: CGOPKGPATH, CGO_FLAGS? // TODO: CGOPKGPATH, CGO_FLAGS?
gofiles := []string{obj + "_cgo_gotypes.go"} gofiles := []string{obj + "_cgo_gotypes.go"}
...@@ -983,7 +991,11 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo, ...@@ -983,7 +991,11 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo,
if err := b.cc(p, obj, importObj, importC); err != nil { if err := b.cc(p, obj, importObj, importC); err != nil {
return nil, nil, err return nil, nil, err
} }
outObj = append(outObj, importObj)
// NOTE(rsc): The importObj is a 5c/6c/8c object and on Windows
// must be processed before the gcc-generated objects.
// Put it first. We left room above. http://golang.org/issue/2601
outObj[0] = importObj
return outGo, outObj, nil return outGo, outObj, nil
} }
......
...@@ -71,6 +71,7 @@ do ...@@ -71,6 +71,7 @@ do
fi fi
done done
$USE_GO_TOOL ||
( (
cd "$GOROOT"/src/pkg; cd "$GOROOT"/src/pkg;
bash deps.bash # do this here so clean.bash will work in the pkg directory bash deps.bash # do this here so clean.bash will work in the pkg directory
......
...@@ -84,6 +84,8 @@ var cgoEnabled = map[string]bool{ ...@@ -84,6 +84,8 @@ var cgoEnabled = map[string]bool{
"linux/amd64": true, "linux/amd64": true,
"freebsd/386": true, "freebsd/386": true,
"freebsd/amd64": true, "freebsd/amd64": true,
"windows/386": true,
"windows/amd64": true,
} }
func defaultContext() Context { func defaultContext() Context {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment