1 # Test automatic setting of CGO_ENABLED based on $CC and what's in $PATH.
2
3 [!cgo] skip
4 [cross] skip
5
6 # Assume we're on a system that can enable cgo normally.
7 env CGO_ENABLED=
8 go env CGO_ENABLED
9 stdout 1
10
11 # Clearing CC and removing everything but Go from the PATH should usually
12 # disable cgo: no C compiler anymore (unless the baked-in defaultCC is an
13 # absolute path and exists.
14 env CC=
15 env PATH=$GOROOT/bin
16 go env CGO_ENABLED
17 [!abscc] stdout 0
18 [abscc] stdout 1
19
20 # Setting CC should re-enable cgo.
21 env CC=cc
22 go env CGO_ENABLED
23 stdout 1
24
25 # So should setting CGO_ENABLED.
26 env CC=
27 env CGO_ENABLED=1
28 go env CGO_ENABLED
29 stdout 1
30
View as plain text