aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-11-10 15:19:11 -0800
committerIan Lance Taylor <iant@golang.org>2016-11-10 23:58:25 +0000
commit7bdb77af5fea5b94cf3d5d7840ca9162e76b3e9b (patch)
tree335a75174b69b8249e158fc774cae4a5d2d235da
parent35ea53dcc8d8350898250e87a0b5ffa03e14173e (diff)
downloadgo-7bdb77af5fea5b94cf3d5d7840ca9162e76b3e9b.tar.gz
go-7bdb77af5fea5b94cf3d5d7840ca9162e76b3e9b.zip
cmd/cgo: don't depend on runtime/cgo if !CgoEnabled
Fixes the build when CGO_ENABLED=0. Change-Id: I7f3c67d61e156e69536558fda0a0a4b429b82bbd Reviewed-on: https://go-review.googlesource.com/33104 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/cmd/go/pkg.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 23d3114682..064a428703 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -913,23 +913,25 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
importPaths = append(importPaths, "syscall")
}
- // Currently build modes c-shared, pie (on systems that do not
- // support PIE with internal linking mode), plugin, and
- // -linkshared force external linking mode, as of course does
- // -ldflags=-linkmode=external. External linking mode forces
- // an import of runtime/cgo.
- pieCgo := buildBuildmode == "pie" && (buildContext.GOOS != "linux" || buildContext.GOARCH != "amd64")
- linkmodeExternal := false
- for i, a := range buildLdflags {
- if a == "-linkmode=external" {
- linkmodeExternal = true
- }
- if a == "-linkmode" && i+1 < len(buildLdflags) && buildLdflags[i+1] == "external" {
- linkmodeExternal = true
- }
- }
- if p.Name == "main" && !p.Goroot && (buildBuildmode == "c-shared" || buildBuildmode == "plugin" || pieCgo || buildLinkshared || linkmodeExternal) {
- importPaths = append(importPaths, "runtime/cgo")
+ if buildContext.CgoEnabled && p.Name == "main" && !p.Goroot {
+ // Currently build modes c-shared, pie (on systems that do not
+ // support PIE with internal linking mode), plugin, and
+ // -linkshared force external linking mode, as of course does
+ // -ldflags=-linkmode=external. External linking mode forces
+ // an import of runtime/cgo.
+ pieCgo := buildBuildmode == "pie" && (buildContext.GOOS != "linux" || buildContext.GOARCH != "amd64")
+ linkmodeExternal := false
+ for i, a := range buildLdflags {
+ if a == "-linkmode=external" {
+ linkmodeExternal = true
+ }
+ if a == "-linkmode" && i+1 < len(buildLdflags) && buildLdflags[i+1] == "external" {
+ linkmodeExternal = true
+ }
+ }
+ if buildBuildmode == "c-shared" || buildBuildmode == "plugin" || pieCgo || buildLinkshared || linkmodeExternal {
+ importPaths = append(importPaths, "runtime/cgo")
+ }
}
// Everything depends on runtime, except runtime, its internal