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