1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:18:33 -06:00

go/loader: don't pass ldflags to cgo

Although these flags are harmless on linux, they
cause clang on darwin to issue an error about
unused flags (-lpthread).  We only care about compilation
so we don't need them.

Change-Id: I0fc756e2f4d7a829d43b5aa912c4e4b24a802a1c
Reviewed-on: https://go-review.googlesource.com/21283
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-03-29 14:32:15 -04:00 committed by Alan Donovan
parent 0ed9f242ee
commit 84e7bc0dd3
2 changed files with 9 additions and 16 deletions

View File

@ -115,16 +115,15 @@ var cgoRe = regexp.MustCompile(`[/\\:]`)
// Objective C, CGOPKGPATH, CGO_FLAGS.
//
func runCgo(bp *build.Package, pkgdir, tmpdir string) (files, displayFiles []string, err error) {
cgoCPPFLAGS, _, _, cgoLDFLAGS := cflags(bp, true)
cgoCPPFLAGS, _, _, _ := cflags(bp, true)
_, cgoexeCFLAGS, _, _ := cflags(bp, false)
if len(bp.CgoPkgConfig) > 0 {
pcCFLAGS, pcLDFLAGS, err := pkgConfigFlags(bp)
pcCFLAGS, err := pkgConfigFlags(bp)
if err != nil {
return nil, nil, err
}
cgoCPPFLAGS = append(cgoCPPFLAGS, pcCFLAGS...)
cgoLDFLAGS = append(cgoLDFLAGS, pcLDFLAGS...)
}
// Allows including _cgo_export.h from .[ch] files in the package.
@ -150,7 +149,7 @@ func runCgo(bp *build.Package, pkgdir, tmpdir string) (files, displayFiles []str
args := stringList(
"go", "tool", "cgo", "-objdir", tmpdir, cgoflags, "--",
cgoCPPFLAGS, cgoLDFLAGS, cgoexeCFLAGS, bp.CgoFiles,
cgoCPPFLAGS, cgoexeCFLAGS, bp.CgoFiles,
)
if false {
log.Printf("Running cgo for package %q: %s (dir=%s)", bp.ImportPath, args, pkgdir)

View File

@ -29,17 +29,11 @@ func pkgConfig(mode string, pkgs []string) (flags []string, err error) {
return
}
// pkgConfigFlags calls pkg-config if needed and returns the cflags/ldflags needed to build the package.
func pkgConfigFlags(p *build.Package) (cflags, ldflags []string, err error) {
if pkgs := p.CgoPkgConfig; len(pkgs) > 0 {
cflags, err = pkgConfig("--cflags", pkgs)
if err != nil {
return nil, nil, err
}
ldflags, err = pkgConfig("--libs", pkgs)
if err != nil {
return nil, nil, err
}
// pkgConfigFlags calls pkg-config if needed and returns the cflags
// needed to build the package.
func pkgConfigFlags(p *build.Package) (cflags []string, err error) {
if len(p.CgoPkgConfig) == 0 {
return nil, nil
}
return
return pkgConfig("--cflags", p.CgoPkgConfig)
}