Skip to content

Commit d23973d

Browse files
cmd/go: document environment variables
This adds documentation for all the environment variables I could locate in the go tool and the commands that it invokes. Fixes #9672. Change-Id: Id5f09160a3a8a938af4a3fcb8757eb3eced05416 Reviewed-on: https://go-review.googlesource.com/12620 Reviewed-by: Rob Pike <[email protected]>
1 parent d9ee9a0 commit d23973d

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

src/cmd/go/alldocs.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Additional help topics:
3838
buildmode description of build modes
3939
filetype file types
4040
gopath GOPATH environment variable
41+
environment environment variables
4142
importpath import path syntax
4243
packages description of package lists
4344
testflag description of testing flags
@@ -974,6 +975,77 @@ in future releases. Once settled, they will be on by default.
974975
See https://golang.org/s/go15vendor for details.
975976
976977
978+
Environment variables
979+
980+
The go command, and the tools it invokes, examine a few different
981+
environment variables. For many of these, you can see the default
982+
value of on your system by running 'go env NAME', where NAME is the
983+
name of the variable.
984+
985+
General-purpose environment variables:
986+
987+
GCCGO
988+
The gccgo command to run for 'go build -compiler=gccgo'.
989+
GOARCH
990+
The architecture, or processor, for which to compile code.
991+
Examples are amd64, 386, arm, ppc64.
992+
GOBIN
993+
The directory where 'go install' will install a command.
994+
GOOS
995+
The operating system for which to compile code.
996+
Examples are linux, darwin, windows, netbsd.
997+
GOPATH
998+
See 'go help gopath'.
999+
GORACE
1000+
Options for the race detector.
1001+
See https://golang.org/doc/articles/race_detector.html.
1002+
GOROOT
1003+
The root of the go tree.
1004+
1005+
Environment variables for use with cgo:
1006+
1007+
CC
1008+
The command to use to compile C code.
1009+
CGO_ENABLED
1010+
Whether the cgo command is supported. Either 0 or 1.
1011+
CGO_CFLAGS
1012+
Flags that cgo will pass to the compiler when compiling
1013+
C code.
1014+
CGO_CPPFLAGS
1015+
Flags that cgo will pass to the compiler when compiling
1016+
C or C++ code.
1017+
CGO_CXXFLAGS
1018+
Flags that cgo will pass to the compiler when compiling
1019+
C++ code.
1020+
CGO_LDFLAGS
1021+
Flags that cgo will pass to the compiler when linking.
1022+
CXX
1023+
The command to use to compile C++ code.
1024+
1025+
Architecture-specific environment variables:
1026+
1027+
GOARM
1028+
For GOARCH=arm, the ARM architecture for which to compile.
1029+
Valid values are 5, 6, 7.
1030+
GO386
1031+
For GOARCH=386, the floating point instruction set.
1032+
Valid values are 387, sse2.
1033+
1034+
Special-purpose environment variables:
1035+
1036+
GOROOT_FINAL
1037+
The root of the installed Go tree, when it is
1038+
installed in a location other than where it is built.
1039+
File names in stack traces are rewritten from GOROOT to
1040+
GOROOT_FINAL.
1041+
GO15VENDOREXPERIMENT
1042+
Set to 1 to enable the Go 1.5 vendoring experiment.
1043+
GO_EXTLINK_ENABLED
1044+
Whether the linker should use external linking mode
1045+
when using -linkmode=auto with code that uses cgo.
1046+
Set to 0 to disable external linking mode, 1 to enable it.
1047+
1048+
9771049
Import path syntax
9781050
9791051
An import path (see 'go help packages') denotes a package

src/cmd/go/help.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,81 @@ See https://golang.org/s/go15vendor for details.
420420
`,
421421
}
422422

423+
var helpEnvironment = &Command{
424+
UsageLine: "environment",
425+
Short: "environment variables",
426+
Long: `
427+
428+
The go command, and the tools it invokes, examine a few different
429+
environment variables. For many of these, you can see the default
430+
value of on your system by running 'go env NAME', where NAME is the
431+
name of the variable.
432+
433+
General-purpose environment variables:
434+
435+
GCCGO
436+
The gccgo command to run for 'go build -compiler=gccgo'.
437+
GOARCH
438+
The architecture, or processor, for which to compile code.
439+
Examples are amd64, 386, arm, ppc64.
440+
GOBIN
441+
The directory where 'go install' will install a command.
442+
GOOS
443+
The operating system for which to compile code.
444+
Examples are linux, darwin, windows, netbsd.
445+
GOPATH
446+
See 'go help gopath'.
447+
GORACE
448+
Options for the race detector.
449+
See https://golang.org/doc/articles/race_detector.html.
450+
GOROOT
451+
The root of the go tree.
452+
453+
Environment variables for use with cgo:
454+
455+
CC
456+
The command to use to compile C code.
457+
CGO_ENABLED
458+
Whether the cgo command is supported. Either 0 or 1.
459+
CGO_CFLAGS
460+
Flags that cgo will pass to the compiler when compiling
461+
C code.
462+
CGO_CPPFLAGS
463+
Flags that cgo will pass to the compiler when compiling
464+
C or C++ code.
465+
CGO_CXXFLAGS
466+
Flags that cgo will pass to the compiler when compiling
467+
C++ code.
468+
CGO_LDFLAGS
469+
Flags that cgo will pass to the compiler when linking.
470+
CXX
471+
The command to use to compile C++ code.
472+
473+
Architecture-specific environment variables:
474+
475+
GOARM
476+
For GOARCH=arm, the ARM architecture for which to compile.
477+
Valid values are 5, 6, 7.
478+
GO386
479+
For GOARCH=386, the floating point instruction set.
480+
Valid values are 387, sse2.
481+
482+
Special-purpose environment variables:
483+
484+
GOROOT_FINAL
485+
The root of the installed Go tree, when it is
486+
installed in a location other than where it is built.
487+
File names in stack traces are rewritten from GOROOT to
488+
GOROOT_FINAL.
489+
GO15VENDOREXPERIMENT
490+
Set to 1 to enable the Go 1.5 vendoring experiment.
491+
GO_EXTLINK_ENABLED
492+
Whether the linker should use external linking mode
493+
when using -linkmode=auto with code that uses cgo.
494+
Set to 0 to disable external linking mode, 1 to enable it.
495+
`,
496+
}
497+
423498
var helpFileType = &Command{
424499
UsageLine: "filetype",
425500
Short: "file types",

src/cmd/go/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var commands = []*Command{
9595
helpBuildmode,
9696
helpFileType,
9797
helpGopath,
98+
helpEnvironment,
9899
helpImportPath,
99100
helpPackages,
100101
helpTestflag,

0 commit comments

Comments
 (0)