From 84e7bc0dd39bab24b696dde4d714641fa738f945 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 29 Mar 2016 14:32:15 -0400 Subject: [PATCH] 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 --- go/loader/cgo.go | 7 +++---- go/loader/cgo_pkgconfig.go | 18 ++++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/go/loader/cgo.go b/go/loader/cgo.go index c925ace405..245b914914 100644 --- a/go/loader/cgo.go +++ b/go/loader/cgo.go @@ -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) diff --git a/go/loader/cgo_pkgconfig.go b/go/loader/cgo_pkgconfig.go index 91ab2ccf9e..de57422df2 100644 --- a/go/loader/cgo_pkgconfig.go +++ b/go/loader/cgo_pkgconfig.go @@ -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) }