Skip to content

cmd/go/internal/work: allows installing cross-compiled binaries GOBIN is set #66065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ type PackageInternal struct {
Cover CoverSetup // coverage mode and other setup info of -cover is being applied to this package
CoverVars map[string]*CoverVar // variables created by coverage analysis
OmitDebug bool // tell linker not to write debug information
GobinSubdir bool // install target would be subdir of GOBIN
BuildInfo *debug.BuildInfo // add this info to package main
TestmainGo *[]byte // content for _testmain.go
Embed map[string][]string // //go:embed comment mapping
Expand Down Expand Up @@ -1830,10 +1829,9 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
if p.Internal.Build.BinDir != "" {
// Install to GOBIN or bin of GOPATH entry.
p.Target = filepath.Join(p.Internal.Build.BinDir, elem)
if !p.Goroot && strings.Contains(elem, string(filepath.Separator)) && cfg.GOBIN != "" {
// Do not create $GOBIN/goos_goarch/elem.
p.Target = ""
p.Internal.GobinSubdir = true
if cfg.GOBIN != "" {
// Do not create $GOBIN/goos_goarch/elem if GOBIN is set.
p.Target = filepath.Join(cfg.GOBIN, p.DefaultExecName()+cfg.ExeSuffix)
}
}
if InstallTargetDir(p) == ToTool {
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,6 @@ func InstallPackages(ctx context.Context, patterns []string, pkgs []*load.Packag
// rebuilt and used directly from the build cache.
// A few targets (notably those using cgo) still do need to be installed
// in case the user's environment lacks a C compiler.
case p.Internal.GobinSubdir:
base.Errorf("go: cannot install cross-compiled binaries when GOBIN is set")
case p.Internal.CmdlineFiles:
base.Errorf("go: no install location for .go files listed on command line (GOBIN not set)")
case p.ConflictDir != "":
Expand Down
10 changes: 0 additions & 10 deletions src/cmd/go/testdata/script/install_cmd_gobin.txt

This file was deleted.

3 changes: 2 additions & 1 deletion src/cmd/go/testdata/script/install_cross_gobin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ exists $GOPATH/bin/linux_$GOARCH/mycmd

# cross-compile install with explicit GOBIN cannot make subdirectory
env GOBIN=$WORK/bin
! go install mycmd
go install mycmd
! exists $GOBIN/linux_$GOARCH
exists $GOBIN/mycmd

# The install directory for a cross-compiled standard command should include GOARCH.
go list -f '{{.Target}}' cmd/pack
Expand Down