-x
print the commands.
+ -buildmode mode
+ build mode to use. See 'go help buildmodes' for more.
-compiler name
name of compiler to use, as in runtime.Compiler (gccgo or gc).
-gccgoflags 'arg list'
a suffix to use in the name of the package installation directory,
in order to keep output separate from default builds.
If using the -race flag, the install suffix is automatically set to race
- or, if set explicitly, has _race appended to it.
+ or, if set explicitly, has _race appended to it. Using a -buildmode
+ option that requires non-default compile flags has a similar effect.
-ldflags 'flag list'
arguments to pass on each 5l, 6l, 8l, or 9l linker invocation.
-asmflags 'flag list'
var buildGccgoflags []string // -gccgoflags flag
var buildRace bool // -race flag
var buildToolExec []string // -toolexec flag
+var buildBuildmode string // -buildmode flag
var buildContext = build.Default
var buildToolchain toolchain = noToolchain{}
cmd.Flag.Var(buildCompiler{}, "compiler", "")
cmd.Flag.BoolVar(&buildRace, "race", false, "")
cmd.Flag.Var((*stringsFlag)(&buildToolExec), "toolexec", "")
+ cmd.Flag.StringVar(&buildBuildmode, "buildmode", "default", "")
}
func addBuildFlagsNX(cmd *Command) {
return "<stringsFlag>"
}
+var pkgFilter = func(p *Package) bool { return true }
+
+func buildModeInit() {
+ var codegenArg, ldBuildmode string
+ switch buildBuildmode {
+ case "archive":
+ pkgFilter = func(p *Package) bool { return p.Name != "main" }
+ case "c-shared":
+ pkgFilter = func(p *Package) bool { return p.Name == "main" }
+ platform := goos + "/" + goarch
+ switch platform {
+ case "linux/amd64":
+ case "android/arm":
+ default:
+ fmt.Fprintf(os.Stderr, "go %s: -buildmode=c-shared not supported on %s\n", platform)
+ os.Exit(2)
+ }
+ if goarch == "amd64" {
+ codegenArg = "-shared"
+ }
+ ldBuildmode = "c-shared"
+ case "default":
+ ldBuildmode = "exe"
+ case "exe":
+ pkgFilter = func(p *Package) bool { return p.Name == "main" }
+ ldBuildmode = "exe"
+ default:
+ fatalf("buildmode=%s not supported", buildBuildmode)
+ }
+ if ldBuildmode != "" {
+ buildLdflags = append(buildLdflags, "-buildmode="+ldBuildmode)
+ }
+ if codegenArg != "" {
+ buildAsmflags = append(buildAsmflags, codegenArg)
+ buildGcflags = append(buildGcflags, codegenArg)
+ if buildContext.InstallSuffix != "" {
+ buildContext.InstallSuffix += "_"
+ }
+ buildContext.InstallSuffix += codegenArg[1:]
+ }
+}
+
func runBuild(cmd *Command, args []string) {
raceInit()
+ buildModeInit()
var b builder
b.init()
a := &action{}
for _, p := range packages(args) {
- a.deps = append(a.deps, b.action(modeBuild, depMode, p))
+ if pkgFilter(p) {
+ a.deps = append(a.deps, b.action(modeBuild, depMode, p))
+ }
}
b.do(a)
}
a := &action{}
var tools []*action
for _, p := range pkgs {
+ if !pkgFilter(p) {
+ continue
+ }
// If p is a tool, delay the installation until the end of the build.
// This avoids installing assemblers/compilers that are being executed
// by other steps in the build.
Additional help topics:
c calling between Go and C
+ buildmode description of build modes
filetype file types
gopath GOPATH environment variable
importpath import path syntax
-x
print the commands.
+ -buildmode mode
+ build mode to use. See 'go help buildmodes' for more.
-compiler name
name of compiler to use, as in runtime.Compiler (gccgo or gc).
-gccgoflags 'arg list'
a suffix to use in the name of the package installation directory,
in order to keep output separate from default builds.
If using the -race flag, the install suffix is automatically set to race
- or, if set explicitly, has _race appended to it.
+ or, if set explicitly, has _race appended to it. Using a -buildmode
+ option that requires non-default compile flags has a similar effect.
-ldflags 'flag list'
arguments to pass on each 5l, 6l, 8l, or 9l linker invocation.
-asmflags 'flag list'
the C or C++ compiler, respectively, to use.
+Description of build modes
+
+The 'go build' and 'go install' commands take a -buildmode argument which
+indicates which kind of object file is to be built. Currently supported values
+are:
+
+ -buildmode=archive
+ Build the listed non-main packages into .a files. Packages named
+ main are ignored.
+
+ -buildmode=c-shared
+ Build the listed main packages, plus all packages that they
+ import, into C shared libraries. The only callable symbols will
+ be those functions marked as exported. Non-main packages are
+ ignored.
+
+ -buildmode=default
+ Listed main packages are built into executables and listed
+ non-main packages are built into .a files (the default
+ behavior).
+
+ -buildmode=exe
+ Build the listed main packages and everything they import into
+ executables. Packages not named main are ignored.
+
+
File types
The go command examines the contents of a restricted set of files
line comment.
`,
}
+
+var helpBuildmode = &Command{
+ UsageLine: "buildmode",
+ Short: "description of build modes",
+ Long: `
+The 'go build' and 'go install' commands take a -buildmode argument which
+indicates which kind of object file is to be built. Currently supported values
+are:
+
+ -buildmode=archive
+ Build the listed non-main packages into .a files. Packages named
+ main are ignored.
+
+ -buildmode=c-shared
+ Build the listed main packages, plus all packages that they
+ import, into C shared libraries. The only callable symbols will
+ be those functions marked as exported. Non-main packages are
+ ignored.
+
+ -buildmode=default
+ Listed main packages are built into executables and listed
+ non-main packages are built into .a files (the default
+ behavior).
+
+ -buildmode=exe
+ Build the listed main packages and everything they import into
+ executables. Packages not named main are ignored.
+`,
+}