...

Source file src/cmd/dist/buildruntime.go

Documentation: cmd/dist

     1  // Copyright 2012 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 main
     6  
     7  import (
     8  	"fmt"
     9  	"strings"
    10  )
    11  
    12  /*
    13   * Helpers for building runtime.
    14   */
    15  
    16  // mkzversion writes zversion.go:
    17  //
    18  //	package sys
    19  //
    20  // (Nothing right now!)
    21  func mkzversion(dir, file string) {
    22  	var buf strings.Builder
    23  	writeHeader(&buf)
    24  	fmt.Fprintf(&buf, "package sys\n")
    25  	writefile(buf.String(), file, writeSkipSame)
    26  }
    27  
    28  // mkbuildcfg writes internal/buildcfg/zbootstrap.go:
    29  //
    30  //	package buildcfg
    31  //
    32  //	const defaultGOROOT = <goroot>
    33  //	const defaultGO386 = <go386>
    34  //	...
    35  //	const defaultGOOS = runtime.GOOS
    36  //	const defaultGOARCH = runtime.GOARCH
    37  //
    38  // The use of runtime.GOOS and runtime.GOARCH makes sure that
    39  // a cross-compiled compiler expects to compile for its own target
    40  // system. That is, if on a Mac you do:
    41  //
    42  //	GOOS=linux GOARCH=ppc64 go build cmd/compile
    43  //
    44  // the resulting compiler will default to generating linux/ppc64 object files.
    45  // This is more useful than having it default to generating objects for the
    46  // original target (in this example, a Mac).
    47  func mkbuildcfg(file string) {
    48  	var buf strings.Builder
    49  	writeHeader(&buf)
    50  	fmt.Fprintf(&buf, "package buildcfg\n")
    51  	fmt.Fprintln(&buf)
    52  	fmt.Fprintf(&buf, "import \"runtime\"\n")
    53  	fmt.Fprintln(&buf)
    54  	fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386)
    55  	fmt.Fprintf(&buf, "const defaultGOAMD64 = `%s`\n", goamd64)
    56  	fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm)
    57  	fmt.Fprintf(&buf, "const defaultGOARM64 = `%s`\n", goarm64)
    58  	fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips)
    59  	fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64)
    60  	fmt.Fprintf(&buf, "const defaultGOPPC64 = `%s`\n", goppc64)
    61  	fmt.Fprintf(&buf, "const defaultGORISCV64 = `%s`\n", goriscv64)
    62  	fmt.Fprintf(&buf, "const defaultGOEXPERIMENT = `%s`\n", goexperiment)
    63  	fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)
    64  	fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)
    65  	fmt.Fprintf(&buf, "const version = `%s`\n", findgoversion())
    66  	fmt.Fprintf(&buf, "const defaultGOOS = runtime.GOOS\n")
    67  	fmt.Fprintf(&buf, "const defaultGOARCH = runtime.GOARCH\n")
    68  
    69  	writefile(buf.String(), file, writeSkipSame)
    70  }
    71  
    72  // mkobjabi writes cmd/internal/objabi/zbootstrap.go:
    73  //
    74  //	package objabi
    75  //
    76  // (Nothing right now!)
    77  func mkobjabi(file string) {
    78  	var buf strings.Builder
    79  	writeHeader(&buf)
    80  	fmt.Fprintf(&buf, "package objabi\n")
    81  
    82  	writefile(buf.String(), file, writeSkipSame)
    83  }
    84  

View as plain text