1 [short] skip
2
3 # Compiler name is always added.
4 go build
5 go version -m m$GOEXE
6 stdout '^\tbuild\t-compiler=gc$'
7 stdout '^\tbuild\tGOOS='
8 stdout '^\tbuild\tGOARCH='
9 [GOARCH:amd64] stdout '^\tbuild\tGOAMD64='
10 ! stdout asmflags|gcflags|ldflags|gccgoflags
11
12 # Toolchain flags are added if present.
13 # The raw flags are included, with package patterns if specified.
14 go build -asmflags=example.com/m=-D=FOO=bar
15 go version -m m$GOEXE
16 stdout '^\tbuild\t-asmflags=example\.com/m=-D=FOO=bar$'
17
18 go build -gcflags=example.com/m=-N
19 go version -m m$GOEXE
20 stdout '^\tbuild\t-gcflags=example\.com/m=-N$'
21
22 go build -ldflags=example.com/m=-w
23 go version -m m$GOEXE
24 stdout '^\tbuild\t-ldflags=example\.com/m=-w$'
25
26 go build -trimpath
27 go version -m m$GOEXE
28 stdout '\tbuild\t-trimpath=true$'
29
30 # gccgoflags are not added when gc is used, and vice versa.
31 # TODO: test gccgo.
32 go build -gccgoflags=all=UNUSED
33 go version -m m$GOEXE
34 ! stdout gccgoflags
35
36 # Build and tool tags are added but not release tags.
37 # "race" is included with build tags but not "cgo".
38 go build -tags=a,b
39 go version -m m$GOEXE
40 stdout '^\tbuild\t-tags=a,b$'
41 [race] go build -race
42 [race] go version -m m$GOEXE
43 [race] ! stdout '^\tbuild\t-tags='
44 [race] stdout '^\tbuild\t-race=true$'
45
46 # CGO flags are separate settings.
47 # CGO_ENABLED is always present.
48 # Other flags are added if CGO_ENABLED is true.
49 env CGO_ENABLED=0
50 go build
51 go version -m m$GOEXE
52 stdout '^\tbuild\tCGO_ENABLED=0$'
53 ! stdout CGO_CPPFLAGS|CGO_CFLAGS|CGO_CXXFLAGS|CGO_LDFLAGS
54
55 [cgo] env CGO_ENABLED=1
56 [cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
57 [cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
58 [cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
59 [cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
60 [cgo] go build '-ldflags=all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist'
61 [cgo] go version -m m$GOEXE
62 [cgo] stdout '^\tbuild\t-ldflags="all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist"$'
63 [cgo] stdout '^\tbuild\tCGO_ENABLED=1$'
64 [cgo] stdout '^\tbuild\tCGO_CPPFLAGS=-DFROM_CPPFLAGS=1$'
65 [cgo] stdout '^\tbuild\tCGO_CFLAGS=-DFROM_CFLAGS=1$'
66 [cgo] stdout '^\tbuild\tCGO_CXXFLAGS=-DFROM_CXXFLAGS=1$'
67 [cgo] stdout '^\tbuild\tCGO_LDFLAGS=-L/extra/dir/does/not/exist$'
68
69 # https://go.dev/issue/52372: a cgo-enabled binary should not be stamped with
70 # CGO_ flags that contain paths.
71 [cgo] env CGO_ENABLED=1
72 [cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
73 [cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
74 [cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
75 [cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
76 [cgo] go build -trimpath '-ldflags=all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist'
77 [cgo] go version -m m$GOEXE
78 [cgo] ! stdout '/extra/dir/does/not/exist'
79 [cgo] ! stdout '/bonus/dir/does/not/exist'
80 [cgo] stdout '^\tbuild\tCGO_ENABLED=1$'
81
82 -- go.mod --
83 module example.com/m
84
85 go 1.18
86 -- m.go --
87 package main
88
89 func main() {}
90
View as plain text