Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/internal/help/helpdoc.go

Documentation: cmd/go/internal/help

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package help
     6  
     7  import "cmd/go/internal/base"
     8  
     9  var HelpC = &base.Command{
    10  	UsageLine: "c",
    11  	Short:     "calling between Go and C",
    12  	Long: `
    13  There are two different ways to call between Go and C/C++ code.
    14  
    15  The first is the cgo tool, which is part of the Go distribution. For
    16  information on how to use it see the cgo documentation (go doc cmd/cgo).
    17  
    18  The second is the SWIG program, which is a general tool for
    19  interfacing between languages. For information on SWIG see
    20  http://swig.org/. When running go build, any file with a .swig
    21  extension will be passed to SWIG. Any file with a .swigcxx extension
    22  will be passed to SWIG with the -c++ option.
    23  
    24  When either cgo or SWIG is used, go build will pass any .c, .m, .s, .S
    25  or .sx files to the C compiler, and any .cc, .cpp, .cxx files to the C++
    26  compiler. The CC or CXX environment variables may be set to determine
    27  the C or C++ compiler, respectively, to use.
    28  	`,
    29  }
    30  
    31  var HelpPackages = &base.Command{
    32  	UsageLine: "packages",
    33  	Short:     "package lists and patterns",
    34  	Long: `
    35  Many commands apply to a set of packages:
    36  
    37  	go action [packages]
    38  
    39  Usually, [packages] is a list of import paths.
    40  
    41  An import path that is a rooted path or that begins with
    42  a . or .. element is interpreted as a file system path and
    43  denotes the package in that directory.
    44  
    45  Otherwise, the import path P denotes the package found in
    46  the directory DIR/src/P for some DIR listed in the GOPATH
    47  environment variable (For more details see: 'go help gopath').
    48  
    49  If no import paths are given, the action applies to the
    50  package in the current directory.
    51  
    52  There are four reserved names for paths that should not be used
    53  for packages to be built with the go tool:
    54  
    55  - "main" denotes the top-level package in a stand-alone executable.
    56  
    57  - "all" expands to all packages found in all the GOPATH
    58  trees. For example, 'go list all' lists all the packages on the local
    59  system. When using modules, "all" expands to all packages in
    60  the main module and their dependencies, including dependencies
    61  needed by tests of any of those.
    62  
    63  - "std" is like all but expands to just the packages in the standard
    64  Go library.
    65  
    66  - "cmd" expands to the Go repository's commands and their
    67  internal libraries.
    68  
    69  Import paths beginning with "cmd/" only match source code in
    70  the Go repository.
    71  
    72  An import path is a pattern if it includes one or more "..." wildcards,
    73  each of which can match any string, including the empty string and
    74  strings containing slashes. Such a pattern expands to all package
    75  directories found in the GOPATH trees with names matching the
    76  patterns.
    77  
    78  To make common patterns more convenient, there are two special cases.
    79  First, /... at the end of the pattern can match an empty string,
    80  so that net/... matches both net and packages in its subdirectories, like net/http.
    81  Second, any slash-separated pattern element containing a wildcard never
    82  participates in a match of the "vendor" element in the path of a vendored
    83  package, so that ./... does not match packages in subdirectories of
    84  ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
    85  Note, however, that a directory named vendor that itself contains code
    86  is not a vendored package: cmd/vendor would be a command named vendor,
    87  and the pattern cmd/... matches it.
    88  See golang.org/s/go15vendor for more about vendoring.
    89  
    90  An import path can also name a package to be downloaded from
    91  a remote repository. Run 'go help importpath' for details.
    92  
    93  Every package in a program must have a unique import path.
    94  By convention, this is arranged by starting each path with a
    95  unique prefix that belongs to you. For example, paths used
    96  internally at Google all begin with 'google', and paths
    97  denoting remote repositories begin with the path to the code,
    98  such as 'github.com/user/repo'.
    99  
   100  Packages in a program need not have unique package names,
   101  but there are two reserved package names with special meaning.
   102  The name main indicates a command, not a library.
   103  Commands are built into binaries and cannot be imported.
   104  The name documentation indicates documentation for
   105  a non-Go program in the directory. Files in package documentation
   106  are ignored by the go command.
   107  
   108  As a special case, if the package list is a list of .go files from a
   109  single directory, the command is applied to a single synthesized
   110  package made up of exactly those files, ignoring any build constraints
   111  in those files and ignoring any other files in the directory.
   112  
   113  Directory and file names that begin with "." or "_" are ignored
   114  by the go tool, as are directories named "testdata".
   115  	`,
   116  }
   117  
   118  var HelpImportPath = &base.Command{
   119  	UsageLine: "importpath",
   120  	Short:     "import path syntax",
   121  	Long: `
   122  
   123  An import path (see 'go help packages') denotes a package stored in the local
   124  file system. In general, an import path denotes either a standard package (such
   125  as "unicode/utf8") or a package found in one of the work spaces (For more
   126  details see: 'go help gopath').
   127  
   128  Relative import paths
   129  
   130  An import path beginning with ./ or ../ is called a relative path.
   131  The toolchain supports relative import paths as a shortcut in two ways.
   132  
   133  First, a relative path can be used as a shorthand on the command line.
   134  If you are working in the directory containing the code imported as
   135  "unicode" and want to run the tests for "unicode/utf8", you can type
   136  "go test ./utf8" instead of needing to specify the full path.
   137  Similarly, in the reverse situation, "go test .." will test "unicode" from
   138  the "unicode/utf8" directory. Relative patterns are also allowed, like
   139  "go test ./..." to test all subdirectories. See 'go help packages' for details
   140  on the pattern syntax.
   141  
   142  Second, if you are compiling a Go program not in a work space,
   143  you can use a relative path in an import statement in that program
   144  to refer to nearby code also not in a work space.
   145  This makes it easy to experiment with small multipackage programs
   146  outside of the usual work spaces, but such programs cannot be
   147  installed with "go install" (there is no work space in which to install them),
   148  so they are rebuilt from scratch each time they are built.
   149  To avoid ambiguity, Go programs cannot use relative import paths
   150  within a work space.
   151  
   152  Remote import paths
   153  
   154  Certain import paths also
   155  describe how to obtain the source code for the package using
   156  a revision control system.
   157  
   158  A few common code hosting sites have special syntax:
   159  
   160  	Bitbucket (Git, Mercurial)
   161  
   162  		import "bitbucket.org/user/project"
   163  		import "bitbucket.org/user/project/sub/directory"
   164  
   165  	GitHub (Git)
   166  
   167  		import "github.com/user/project"
   168  		import "github.com/user/project/sub/directory"
   169  
   170  	Launchpad (Bazaar)
   171  
   172  		import "launchpad.net/project"
   173  		import "launchpad.net/project/series"
   174  		import "launchpad.net/project/series/sub/directory"
   175  
   176  		import "launchpad.net/~user/project/branch"
   177  		import "launchpad.net/~user/project/branch/sub/directory"
   178  
   179  	IBM DevOps Services (Git)
   180  
   181  		import "hub.jazz.net/git/user/project"
   182  		import "hub.jazz.net/git/user/project/sub/directory"
   183  
   184  For code hosted on other servers, import paths may either be qualified
   185  with the version control type, or the go tool can dynamically fetch
   186  the import path over https/http and discover where the code resides
   187  from a <meta> tag in the HTML.
   188  
   189  To declare the code location, an import path of the form
   190  
   191  	repository.vcs/path
   192  
   193  specifies the given repository, with or without the .vcs suffix,
   194  using the named version control system, and then the path inside
   195  that repository. The supported version control systems are:
   196  
   197  	Bazaar      .bzr
   198  	Fossil      .fossil
   199  	Git         .git
   200  	Mercurial   .hg
   201  	Subversion  .svn
   202  
   203  For example,
   204  
   205  	import "example.org/user/foo.hg"
   206  
   207  denotes the root directory of the Mercurial repository at
   208  example.org/user/foo or foo.hg, and
   209  
   210  	import "example.org/repo.git/foo/bar"
   211  
   212  denotes the foo/bar directory of the Git repository at
   213  example.org/repo or repo.git.
   214  
   215  When a version control system supports multiple protocols,
   216  each is tried in turn when downloading. For example, a Git
   217  download tries https://, then git+ssh://.
   218  
   219  By default, downloads are restricted to known secure protocols
   220  (e.g. https, ssh). To override this setting for Git downloads, the
   221  GIT_ALLOW_PROTOCOL environment variable can be set (For more details see:
   222  'go help environment').
   223  
   224  If the import path is not a known code hosting site and also lacks a
   225  version control qualifier, the go tool attempts to fetch the import
   226  over https/http and looks for a <meta> tag in the document's HTML
   227  <head>.
   228  
   229  The meta tag has the form:
   230  
   231  	<meta name="go-import" content="import-prefix vcs repo-root">
   232  
   233  The import-prefix is the import path corresponding to the repository
   234  root. It must be a prefix or an exact match of the package being
   235  fetched with "go get". If it's not an exact match, another http
   236  request is made at the prefix to verify the <meta> tags match.
   237  
   238  The meta tag should appear as early in the file as possible.
   239  In particular, it should appear before any raw JavaScript or CSS,
   240  to avoid confusing the go command's restricted parser.
   241  
   242  The vcs is one of "bzr", "fossil", "git", "hg", "svn".
   243  
   244  The repo-root is the root of the version control system
   245  containing a scheme and not containing a .vcs qualifier.
   246  
   247  For example,
   248  
   249  	import "example.org/pkg/foo"
   250  
   251  will result in the following requests:
   252  
   253  	https://example.org/pkg/foo?go-get=1 (preferred)
   254  	http://example.org/pkg/foo?go-get=1  (fallback, only with use of correctly set GOINSECURE)
   255  
   256  If that page contains the meta tag
   257  
   258  	<meta name="go-import" content="example.org git https://code.org/r/p/exproj">
   259  
   260  the go tool will verify that https://example.org/?go-get=1 contains the
   261  same meta tag and then git clone https://code.org/r/p/exproj into
   262  GOPATH/src/example.org.
   263  
   264  When using GOPATH, downloaded packages are written to the first directory
   265  listed in the GOPATH environment variable.
   266  (See 'go help gopath-get' and 'go help gopath'.)
   267  
   268  When using modules, downloaded packages are stored in the module cache.
   269  See https://golang.org/ref/mod#module-cache.
   270  
   271  When using modules, an additional variant of the go-import meta tag is
   272  recognized and is preferred over those listing version control systems.
   273  That variant uses "mod" as the vcs in the content value, as in:
   274  
   275  	<meta name="go-import" content="example.org mod https://code.org/moduleproxy">
   276  
   277  This tag means to fetch modules with paths beginning with example.org
   278  from the module proxy available at the URL https://code.org/moduleproxy.
   279  See https://golang.org/ref/mod#goproxy-protocol for details about the
   280  proxy protocol.
   281  
   282  Import path checking
   283  
   284  When the custom import path feature described above redirects to a
   285  known code hosting site, each of the resulting packages has two possible
   286  import paths, using the custom domain or the known hosting site.
   287  
   288  A package statement is said to have an "import comment" if it is immediately
   289  followed (before the next newline) by a comment of one of these two forms:
   290  
   291  	package math // import "path"
   292  	package math /* import "path" */
   293  
   294  The go command will refuse to install a package with an import comment
   295  unless it is being referred to by that import path. In this way, import comments
   296  let package authors make sure the custom import path is used and not a
   297  direct path to the underlying code hosting site.
   298  
   299  Import path checking is disabled for code found within vendor trees.
   300  This makes it possible to copy code into alternate locations in vendor trees
   301  without needing to update import comments.
   302  
   303  Import path checking is also disabled when using modules.
   304  Import path comments are obsoleted by the go.mod file's module statement.
   305  
   306  See https://golang.org/s/go14customimport for details.
   307  	`,
   308  }
   309  
   310  var HelpGopath = &base.Command{
   311  	UsageLine: "gopath",
   312  	Short:     "GOPATH environment variable",
   313  	Long: `
   314  The Go path is used to resolve import statements.
   315  It is implemented by and documented in the go/build package.
   316  
   317  The GOPATH environment variable lists places to look for Go code.
   318  On Unix, the value is a colon-separated string.
   319  On Windows, the value is a semicolon-separated string.
   320  On Plan 9, the value is a list.
   321  
   322  If the environment variable is unset, GOPATH defaults
   323  to a subdirectory named "go" in the user's home directory
   324  ($HOME/go on Unix, %USERPROFILE%\go on Windows),
   325  unless that directory holds a Go distribution.
   326  Run "go env GOPATH" to see the current GOPATH.
   327  
   328  See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH.
   329  
   330  Each directory listed in GOPATH must have a prescribed structure:
   331  
   332  The src directory holds source code. The path below src
   333  determines the import path or executable name.
   334  
   335  The pkg directory holds installed package objects.
   336  As in the Go tree, each target operating system and
   337  architecture pair has its own subdirectory of pkg
   338  (pkg/GOOS_GOARCH).
   339  
   340  If DIR is a directory listed in the GOPATH, a package with
   341  source in DIR/src/foo/bar can be imported as "foo/bar" and
   342  has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a".
   343  
   344  The bin directory holds compiled commands.
   345  Each command is named for its source directory, but only
   346  the final element, not the entire path. That is, the
   347  command with source in DIR/src/foo/quux is installed into
   348  DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped
   349  so that you can add DIR/bin to your PATH to get at the
   350  installed commands. If the GOBIN environment variable is
   351  set, commands are installed to the directory it names instead
   352  of DIR/bin. GOBIN must be an absolute path.
   353  
   354  Here's an example directory layout:
   355  
   356      GOPATH=/home/user/go
   357  
   358      /home/user/go/
   359          src/
   360              foo/
   361                  bar/               (go code in package bar)
   362                      x.go
   363                  quux/              (go code in package main)
   364                      y.go
   365          bin/
   366              quux                   (installed command)
   367          pkg/
   368              linux_amd64/
   369                  foo/
   370                      bar.a          (installed package object)
   371  
   372  Go searches each directory listed in GOPATH to find source code,
   373  but new packages are always downloaded into the first directory
   374  in the list.
   375  
   376  See https://golang.org/doc/code.html for an example.
   377  
   378  GOPATH and Modules
   379  
   380  When using modules, GOPATH is no longer used for resolving imports.
   381  However, it is still used to store downloaded source code (in GOPATH/pkg/mod)
   382  and compiled commands (in GOPATH/bin).
   383  
   384  Internal Directories
   385  
   386  Code in or below a directory named "internal" is importable only
   387  by code in the directory tree rooted at the parent of "internal".
   388  Here's an extended version of the directory layout above:
   389  
   390      /home/user/go/
   391          src/
   392              crash/
   393                  bang/              (go code in package bang)
   394                      b.go
   395              foo/                   (go code in package foo)
   396                  f.go
   397                  bar/               (go code in package bar)
   398                      x.go
   399                  internal/
   400                      baz/           (go code in package baz)
   401                          z.go
   402                  quux/              (go code in package main)
   403                      y.go
   404  
   405  
   406  The code in z.go is imported as "foo/internal/baz", but that
   407  import statement can only appear in source files in the subtree
   408  rooted at foo. The source files foo/f.go, foo/bar/x.go, and
   409  foo/quux/y.go can all import "foo/internal/baz", but the source file
   410  crash/bang/b.go cannot.
   411  
   412  See https://golang.org/s/go14internal for details.
   413  
   414  Vendor Directories
   415  
   416  Go 1.6 includes support for using local copies of external dependencies
   417  to satisfy imports of those dependencies, often referred to as vendoring.
   418  
   419  Code below a directory named "vendor" is importable only
   420  by code in the directory tree rooted at the parent of "vendor",
   421  and only using an import path that omits the prefix up to and
   422  including the vendor element.
   423  
   424  Here's the example from the previous section,
   425  but with the "internal" directory renamed to "vendor"
   426  and a new foo/vendor/crash/bang directory added:
   427  
   428      /home/user/go/
   429          src/
   430              crash/
   431                  bang/              (go code in package bang)
   432                      b.go
   433              foo/                   (go code in package foo)
   434                  f.go
   435                  bar/               (go code in package bar)
   436                      x.go
   437                  vendor/
   438                      crash/
   439                          bang/      (go code in package bang)
   440                              b.go
   441                      baz/           (go code in package baz)
   442                          z.go
   443                  quux/              (go code in package main)
   444                      y.go
   445  
   446  The same visibility rules apply as for internal, but the code
   447  in z.go is imported as "baz", not as "foo/vendor/baz".
   448  
   449  Code in vendor directories deeper in the source tree shadows
   450  code in higher directories. Within the subtree rooted at foo, an import
   451  of "crash/bang" resolves to "foo/vendor/crash/bang", not the
   452  top-level "crash/bang".
   453  
   454  Code in vendor directories is not subject to import path
   455  checking (see 'go help importpath').
   456  
   457  When 'go get' checks out or updates a git repository, it now also
   458  updates submodules.
   459  
   460  Vendor directories do not affect the placement of new repositories
   461  being checked out for the first time by 'go get': those are always
   462  placed in the main GOPATH, never in a vendor subtree.
   463  
   464  See https://golang.org/s/go15vendor for details.
   465  	`,
   466  }
   467  
   468  var HelpEnvironment = &base.Command{
   469  	UsageLine: "environment",
   470  	Short:     "environment variables",
   471  	Long: `
   472  
   473  The go command and the tools it invokes consult environment variables
   474  for configuration. If an environment variable is unset, the go command
   475  uses a sensible default setting. To see the effective setting of the
   476  variable <NAME>, run 'go env <NAME>'. To change the default setting,
   477  run 'go env -w <NAME>=<VALUE>'. Defaults changed using 'go env -w'
   478  are recorded in a Go environment configuration file stored in the
   479  per-user configuration directory, as reported by os.UserConfigDir.
   480  The location of the configuration file can be changed by setting
   481  the environment variable GOENV, and 'go env GOENV' prints the
   482  effective location, but 'go env -w' cannot change the default location.
   483  See 'go help env' for details.
   484  
   485  General-purpose environment variables:
   486  
   487  	GO111MODULE
   488  		Controls whether the go command runs in module-aware mode or GOPATH mode.
   489  		May be "off", "on", or "auto".
   490  		See https://golang.org/ref/mod#mod-commands.
   491  	GCCGO
   492  		The gccgo command to run for 'go build -compiler=gccgo'.
   493  	GOARCH
   494  		The architecture, or processor, for which to compile code.
   495  		Examples are amd64, 386, arm, ppc64.
   496  	GOBIN
   497  		The directory where 'go install' will install a command.
   498  	GOCACHE
   499  		The directory where the go command will store cached
   500  		information for reuse in future builds.
   501  	GOMODCACHE
   502  		The directory where the go command will store downloaded modules.
   503  	GODEBUG
   504  		Enable various debugging facilities. See 'go doc runtime'
   505  		for details.
   506  	GOENV
   507  		The location of the Go environment configuration file.
   508  		Cannot be set using 'go env -w'.
   509  	GOFLAGS
   510  		A space-separated list of -flag=value settings to apply
   511  		to go commands by default, when the given flag is known by
   512  		the current command. Each entry must be a standalone flag.
   513  		Because the entries are space-separated, flag values must
   514  		not contain spaces. Flags listed on the command line
   515  		are applied after this list and therefore override it.
   516  	GOINSECURE
   517  		Comma-separated list of glob patterns (in the syntax of Go's path.Match)
   518  		of module path prefixes that should always be fetched in an insecure
   519  		manner. Only applies to dependencies that are being fetched directly.
   520  		GOINSECURE does not disable checksum database validation. GOPRIVATE or
   521  		GONOSUMDB may be used to achieve that.
   522  	GOOS
   523  		The operating system for which to compile code.
   524  		Examples are linux, darwin, windows, netbsd.
   525  	GOPATH
   526  		For more details see: 'go help gopath'.
   527  	GOPROXY
   528  		URL of Go module proxy. See https://golang.org/ref/mod#environment-variables
   529  		and https://golang.org/ref/mod#module-proxy for details.
   530  	GOPRIVATE, GONOPROXY, GONOSUMDB
   531  		Comma-separated list of glob patterns (in the syntax of Go's path.Match)
   532  		of module path prefixes that should always be fetched directly
   533  		or that should not be compared against the checksum database.
   534  		See https://golang.org/ref/mod#private-modules.
   535  	GOROOT
   536  		The root of the go tree.
   537  	GOSUMDB
   538  		The name of checksum database to use and optionally its public key and
   539  		URL. See https://golang.org/ref/mod#authenticating.
   540  	GOTMPDIR
   541  		The directory where the go command will write
   542  		temporary source files, packages, and binaries.
   543  	GOVCS
   544  		Lists version control commands that may be used with matching servers.
   545  		See 'go help vcs'.
   546  
   547  Environment variables for use with cgo:
   548  
   549  	AR
   550  		The command to use to manipulate library archives when
   551  		building with the gccgo compiler.
   552  		The default is 'ar'.
   553  	CC
   554  		The command to use to compile C code.
   555  	CGO_ENABLED
   556  		Whether the cgo command is supported. Either 0 or 1.
   557  	CGO_CFLAGS
   558  		Flags that cgo will pass to the compiler when compiling
   559  		C code.
   560  	CGO_CFLAGS_ALLOW
   561  		A regular expression specifying additional flags to allow
   562  		to appear in #cgo CFLAGS source code directives.
   563  		Does not apply to the CGO_CFLAGS environment variable.
   564  	CGO_CFLAGS_DISALLOW
   565  		A regular expression specifying flags that must be disallowed
   566  		from appearing in #cgo CFLAGS source code directives.
   567  		Does not apply to the CGO_CFLAGS environment variable.
   568  	CGO_CPPFLAGS, CGO_CPPFLAGS_ALLOW, CGO_CPPFLAGS_DISALLOW
   569  		Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW,
   570  		but for the C preprocessor.
   571  	CGO_CXXFLAGS, CGO_CXXFLAGS_ALLOW, CGO_CXXFLAGS_DISALLOW
   572  		Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW,
   573  		but for the C++ compiler.
   574  	CGO_FFLAGS, CGO_FFLAGS_ALLOW, CGO_FFLAGS_DISALLOW
   575  		Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW,
   576  		but for the Fortran compiler.
   577  	CGO_LDFLAGS, CGO_LDFLAGS_ALLOW, CGO_LDFLAGS_DISALLOW
   578  		Like CGO_CFLAGS, CGO_CFLAGS_ALLOW, and CGO_CFLAGS_DISALLOW,
   579  		but for the linker.
   580  	CXX
   581  		The command to use to compile C++ code.
   582  	FC
   583  		The command to use to compile Fortran code.
   584  	PKG_CONFIG
   585  		Path to pkg-config tool.
   586  
   587  Architecture-specific environment variables:
   588  
   589  	GOARM
   590  		For GOARCH=arm, the ARM architecture for which to compile.
   591  		Valid values are 5, 6, 7.
   592  	GO386
   593  		For GOARCH=386, how to implement floating point instructions.
   594  		Valid values are sse2 (default), softfloat.
   595  	GOMIPS
   596  		For GOARCH=mips{,le}, whether to use floating point instructions.
   597  		Valid values are hardfloat (default), softfloat.
   598  	GOMIPS64
   599  		For GOARCH=mips64{,le}, whether to use floating point instructions.
   600  		Valid values are hardfloat (default), softfloat.
   601  	GOPPC64
   602  		For GOARCH=ppc64{,le}, the target ISA (Instruction Set Architecture).
   603  		Valid values are power8 (default), power9.
   604  	GOWASM
   605  		For GOARCH=wasm, comma-separated list of experimental WebAssembly features to use.
   606  		Valid values are satconv, signext.
   607  
   608  Special-purpose environment variables:
   609  
   610  	GCCGOTOOLDIR
   611  		If set, where to find gccgo tools, such as cgo.
   612  		The default is based on how gccgo was configured.
   613  	GOEXPERIMENT
   614  		Comma-separated list of toolchain experiments to enable or disable.
   615  		The list of available experiments may change arbitrarily over time.
   616  		See src/internal/goexperiment/flags.go for currently valid values.
   617  		Warning: This variable is provided for the development and testing
   618  		of the Go toolchain itself. Use beyond that purpose is unsupported.
   619  	GOROOT_FINAL
   620  		The root of the installed Go tree, when it is
   621  		installed in a location other than where it is built.
   622  		File names in stack traces are rewritten from GOROOT to
   623  		GOROOT_FINAL.
   624  	GO_EXTLINK_ENABLED
   625  		Whether the linker should use external linking mode
   626  		when using -linkmode=auto with code that uses cgo.
   627  		Set to 0 to disable external linking mode, 1 to enable it.
   628  	GIT_ALLOW_PROTOCOL
   629  		Defined by Git. A colon-separated list of schemes that are allowed
   630  		to be used with git fetch/clone. If set, any scheme not explicitly
   631  		mentioned will be considered insecure by 'go get'.
   632  		Because the variable is defined by Git, the default value cannot
   633  		be set using 'go env -w'.
   634  
   635  Additional information available from 'go env' but not read from the environment:
   636  
   637  	GOEXE
   638  		The executable file name suffix (".exe" on Windows, "" on other systems).
   639  	GOGCCFLAGS
   640  		A space-separated list of arguments supplied to the CC command.
   641  	GOHOSTARCH
   642  		The architecture (GOARCH) of the Go toolchain binaries.
   643  	GOHOSTOS
   644  		The operating system (GOOS) of the Go toolchain binaries.
   645  	GOMOD
   646  		The absolute path to the go.mod of the main module.
   647  		If module-aware mode is enabled, but there is no go.mod, GOMOD will be
   648  		os.DevNull ("/dev/null" on Unix-like systems, "NUL" on Windows).
   649  		If module-aware mode is disabled, GOMOD will be the empty string.
   650  	GOTOOLDIR
   651  		The directory where the go tools (compile, cover, doc, etc...) are installed.
   652  	GOVERSION
   653  		The version of the installed Go tree, as reported by runtime.Version.
   654  	`,
   655  }
   656  
   657  var HelpFileType = &base.Command{
   658  	UsageLine: "filetype",
   659  	Short:     "file types",
   660  	Long: `
   661  The go command examines the contents of a restricted set of files
   662  in each directory. It identifies which files to examine based on
   663  the extension of the file name. These extensions are:
   664  
   665  	.go
   666  		Go source files.
   667  	.c, .h
   668  		C source files.
   669  		If the package uses cgo or SWIG, these will be compiled with the
   670  		OS-native compiler (typically gcc); otherwise they will
   671  		trigger an error.
   672  	.cc, .cpp, .cxx, .hh, .hpp, .hxx
   673  		C++ source files. Only useful with cgo or SWIG, and always
   674  		compiled with the OS-native compiler.
   675  	.m
   676  		Objective-C source files. Only useful with cgo, and always
   677  		compiled with the OS-native compiler.
   678  	.s, .S, .sx
   679  		Assembler source files.
   680  		If the package uses cgo or SWIG, these will be assembled with the
   681  		OS-native assembler (typically gcc (sic)); otherwise they
   682  		will be assembled with the Go assembler.
   683  	.swig, .swigcxx
   684  		SWIG definition files.
   685  	.syso
   686  		System object files.
   687  
   688  Files of each of these types except .syso may contain build
   689  constraints, but the go command stops scanning for build constraints
   690  at the first item in the file that is not a blank line or //-style
   691  line comment. See the go/build package documentation for
   692  more details.
   693  	`,
   694  }
   695  
   696  var HelpBuildmode = &base.Command{
   697  	UsageLine: "buildmode",
   698  	Short:     "build modes",
   699  	Long: `
   700  The 'go build' and 'go install' commands take a -buildmode argument which
   701  indicates which kind of object file is to be built. Currently supported values
   702  are:
   703  
   704  	-buildmode=archive
   705  		Build the listed non-main packages into .a files. Packages named
   706  		main are ignored.
   707  
   708  	-buildmode=c-archive
   709  		Build the listed main package, plus all packages it imports,
   710  		into a C archive file. The only callable symbols will be those
   711  		functions exported using a cgo //export comment. Requires
   712  		exactly one main package to be listed.
   713  
   714  	-buildmode=c-shared
   715  		Build the listed main package, plus all packages it imports,
   716  		into a C shared library. The only callable symbols will
   717  		be those functions exported using a cgo //export comment.
   718  		Requires exactly one main package to be listed.
   719  
   720  	-buildmode=default
   721  		Listed main packages are built into executables and listed
   722  		non-main packages are built into .a files (the default
   723  		behavior).
   724  
   725  	-buildmode=shared
   726  		Combine all the listed non-main packages into a single shared
   727  		library that will be used when building with the -linkshared
   728  		option. Packages named main are ignored.
   729  
   730  	-buildmode=exe
   731  		Build the listed main packages and everything they import into
   732  		executables. Packages not named main are ignored.
   733  
   734  	-buildmode=pie
   735  		Build the listed main packages and everything they import into
   736  		position independent executables (PIE). Packages not named
   737  		main are ignored.
   738  
   739  	-buildmode=plugin
   740  		Build the listed main packages, plus all packages that they
   741  		import, into a Go plugin. Packages not named main are ignored.
   742  
   743  On AIX, when linking a C program that uses a Go archive built with
   744  -buildmode=c-archive, you must pass -Wl,-bnoobjreorder to the C compiler.
   745  `,
   746  }
   747  
   748  var HelpCache = &base.Command{
   749  	UsageLine: "cache",
   750  	Short:     "build and test caching",
   751  	Long: `
   752  The go command caches build outputs for reuse in future builds.
   753  The default location for cache data is a subdirectory named go-build
   754  in the standard user cache directory for the current operating system.
   755  Setting the GOCACHE environment variable overrides this default,
   756  and running 'go env GOCACHE' prints the current cache directory.
   757  
   758  The go command periodically deletes cached data that has not been
   759  used recently. Running 'go clean -cache' deletes all cached data.
   760  
   761  The build cache correctly accounts for changes to Go source files,
   762  compilers, compiler options, and so on: cleaning the cache explicitly
   763  should not be necessary in typical use. However, the build cache
   764  does not detect changes to C libraries imported with cgo.
   765  If you have made changes to the C libraries on your system, you
   766  will need to clean the cache explicitly or else use the -a build flag
   767  (see 'go help build') to force rebuilding of packages that
   768  depend on the updated C libraries.
   769  
   770  The go command also caches successful package test results.
   771  See 'go help test' for details. Running 'go clean -testcache' removes
   772  all cached test results (but not cached build results).
   773  
   774  The GODEBUG environment variable can enable printing of debugging
   775  information about the state of the cache:
   776  
   777  GODEBUG=gocacheverify=1 causes the go command to bypass the
   778  use of any cache entries and instead rebuild everything and check
   779  that the results match existing cache entries.
   780  
   781  GODEBUG=gocachehash=1 causes the go command to print the inputs
   782  for all of the content hashes it uses to construct cache lookup keys.
   783  The output is voluminous but can be useful for debugging the cache.
   784  
   785  GODEBUG=gocachetest=1 causes the go command to print details of its
   786  decisions about whether to reuse a cached test result.
   787  `,
   788  }
   789  
   790  var HelpBuildConstraint = &base.Command{
   791  	UsageLine: "buildconstraint",
   792  	Short:     "build constraints",
   793  	Long: `
   794  A build constraint, also known as a build tag, is a line comment that begins
   795  
   796  	//go:build
   797  
   798  that lists the conditions under which a file should be included in the package.
   799  Constraints may appear in any kind of source file (not just Go), but
   800  they must appear near the top of the file, preceded
   801  only by blank lines and other line comments. These rules mean that in Go
   802  files a build constraint must appear before the package clause.
   803  
   804  To distinguish build constraints from package documentation,
   805  a build constraint should be followed by a blank line.
   806  
   807  A build constraint is evaluated as an expression containing options
   808  combined by ||, &&, and ! operators and parentheses. Operators have
   809  the same meaning as in Go.
   810  
   811  For example, the following build constraint constrains a file to
   812  build when the "linux" and "386" constraints are satisfied, or when
   813  "darwin" is satisfied and "cgo" is not:
   814  
   815  	//go:build (linux && 386) || (darwin && !cgo)
   816  
   817  It is an error for a file to have more than one //go:build line.
   818  
   819  During a particular build, the following words are satisfied:
   820  
   821  	- the target operating system, as spelled by runtime.GOOS, set with the
   822  	  GOOS environment variable.
   823  	- the target architecture, as spelled by runtime.GOARCH, set with the
   824  	  GOARCH environment variable.
   825  	- the compiler being used, either "gc" or "gccgo"
   826  	- "cgo", if the cgo command is supported (see CGO_ENABLED in
   827  	  'go help environment').
   828  	- a term for each Go major release, through the current version:
   829  	  "go1.1" from Go version 1.1 onward, "go1.12" from Go 1.12, and so on.
   830  	- any additional tags given by the -tags flag (see 'go help build').
   831  
   832  There are no separate build tags for beta or minor releases.
   833  
   834  If a file's name, after stripping the extension and a possible _test suffix,
   835  matches any of the following patterns:
   836  	*_GOOS
   837  	*_GOARCH
   838  	*_GOOS_GOARCH
   839  (example: source_windows_amd64.go) where GOOS and GOARCH represent
   840  any known operating system and architecture values respectively, then
   841  the file is considered to have an implicit build constraint requiring
   842  those terms (in addition to any explicit constraints in the file).
   843  
   844  Using GOOS=android matches build tags and files as for GOOS=linux
   845  in addition to android tags and files.
   846  
   847  Using GOOS=illumos matches build tags and files as for GOOS=solaris
   848  in addition to illumos tags and files.
   849  
   850  Using GOOS=ios matches build tags and files as for GOOS=darwin
   851  in addition to ios tags and files.
   852  
   853  To keep a file from being considered for the build:
   854  
   855  	//go:build ignore
   856  
   857  (any other unsatisfied word will work as well, but "ignore" is conventional.)
   858  
   859  To build a file only when using cgo, and only on Linux and OS X:
   860  
   861  	//go:build cgo && (linux || darwin)
   862  
   863  Such a file is usually paired with another file implementing the
   864  default functionality for other systems, which in this case would
   865  carry the constraint:
   866  
   867  	//go:build !(cgo && (linux || darwin))
   868  
   869  Naming a file dns_windows.go will cause it to be included only when
   870  building the package for Windows; similarly, math_386.s will be included
   871  only when building the package for 32-bit x86.
   872  
   873  Go versions 1.16 and earlier used a different syntax for build constraints,
   874  with a "// +build" prefix. The gofmt command will add an equivalent //go:build
   875  constraint when encountering the older syntax.
   876  `,
   877  }
   878  

View as plain text