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".
9 go generate
10
11 # Build with the generated file.
12 go build
13
14 -- go.mod --
15 module cgolongcmd
16
17 go 1.22
18 -- generate.go --
19 //go:build ignore
20
21 package main
22
23 import (
24 "fmt"
25 "log"
26 "os"
27 "bytes"
28 )
29
30 func 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 --
44 package p
45
46 //go:generate go run generate.go
47
View as plain text