-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: import runtime/cgo when externally linking
Restore CL 477195, which was reverted in CL 477795. This version includes CL 477397, which fixes the test problems with CL 477195. CL 477397 was not submitted because it had an unrelated failure on darwin-amd64. That failure is fixed by CL 477736. Fixes #31544 Change-Id: I3a2258cd0ca295cede3511ab212e56fd0114f94a Reviewed-on: https://go-review.googlesource.com/c/go/+/477839 Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
1 parent
86ad2d5
commit c7f5b35
Showing
2 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[short] skip 'links and runs binaries' | ||
|
||
# This test requires external linking. Assume that if cgo is supported | ||
# then external linking works. | ||
[!cgo] skip 'requires a C linker' | ||
|
||
# Only run on Unix systems. | ||
[GOOS:windows] skip | ||
[GOOS:plan9] skip | ||
|
||
# Ordinary build should work. | ||
go build | ||
exec ./hello | ||
stdout Hello | ||
|
||
# Building with -linkmode=external should not say anything about | ||
# runtime/cgo (issue #31544). | ||
go build -ldflags=-linkmode=external | ||
! stderr runtime/cgo | ||
exec ./hello | ||
stdout Hello | ||
|
||
# Some targets don't support -static | ||
[GOOS:darwin] skip 'no static linking on Darwin' | ||
[GOOS:solaris] skip 'no static linking on Solaris' | ||
|
||
# Building with -linkmode=external -extldflags=-static should work. | ||
go build -ldflags='-linkmode=external -extldflags=-static' | ||
! stderr runtime/cgo | ||
exec ./hello | ||
stdout Hello | ||
|
||
-- go.mod -- | ||
module hello | ||
|
||
go 1.20 | ||
-- hello.go -- | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello, world") | ||
} |