github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/run/run.go (about) 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 run implements the “go run” command. 6 package run 7 8 import ( 9 "github.com/shogo82148/std/cmd/go/internal/base" 10 ) 11 12 var CmdRun = &base.Command{ 13 UsageLine: "go run [build flags] [-exec xprog] package [arguments...]", 14 Short: "compile and run Go program", 15 Long: ` 16 Run compiles and runs the named main Go package. 17 Typically the package is specified as a list of .go source files from a single 18 directory, but it may also be an import path, file system path, or pattern 19 matching a single known package, as in 'go run .' or 'go run my/cmd'. 20 21 If the package argument has a version suffix (like @latest or @v1.0.0), 22 "go run" builds the program in module-aware mode, ignoring the go.mod file in 23 the current directory or any parent directory, if there is one. This is useful 24 for running programs without affecting the dependencies of the main module. 25 26 If the package argument doesn't have a version suffix, "go run" may run in 27 module-aware mode or GOPATH mode, depending on the GO111MODULE environment 28 variable and the presence of a go.mod file. See 'go help modules' for details. 29 If module-aware mode is enabled, "go run" runs in the context of the main 30 module. 31 32 By default, 'go run' runs the compiled binary directly: 'a.out arguments...'. 33 If the -exec flag is given, 'go run' invokes the binary using xprog: 34 'xprog a.out arguments...'. 35 If the -exec flag is not given, GOOS or GOARCH is different from the system 36 default, and a program named go_$GOOS_$GOARCH_exec can be found 37 on the current search path, 'go run' invokes the binary using that program, 38 for example 'go_js_wasm_exec a.out arguments...'. This allows execution of 39 cross-compiled programs when a simulator or other execution method is 40 available. 41 42 By default, 'go run' compiles the binary without generating the information 43 used by debuggers, to reduce build time. To include debugger information in 44 the binary, use 'go build'. 45 46 The exit status of Run is not the exit status of the compiled binary. 47 48 For more about build flags, see 'go help build'. 49 For more about specifying packages, see 'go help packages'. 50 51 See also: go build. 52 `, 53 }