aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-11-21 16:57:52 -0500
committerGopher Robot <gobot@golang.org>2022-11-21 22:43:41 +0000
commit7656cba9ccec334bb4219489d4488234f42f5302 (patch)
treea53b12c4c8a61c1f7befb1079b069d43a02e4e94 /misc
parentd58f2e741c742aafe5d3247bd184e182da71408d (diff)
downloadgo-7656cba9ccec334bb4219489d4488234f42f5302.tar.gz
go-7656cba9ccec334bb4219489d4488234f42f5302.zip
cmd/go: do not install .a files for packages in std
As of CL 450739, we do not need install targets for cgo files when a C compiler is not present because cgo is not enabled by default. (Without a C compiler, builds will proceed with cgo disabled.) Fixes #47257. Fixes #56888. Change-Id: I274c50a60b5b1382e291df86a5464da8ad3695a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/452457 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/testcshared/cshared_test.go82
1 files changed, 27 insertions, 55 deletions
diff --git a/misc/cgo/testcshared/cshared_test.go b/misc/cgo/testcshared/cshared_test.go
index 0d1b0ad9b7..7bb5a2dba5 100644
--- a/misc/cgo/testcshared/cshared_test.go
+++ b/misc/cgo/testcshared/cshared_test.go
@@ -31,7 +31,7 @@ var exeSuffix string
var GOOS, GOARCH, GOROOT string
var installdir, androiddir string
-var libSuffix, libgoname string
+var libgoname string
func TestMain(m *testing.M) {
os.Exit(testMain(m))
@@ -153,18 +153,6 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
- // Directory where cgo headers and outputs will be installed.
- // The installation directory format varies depending on the platform.
- output, err := exec.Command("go", "list",
- "-buildmode=c-shared",
- "-f", "{{.Target}}",
- "runtime/cgo").CombinedOutput()
- if err != nil {
- log.Panicf("go list failed: %v\n%s", err, output)
- }
- runtimeCgoTarget := string(bytes.TrimSpace(output))
- libSuffix = strings.TrimPrefix(filepath.Ext(runtimeCgoTarget), ".")
-
defer func() {
if installdir != "" {
err := os.RemoveAll(installdir)
@@ -300,7 +288,7 @@ func createHeaders() error {
if err != nil {
return err
}
- libgoname = "libgo." + libSuffix
+ libgoname = "libgo.a"
args = []string{"go", "build", "-buildmode=c-shared", "-o", filepath.Join(installdir, libgoname), "./libgo"}
cmd = exec.Command(args[0], args[1:]...)
@@ -335,46 +323,30 @@ func createHeaders() error {
if err != nil {
return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
}
- dlltoolpath := strings.TrimSpace(string(out))
- if filepath.Ext(dlltoolpath) == "" {
- // Some compilers report slash-separated paths without extensions
- // instead of ordinary Windows paths.
- // Try to find the canonical name for the path.
- if lp, err := exec.LookPath(dlltoolpath); err == nil {
- dlltoolpath = lp
- }
- }
+ args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
- args := []string{dlltoolpath, "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
-
- if filepath.Ext(dlltoolpath) == "" {
- // This is an unfortunate workaround for
- // https://github.com/mstorsjo/llvm-mingw/issues/205 in which
- // we basically reimplement the contents of the dlltool.sh
- // wrapper: https://git.io/JZFlU.
- // TODO(thanm): remove this workaround once we can upgrade
- // the compilers on the windows-arm64 builder.
- dlltoolContents, err := os.ReadFile(args[0])
- if err != nil {
- return fmt.Errorf("unable to read dlltool: %v\n", err)
+ // This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
+ // we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
+ dlltoolContents, err := os.ReadFile(args[0])
+ if err != nil {
+ return fmt.Errorf("unable to read dlltool: %v\n", err)
+ }
+ if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
+ base, name := filepath.Split(args[0])
+ args[0] = filepath.Join(base, "llvm-dlltool")
+ var machine string
+ switch prefix, _, _ := strings.Cut(name, "-"); prefix {
+ case "i686":
+ machine = "i386"
+ case "x86_64":
+ machine = "i386:x86-64"
+ case "armv7":
+ machine = "arm"
+ case "aarch64":
+ machine = "arm64"
}
- if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
- base, name := filepath.Split(args[0])
- args[0] = filepath.Join(base, "llvm-dlltool")
- var machine string
- switch prefix, _, _ := strings.Cut(name, "-"); prefix {
- case "i686":
- machine = "i386"
- case "x86_64":
- machine = "i386:x86-64"
- case "armv7":
- machine = "arm"
- case "aarch64":
- machine = "arm64"
- }
- if len(machine) > 0 {
- args = append(args, "-m", machine)
- }
+ if len(machine) > 0 {
+ args = append(args, "-m", machine)
}
}
@@ -578,7 +550,7 @@ func TestUnexportedSymbols(t *testing.T) {
cmd := "testp2"
bin := cmdToRun(cmd)
- libname := "libgo2." + libSuffix
+ libname := "libgo2.a"
run(t,
nil,
@@ -636,7 +608,7 @@ func TestMainExportedOnAndroid(t *testing.T) {
}
func testSignalHandlers(t *testing.T, pkgname, cfile, cmd string) {
- libname := pkgname + "." + libSuffix
+ libname := pkgname + ".a"
run(t,
nil,
"go", "build",
@@ -838,7 +810,7 @@ func TestGo2C2Go(t *testing.T) {
}
defer os.RemoveAll(tmpdir)
- lib := filepath.Join(tmpdir, "libtestgo2c2go."+libSuffix)
+ lib := filepath.Join(tmpdir, "libtestgo2c2go.a")
var env []string
if GOOS == "windows" && strings.HasSuffix(lib, ".a") {
env = append(env, "CGO_LDFLAGS=-Wl,--out-implib,"+lib, "CGO_LDFLAGS_ALLOW=.*")