Skip to content

Commit 9c50fdf

Browse files
ianlancetaylorchengsiyuan
authored and
chengsiyuan
committed
cmd/cgo: read CGO_LDFLAGS environment variable
For golang#66456 we changed from the CGO_LDFLAGS environment variable to the -ldflags option. This broke Bazel, which uses CGO_LDFLAGS. So restore reading CGO_LDFLAGS for now. For golang#66456 Change-Id: Iebdd8bde1c7c18da09c6370e284c7ac7fa08fc54 Reviewed-on: https://go-review.googlesource.com/c/go/+/596615 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 45286eb commit 9c50fdf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/cmd/cgo/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,21 @@ func main() {
343343
p.addToFlag("LDFLAGS", args)
344344
}
345345

346+
// For backward compatibility for Bazel, record CGO_LDFLAGS
347+
// from the environment for external linking.
348+
// This should not happen with cmd/go, which removes CGO_LDFLAGS
349+
// from the environment when invoking cgo.
350+
// This can be removed when we no longer need to support
351+
// older versions of Bazel. See issue #66456 and
352+
// https://github.com/bazelbuild/rules_go/issues/3979.
353+
if envFlags := os.Getenv("CGO_LDFLAGS"); envFlags != "" {
354+
args, err := splitQuoted(envFlags)
355+
if err != nil {
356+
fatalf("bad CGO_LDFLAGS: %q (%s)", envFlags, err)
357+
}
358+
p.addToFlag("LDFLAGS", args)
359+
}
360+
346361
// Need a unique prefix for the global C symbols that
347362
// we use to coordinate between gcc and ourselves.
348363
// We already put _cgo_ at the beginning, so the main

0 commit comments

Comments
 (0)