...
1# Issue #66456
2
3[!cgo] skip
4[GOOS:windows] skip
5[GOOS:plan9] skip
6
7# Generate a file with a very long #cgo LDFLAGS line.
8# This used to cause "go build" to fail with "argument list too long".
9go generate
10
11# Build with the generated file.
12go build
13
14-- go.mod --
15module cgolongcmd
16
17go 1.22
18-- generate.go --
19//go:build ignore
20
21package main
22
23import (
24 "fmt"
25 "log"
26 "os"
27 "bytes"
28)
29
30func main() {
31 var buf bytes.Buffer
32 buf.WriteString("package p\n")
33 buf.WriteString("// #cgo LDFLAGS:")
34 for i := range 10000 {
35 fmt.Fprintf(&buf, " -Wl,-rpath,/nonexistentpath/%d", i)
36 }
37 buf.WriteString("\n")
38 buf.WriteString(`import "C"`+"\n")
39 if err := os.WriteFile("generated.go", buf.Bytes(), 0o644); err != nil {
40 log.Fatal(err)
41 }
42}
43-- gen.go --
44package p
45
46//go:generate go run generate.go
View as plain text