1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07: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. // Objective C, CGOPKGPATH, CGO_FLAGS.
// //
func runCgo(bp *build.Package, pkgdir, tmpdir string) (files, displayFiles []string, err error) { 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) _, cgoexeCFLAGS, _, _ := cflags(bp, false)
if len(bp.CgoPkgConfig) > 0 { if len(bp.CgoPkgConfig) > 0 {
pcCFLAGS, pcLDFLAGS, err := pkgConfigFlags(bp) pcCFLAGS, err := pkgConfigFlags(bp)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
cgoCPPFLAGS = append(cgoCPPFLAGS, pcCFLAGS...) cgoCPPFLAGS = append(cgoCPPFLAGS, pcCFLAGS...)
cgoLDFLAGS = append(cgoLDFLAGS, pcLDFLAGS...)
} }
// Allows including _cgo_export.h from .[ch] files in the package. // 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( args := stringList(
"go", "tool", "cgo", "-objdir", tmpdir, cgoflags, "--", "go", "tool", "cgo", "-objdir", tmpdir, cgoflags, "--",
cgoCPPFLAGS, cgoLDFLAGS, cgoexeCFLAGS, bp.CgoFiles, cgoCPPFLAGS, cgoexeCFLAGS, bp.CgoFiles,
) )
if false { if false {
log.Printf("Running cgo for package %q: %s (dir=%s)", bp.ImportPath, args, pkgdir) 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 return
} }
// pkgConfigFlags calls pkg-config if needed and returns the cflags/ldflags needed to build the package. // pkgConfigFlags calls pkg-config if needed and returns the cflags
func pkgConfigFlags(p *build.Package) (cflags, ldflags []string, err error) { // needed to build the package.
if pkgs := p.CgoPkgConfig; len(pkgs) > 0 { func pkgConfigFlags(p *build.Package) (cflags []string, err error) {
cflags, err = pkgConfig("--cflags", pkgs) if len(p.CgoPkgConfig) == 0 {
if err != nil { return nil, nil
return nil, nil, err
}
ldflags, err = pkgConfig("--libs", pkgs)
if err != nil {
return nil, nil, err
}
} }
return return pkgConfig("--cflags", p.CgoPkgConfig)
} }