From 44c73b8cd725e2a7137834860e0e2a67e8d77cb1 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Tue, 2 May 2023 23:37:42 +1000 Subject: [PATCH 1/7] feat: overhaul Signed-off-by: James Elliott --- .github/workflows/test.yml | 4 +- const.go | 61 ++++++++++ go.go | 74 ++++++------ main.go | 227 ++++++++++++++++++++++++------------- main_osarch.go | 4 +- opts.go | 88 ++++++++++++++ platform.go | 184 ++++++++++++++++-------------- platform_test.go | 61 ++++++---- toolchain.go | 13 +-- 9 files changed, 474 insertions(+), 242 deletions(-) create mode 100644 const.go create mode 100644 opts.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb7eb63..82b4096 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,8 +20,8 @@ jobs: "1.16.15", "1.17.13", "1.18.10", - "1.19.5", - "1.20.0", + "1.19.8", + "1.20.3", ] fail-fast: true diff --git a/const.go b/const.go new file mode 100644 index 0000000..8066c5b --- /dev/null +++ b/const.go @@ -0,0 +1,61 @@ +package main + +const ( + flagNameRace = "race" + flagNameMSAN = "msan" + flagNameASAN = "asan" + flagNameCover = "cover" + flagNameCoverPKG = "coverpkg" + flagNameASMFlags = "asmflags" + flagNameBuildMode = "buildmode" + flagNameBuildVCS = "buildvcs" + flagNameCompiler = "compiler" + flagNameGcCGOFlags = "gccgoflags" + flagNameGcFlags = "gcflags" + flagNameInstallSuffix = "installsuffix" + flagNameLDFlags = "ldflags" + flagNameLinkShared = "linkshared" + flagNameMod = "mod" + flagNameModCacheRW = "modcacherw" + flagNameModFile = "modfile" + flagNameOverlay = "overlay" + flagNameProfileGuidedOptimization = "pgo" + flagNamePackageDir = "pkgdir" + flagNameTags = "tags" + flagNameTrimPath = "trimpath" +) + +const ( + goosWindows = "windows" + goosLinux = "linux" + goosDarwin = "darwin" + goosFreeBSD = "freebsd" + goosNetBSD = "netbsd" + goosOpenBSD = "openbsd" + goosAndroid = "android" + goosPlan9 = "plan9" + goosDragonfly = "dragonfly" + goosNACL = "nacl" + goosSolaris = "solaris" + goosJavaScript = "js" + goosAIX = "aix" + goosIllumos = "illumos" +) + +const ( + goarch386 = "386" + goarchAMD64 = "amd64" + goarchAMD64P32 = "amd64p32" + goarchARM = "arm" + goarchARM64 = "arm64" + gooarchMIPS = "mips" + gooarchMIPSLE = "mipsle" + goarchMIPS64 = "mips64" + goarchMIPS64LE = "mips64le" + goarchS390X = "s390x" + gooarchPowerPC64 = "ppc64" + gooarchPowerPC64LE = "ppc64le" + gooarchRISCV64 = "riscv64" + gooarchLoong64 = "loong64" + gooarchWebAssembly = "wasm" +) diff --git a/go.go b/go.go index 44502e6..93b5008 100644 --- a/go.go +++ b/go.go @@ -3,7 +3,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -20,26 +19,6 @@ type OutputTemplateData struct { Arch string } -type CompileOpts struct { - PackagePath string - Platform Platform - OutputTpl string - Ldflags string - Gcflags string - Cc string - Cxx string - Asmflags string - Tags string - ModMode string - Buildmode string - BuildVCS string - Cgo bool - Rebuild bool - TrimPath bool - GoCmd string - Race bool -} - // GoCrossCompile func GoCrossCompile(opts *CompileOpts) error { env := append(os.Environ(), @@ -72,16 +51,18 @@ func GoCrossCompile(opts *CompileOpts) error { if err != nil { return err } + tplData := OutputTemplateData{ Dir: filepath.Base(opts.PackagePath), OS: opts.Platform.OS, Arch: opts.Platform.Arch, } + if err := tpl.Execute(&outputPath, &tplData); err != nil { return err } - if opts.Platform.OS == "windows" { + if opts.Platform.OS == goosWindows { outputPath.WriteString(".exe") } @@ -98,7 +79,7 @@ func GoCrossCompile(opts *CompileOpts) error { // directory to build. chdir := "" if opts.PackagePath[0] == '_' { - if runtime.GOOS == "windows" { + if runtime.GOOS == goosWindows { // We have to replace weird paths like this: // // _/c_/Users @@ -128,35 +109,43 @@ func GoCrossCompile(opts *CompileOpts) error { } if opts.ModMode != "" { - args = append(args, "-mod", opts.ModMode) + args = append(args, fmtFlag("mod", opts.ModMode)) } - if opts.Buildmode != "" { - args = append(args, "-buildmode", opts.Buildmode) + if opts.BuildMode != "" { + args = append(args, fmtFlag("buildmode", opts.BuildMode)) } if opts.BuildVCS != "" { - args = append(args, "-buildvcs", opts.BuildVCS) + args = append(args, fmtFlag("buildvcs", opts.BuildVCS)) + } + + if opts.Compiler != "" { + args = append(args, fmtFlag("-compiler", opts.Compiler)) } if opts.Race { args = append(args, "-race") } - if opts.Gcflags != "" { - args = append(args, "-gcflags", opts.Gcflags) + if opts.GcFlags != "" { + args = append(args, fmtFlagSpaceSeparated("gcflags", opts.GcFlags)) + } + + if opts.GcCGOFlags != "" { + args = append(args, fmtFlagSpaceSeparated("gccgoflags", opts.GcCGOFlags)) } - if opts.Ldflags != "" { - args = append(args, "-ldflags", opts.Ldflags) + if opts.LDFlags != "" { + args = append(args, fmtFlagSpaceSeparated("ldflags", opts.LDFlags)) } - if opts.Asmflags != "" { - args = append(args, "-asmflags", opts.Asmflags) + if opts.ASMFlags != "" { + args = append(args, fmtFlagSpaceSeparated("asmflags", opts.ASMFlags)) } if opts.Tags != "" { - args = append(args, "-tags", opts.Tags) + args = append(args, fmt.Sprintf("-tags=%s", opts.Tags)) } args = append(args, "-o", outputPathReal, opts.PackagePath) @@ -166,6 +155,18 @@ func GoCrossCompile(opts *CompileOpts) error { return err } +func fmtFlag(name, value string) string { + return fmt.Sprintf(`-%s=%s`, name, value) +} + +func fmtFlagSpaceSeparated(name, value string) string { + if strings.Contains(value, " ") && value[0] != '"' { + return fmt.Sprintf(`-%s="%s"`, name, value) + } + + return fmt.Sprintf(`-%s=%s`, name, value) +} + // GoMainDirs returns the file paths to the packages that are "main" // packages, from the list of packages given. The list of packages can // include relative paths, the special "..." Go keyword, etc. @@ -217,7 +218,7 @@ func GoVersion() (string, error) { // of `go version` might change whereas the source is guaranteed to run // for some time thanks to Go's compatibility guarantee. - td, err := ioutil.TempDir("", "gox") + td, err := os.MkdirTemp("", "gox") if err != nil { return "", err } @@ -225,7 +226,7 @@ func GoVersion() (string, error) { // Write the source code for the program that will generate the version sourcePath := filepath.Join(td, "version.go") - if err := ioutil.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { + if err := os.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { return "", err } @@ -252,6 +253,7 @@ func GoVersionParts() (result [2]int, err error) { func execGo(GoCmd string, env []string, dir string, args ...string) (string, error) { var stderr, stdout bytes.Buffer cmd := exec.Command(GoCmd, args...) + cmd.Stdout = &stdout cmd.Stderr = &stderr if env != nil { diff --git a/main.go b/main.go index 6a81afa..517d017 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "log" "os" "os/exec" "runtime" @@ -19,39 +20,64 @@ func main() { } func realMain() int { - var buildToolchain bool - var ldflags string - var outputTpl string - var parallel int - var platformFlag PlatformFlag - var tags string - var verbose bool - var flagGcflags, flagAsmflags, flagBuildmode, flagBuildVCS string - var flagCgo, flagRebuild, flagTrimPath, flagListOSArch, flagRaceFlag bool - var flagGoCmd string - var modMode string + var ( + flagBuildToolchain, flagVerbose, flagCgo, flagTrimPath, flagListOSArch bool + flagGoCmd, flagLDFlags, flagTags string + flagOutput string + flagParallel int + flagPlatform PlatformFlag + + flagChangeDir, flagCoverPkg, flagASMFlags, flagBuildMode, flagBuildVCS, flagCompiler, flagGcCGOFlags, flagGcFlags string + flagInstallSuffix, flagMod, flagModFile, flagOverlay, flagProfileGuidedOptimization, flagPackageDir string + flagRebuild, flagRace, flagMSAN, flagASAN, flagCover, flagLinkShared, flagModCacheRW bool + ) + flags := flag.NewFlagSet("gox", flag.ExitOnError) + flags.Usage = func() { printUsage() } - flags.Var(platformFlag.ArchFlagValue(), "arch", "arch to build for or skip") - flags.Var(platformFlag.OSArchFlagValue(), "osarch", "os/arch pairs to build for or skip") - flags.Var(platformFlag.OSFlagValue(), "os", "os to build for or skip") - flags.StringVar(&ldflags, "ldflags", "", "linker flags") - flags.StringVar(&tags, "tags", "", "go build tags") - flags.StringVar(&outputTpl, "output", "{{.Dir}}_{{.OS}}_{{.Arch}}", "output path") - flags.IntVar(¶llel, "parallel", -1, "parallelization factor") - flags.BoolVar(&buildToolchain, "build-toolchain", false, "build toolchain") - flags.BoolVar(&verbose, "verbose", false, "verbose") - flags.BoolVar(&flagCgo, "cgo", false, "") - flags.BoolVar(&flagRebuild, "rebuild", false, "") - flags.BoolVar(&flagTrimPath, "trimpath", false, "") + + // Gox Flags. flags.BoolVar(&flagListOSArch, "osarch-list", false, "") - flags.BoolVar(&flagRaceFlag, "race", false, "") - flags.StringVar(&flagBuildmode, "buildmode", "", "") - flags.StringVar(&flagBuildVCS, "buildvcs", "", "") - flags.StringVar(&flagGcflags, "gcflags", "", "") - flags.StringVar(&flagAsmflags, "asmflags", "", "") + flags.StringVar(&flagOutput, "output", "{{.Dir}}_{{.OS}}_{{.Arch}}", "") + flags.IntVar(&flagParallel, "parallel", -1, "") + flags.BoolVar(&flagVerbose, "verbose", false, "") flags.StringVar(&flagGoCmd, "gocmd", "go", "") - flags.StringVar(&modMode, "mod", "", "") + + // Misc. + flags.Var(flagPlatform.ArchFlagValue(), "arch", "") + flags.BoolVar(&flagBuildToolchain, "build-toolchain", false, "") + flags.Var(flagPlatform.OSFlagValue(), "os", "") + flags.Var(flagPlatform.OSArchFlagValue(), "osarch", "") + + // Env Flags. + flags.BoolVar(&flagCgo, "cgo", false, "") + + // Build Flags. + flags.StringVar(&flagChangeDir, "change-dir", "", "") + flags.BoolVar(&flagRebuild, "rebuild", false, "") + flags.BoolVar(&flagRace, flagNameRace, false, "") + flags.BoolVar(&flagMSAN, flagNameMSAN, false, "") + flags.BoolVar(&flagASAN, flagNameASAN, false, "") + flags.BoolVar(&flagCover, flagNameCover, false, "") + flags.StringVar(&flagCoverPkg, flagNameCoverPKG, "", "") + flags.StringVar(&flagASMFlags, flagNameASMFlags, "", "") + flags.StringVar(&flagBuildMode, flagNameBuildMode, "", "") + flags.StringVar(&flagBuildVCS, flagNameBuildVCS, "", "") + flags.StringVar(&flagCompiler, flagNameCompiler, "", "") + flags.StringVar(&flagGcCGOFlags, flagNameGcCGOFlags, "", "") + flags.StringVar(&flagGcFlags, flagNameGcFlags, "", "") + flags.StringVar(&flagInstallSuffix, flagNameInstallSuffix, "", "") + flags.StringVar(&flagLDFlags, flagNameLDFlags, "", "") + flags.BoolVar(&flagLinkShared, flagNameLinkShared, false, "") + flags.StringVar(&flagMod, flagNameMod, "", "") + flags.BoolVar(&flagModCacheRW, flagNameModCacheRW, false, "") + flags.StringVar(&flagModFile, flagNameModFile, "", "") + flags.StringVar(&flagOverlay, flagNameOverlay, "", "") + flags.StringVar(&flagProfileGuidedOptimization, flagNameProfileGuidedOptimization, "", "") + flags.StringVar(&flagPackageDir, flagNamePackageDir, "", "") + flags.StringVar(&flagTags, flagNameTags, "", "") + flags.BoolVar(&flagTrimPath, flagNameTrimPath, false, "") + if err := flags.Parse(os.Args[1:]); err != nil { flags.Usage() return 1 @@ -59,25 +85,40 @@ func realMain() int { // Determine what amount of parallelism we want Default to the current // number of CPUs-1 is <= 0 is specified. - if parallel <= 0 { + if flagParallel <= 0 { cpus := runtime.NumCPU() if cpus < 2 { - parallel = 1 + flagParallel = 1 } else { - parallel = cpus - 1 + flagParallel = cpus - 1 } // Joyent containers report 48 cores via runtime.NumCPU(), and a // default of 47 parallel builds causes a panic. Default to 3 on // Solaris-derived operating systems unless overridden with the // -parallel flag. - if runtime.GOOS == "solaris" { - parallel = 3 + if runtime.GOOS == goosSolaris { + flagParallel = 3 } } - if buildToolchain { - return mainBuildToolchain(parallel, platformFlag, verbose) + versionStr, err := GoVersion() + if err != nil { + fmt.Fprintf(os.Stderr, "error reading Go version: %s", err) + return 1 + } + + var v *version.Version + + // Use latest if we get an unexpected version string + if strings.HasPrefix(versionStr, "go") { + if v, err = version.NewVersion(versionStr[2:]); err != nil { + log.Printf("Unable to parse current go version: %s\n%s", versionStr, err.Error()) + } + } + + if flagBuildToolchain { + return mainBuildToolchain(v, flagParallel, flagPlatform, flagVerbose) } if _, err := exec.LookPath(flagGoCmd); err != nil { @@ -86,14 +127,8 @@ func realMain() int { return 1 } - versionStr, err := GoVersion() - if err != nil { - fmt.Fprintf(os.Stderr, "error reading Go version: %s", err) - return 1 - } - if flagListOSArch { - return mainListOSArch(versionStr) + return mainListOSArch(v) } // Determine the packages that we want to compile. Default to the @@ -111,7 +146,7 @@ func realMain() int { } // Determine the platforms we're building for - platforms := platformFlag.Platforms(SupportedPlatforms(versionStr)) + platforms := flagPlatform.Platforms(SupportedPlatforms(v)) if len(platforms) == 0 { fmt.Println("No valid platforms to build for. If you specified a value") fmt.Println("for the 'os', 'arch', or 'osarch' flags, make sure you're") @@ -120,31 +155,29 @@ func realMain() int { } // Assume -mod is supported when no version prefix is found - if modMode != "" && strings.HasPrefix(versionStr, "go") { - // go-version only cares about version numbers - current, err := version.NewVersion(versionStr[2:]) - if err != nil { - fmt.Fprintf(os.Stderr, "Unable to parse current go version: %s\n%s", versionStr, err.Error()) - return 1 - } - + if flagMod != "" { constraint, err := version.NewConstraint(">= 1.11") if err != nil { panic(err) } - if !constraint.Check(current) { + if !constraint.Check(v) { fmt.Printf("Go compiler version %s does not support the -mod flag\n", versionStr) - modMode = "" + flagMod = "" } } // Build in parallel! - fmt.Printf("Number of parallel builds: %d\n\n", parallel) - var errorLock sync.Mutex - var wg sync.WaitGroup + fmt.Printf("Number of parallel builds: %d\n\n", flagParallel) + + var ( + errorLock sync.Mutex + wg sync.WaitGroup + ) + errors := make([]string, 0) - semaphore := make(chan int, parallel) + semaphore := make(chan int, flagParallel) + for _, platform := range platforms { for _, path := range mainDirs { // Start the goroutine that will do the actual build @@ -155,28 +188,44 @@ func realMain() int { fmt.Printf("--> %15s: %s\n", platform.String(), path) opts := &CompileOpts{ + GoVersion: v, PackagePath: path, Platform: platform, - OutputTpl: outputTpl, - Ldflags: ldflags, - Gcflags: flagGcflags, - Asmflags: flagAsmflags, - Tags: tags, - ModMode: modMode, + OutputTpl: flagOutput, Cgo: flagCgo, - Rebuild: flagRebuild, - Buildmode: flagBuildmode, - BuildVCS: flagBuildVCS, - TrimPath: flagTrimPath, GoCmd: flagGoCmd, - Race: flagRaceFlag, + + ChangeDir: flagChangeDir, + Rebuild: flagRebuild, + Race: flagRace, + MemorySanitizer: flagMSAN, + AddressSanitizer: flagASAN, + Cover: flagCover, + CoverPackage: flagCoverPkg, + ASMFlags: flagASMFlags, + BuildMode: flagBuildMode, + BuildVCS: flagBuildVCS, + Compiler: flagCompiler, + GcCGOFlags: flagGcCGOFlags, + GcFlags: flagGcFlags, + InstallSuffix: flagInstallSuffix, + LDFlags: flagLDFlags, + LinkShared: flagLinkShared, + ModMode: flagMod, + ModCacheRW: flagModCacheRW, + ModFile: flagModFile, + Overlay: flagOverlay, + ProfileGuidedOptimization: flagProfileGuidedOptimization, + PackageDir: flagPackageDir, + Tags: flagTags, + TrimPath: flagTrimPath, } // Determine if we have specific CFLAGS or LDFLAGS for this // GOOS/GOARCH combo and override the defaults if so. - envOverride(&opts.Ldflags, platform, "LDFLAGS") - envOverride(&opts.Gcflags, platform, "GCFLAGS") - envOverride(&opts.Asmflags, platform, "ASMFLAGS") + envOverride(&opts.LDFlags, platform, "LDFLAGS") + envOverride(&opts.GcFlags, platform, "GCFLAGS") + envOverride(&opts.ASMFlags, platform, "ASMFLAGS") envOverride(&opts.Cc, platform, "CC") envOverride(&opts.Cxx, platform, "CXX") @@ -221,23 +270,39 @@ Options: -arch="" Space-separated list of architectures to build for -build-toolchain Build cross-compilation toolchain -cgo Sets CGO_ENABLED=1, requires proper C toolchain (advanced) - -gcflags="" Additional '-gcflags' value to pass to go build - -ldflags="" Additional '-ldflags' value to pass to go build - -asmflags="" Additional '-asmflags' value to pass to go build - -tags="" Additional '-tags' value to pass to go build - -mod="" Additional '-mod' value to pass to go build - -buildmode="" Additional '-buildmode' value to pass to go build -os="" Space-separated list of operating systems to build for -osarch="" Space-separated list of os/arch pairs to build for -osarch-list List supported os/arch pairs for your Go version -output="foo" Output path template. See below for more info -parallel=-1 Amount of parallelism, defaults to number of CPUs - -race Build with the go race detector enabled, requires CGO -gocmd="go" Build command, defaults to Go - -rebuild Force rebuilding of package that were up to date - -trimpath Remove all file system paths from the resulting executable -verbose Verbose mode + -change-dir="" Passed to go build flag '-C'. Change to dir before running the command + -rebuild Passed to go build flag '-a'. Force rebuilding of package that were up to date + -race Passed to go build flag '-race'. Build with the go race detector enabled, requires CGO + -msan Passed to go build flag '-msan'. Enable interoperation with memory sanitizer + -asan Passed to go build flag '-asan'. Enable interoperation with address sanitizer + -cover Passed to go build flag '-cover'. Enable code coverage instrumentation + -coverpkg="" Passed to go build flag '-coverpkg'. Apply coverage analysis to each package matching the patterns + -asmflags="" Passed to go build flag '-asmflags'. + -buildmode="" Passed to go build flag '-buildmode'. + -buildvcs="" Passed to go build flag '-buildvcs'. + -compiler="" Passed to go build flag '-compiler'. + -gccgoflags="" Passed to go build flag '-gccgoflags'. + -gcflags="" Passed to go build flag '-gcflags'. + -installsuffix="" Passed to go build flag '-installsuffix'. + -ldflags="" Passed to go build flag '-ldflags'. + -linkshared Passed to go build flag '-linkshared'. + -mod="" Passed to go build flag '-mod'. + -modcacherw Passed to go build flag '-modcacherw'. + -modfile="" Passed to go build flag '-modfile'. + -overlay="" Passed to go build flag '-overlay'. + -pgo="" Passed to go build flag '-pgo'. + -pkgdir="" Passed to go build flag '-pkgdir'. + -tags="" Passed to go build flag '-tags'. + -trimpath Passed to go build flag '-trimpath'. Remove all file system paths from the resulting executable + Output path template: The output path for the compiled binaries is specified with the diff --git a/main_osarch.go b/main_osarch.go index 05c7ff5..2eaf77e 100644 --- a/main_osarch.go +++ b/main_osarch.go @@ -2,9 +2,11 @@ package main import ( "fmt" + + "github.com/hashicorp/go-version" ) -func mainListOSArch(version string) int { +func mainListOSArch(version *version.Version) int { fmt.Printf( "Supported OS/Arch combinations for %s are shown below. The \"default\"\n"+ "boolean means that if you don't specify an OS/Arch, it will be\n"+ diff --git a/opts.go b/opts.go new file mode 100644 index 0000000..360c2e8 --- /dev/null +++ b/opts.go @@ -0,0 +1,88 @@ +package main + +import ( + "github.com/hashicorp/go-version" +) + +type CompileOpts struct { + PackagePath string + Platform Platform + OutputTpl string + Cc string + Cxx string + Cgo bool + GoCmd string + GoVersion *version.Version + + ChangeDir string // -C (todo) + Rebuild bool // -a + Race bool // -race + + MemorySanitizer bool // -msan (todo) + AddressSanitizer bool // -asan (todo) + + Cover bool // -cover (todo) MUST SET GOEXPERIMENT=coverageredesign + CoverPackage string // -coverpkg (todo) + ASMFlags string // -asmflags + BuildMode string // -buildmode + BuildVCS string // -buildvs + Compiler string // -compiler (todo) + GcCGOFlags string // -gccgoflags (todo) + GcFlags string // -gcflags + InstallSuffix string // -installsuffix (todo) + LDFlags string // -ldflags + LinkShared bool // -linkshared (todo) + ModMode string // -mod + ModCacheRW bool // -modcacherw (todo) + ModFile string // -modfile (todo) + Overlay string // -overlay (todo) + + ProfileGuidedOptimization string // -pgo (todo) + + PackageDir string // -pkgdir (todo) + Tags string // -tags + TrimPath bool // -trimpath +} + +type BuildArgFlags struct { + args []string +} + +func (f *BuildArgFlags) Add(v *version.Version, name, value string, formatter func(string, string) string) { + +} + +var flagConstraints map[string]version.Constraints + +func init() { + inputs := []struct { + name string + constraint string + }{ + {"C", ">= 1.20"}, + {"asan", ">= 1.18"}, + {"cover", ">= 1.20"}, + {"coverpkg", ">= 1.20"}, + {"buildvcs", ">= 1.18"}, + {"modcacherw", ">= 1.14"}, + {"modfile", ">= 1.14"}, + {"overlay", ">= 1.16"}, + {"pgo", ">= 1.20"}, + {"trimpath", ">= 1.13"}, + } + + var ( + constraint version.Constraints + err error + ) + + flagConstraints = map[string]version.Constraints{} + + for _, input := range inputs { + if constraint, err = version.NewConstraint(input.constraint); err != nil { + panic(err) + } + + flagConstraints[input.name] = constraint + } +} diff --git a/platform.go b/platform.go index ea73212..5a9c5d8 100644 --- a/platform.go +++ b/platform.go @@ -2,8 +2,6 @@ package main import ( "fmt" - "log" - "strings" "github.com/hashicorp/go-version" ) @@ -57,129 +55,129 @@ func addDrop(base []Platform, add []Platform, drop []Platform) []Platform { var ( Platforms_1_0 = []Platform{ - {"darwin", "386", true}, - {"darwin", "amd64", true}, - {"linux", "386", true}, - {"linux", "amd64", true}, - {"linux", "arm", true}, - {"freebsd", "386", true}, - {"freebsd", "amd64", true}, - {"openbsd", "386", true}, - {"openbsd", "amd64", true}, - {"windows", "386", true}, - {"windows", "amd64", true}, + {goosDarwin, goarch386, true}, + {goosDarwin, goarchAMD64, true}, + {goosLinux, goarch386, true}, + {goosLinux, goarchAMD64, true}, + {goosLinux, goarchARM, true}, + {goosFreeBSD, goarch386, true}, + {goosFreeBSD, goarchAMD64, true}, + {goosOpenBSD, goarch386, true}, + {goosOpenBSD, goarchAMD64, true}, + {goosWindows, goarch386, true}, + {goosWindows, goarchAMD64, true}, } Platforms_1_1 = addDrop(Platforms_1_0, []Platform{ - {"freebsd", "arm", true}, - {"netbsd", "386", true}, - {"netbsd", "amd64", true}, - {"netbsd", "arm", true}, - {"plan9", "386", false}, + {goosFreeBSD, goarchARM, true}, + {goosNetBSD, goarch386, true}, + {goosNetBSD, goarchAMD64, true}, + {goosNetBSD, goarchARM, true}, + {goosPlan9, goarch386, false}, }, nil) Platforms_1_3 = addDrop(Platforms_1_1, []Platform{ - {"dragonfly", "386", false}, - {"dragonfly", "amd64", false}, - {"nacl", "amd64", false}, - {"nacl", "amd64p32", false}, - {"nacl", "arm", false}, - {"solaris", "amd64", false}, + {goosDragonfly, goarch386, false}, + {goosDragonfly, goarchAMD64, false}, + {goosNACL, goarchAMD64, false}, + {goosNACL, goarchAMD64P32, false}, + {goosNACL, goarchARM, false}, + {goosSolaris, goarchAMD64, false}, }, nil) Platforms_1_4 = addDrop(Platforms_1_3, []Platform{ - {"android", "arm", false}, - {"plan9", "amd64", false}, + {goosAndroid, goarchARM, false}, + {goosPlan9, goarchAMD64, false}, }, nil) Platforms_1_5 = addDrop(Platforms_1_4, []Platform{ - {"darwin", "arm", false}, - {"darwin", "arm64", false}, - {"linux", "arm64", false}, - {"linux", "ppc64", false}, - {"linux", "ppc64le", false}, + {goosDarwin, goarchARM, false}, + {goosDarwin, goarchARM64, false}, + {goosLinux, goarchARM64, false}, + {goosLinux, gooarchPowerPC64, false}, + {goosLinux, gooarchPowerPC64LE, false}, }, nil) Platforms_1_6 = addDrop(Platforms_1_5, []Platform{ - {"android", "386", false}, - {"android", "amd64", false}, - {"linux", "mips64", false}, - {"linux", "mips64le", false}, - {"nacl", "386", false}, - {"openbsd", "arm", true}, + {goosAndroid, goarch386, false}, + {goosAndroid, goarchAMD64, false}, + {goosLinux, goarchMIPS64, false}, + {goosLinux, goarchMIPS64LE, false}, + {goosNACL, goarch386, false}, + {goosOpenBSD, goarchARM, true}, }, nil) Platforms_1_7 = addDrop(Platforms_1_5, []Platform{ // While not fully supported s390x is generally useful - {"linux", "s390x", true}, - {"plan9", "arm", false}, + {goosLinux, goarchS390X, true}, + {goosPlan9, goarchARM, false}, // Add the 1.6 Platforms, but reflect full support for mips64 and mips64le - {"android", "386", false}, - {"android", "amd64", false}, - {"linux", "mips64", true}, - {"linux", "mips64le", true}, - {"nacl", "386", false}, - {"openbsd", "arm", true}, + {goosAndroid, goarch386, false}, + {goosAndroid, goarchAMD64, false}, + {goosLinux, goarchMIPS64, true}, + {goosLinux, goarchMIPS64LE, true}, + {goosNACL, goarch386, false}, + {goosOpenBSD, goarchARM, true}, }, nil) Platforms_1_8 = addDrop(Platforms_1_7, []Platform{ - {"linux", "mips", true}, - {"linux", "mipsle", true}, + {goosLinux, gooarchMIPS, true}, + {goosLinux, gooarchMIPSLE, true}, }, nil) // no new platforms in 1.9 Platforms_1_9 = Platforms_1_8 // unannounced, but dropped support for android/amd64 - Platforms_1_10 = addDrop(Platforms_1_9, nil, []Platform{{"android", "amd64", false}}) + Platforms_1_10 = addDrop(Platforms_1_9, nil, []Platform{{goosAndroid, goarchAMD64, false}}) Platforms_1_11 = addDrop(Platforms_1_10, []Platform{ - {"js", "wasm", true}, + {goosJavaScript, gooarchWebAssembly, true}, }, nil) Platforms_1_12 = addDrop(Platforms_1_11, []Platform{ - {"aix", "ppc64", false}, - {"windows", "arm", true}, + {goosAIX, gooarchPowerPC64, false}, + {goosWindows, goarchARM, true}, }, nil) Platforms_1_13 = addDrop(Platforms_1_12, []Platform{ - {"illumos", "amd64", false}, - {"netbsd", "arm64", true}, - {"openbsd", "arm64", true}, + {goosIllumos, goarchAMD64, false}, + {goosNetBSD, goarchARM64, true}, + {goosOpenBSD, goarchARM64, true}, }, nil) Platforms_1_14 = addDrop(Platforms_1_13, []Platform{ - {"freebsd", "arm64", true}, - {"linux", "riscv64", true}, + {goosFreeBSD, goarchARM64, true}, + {goosLinux, gooarchRISCV64, true}, }, []Platform{ // drop nacl - {"nacl", "386", false}, - {"nacl", "amd64", false}, - {"nacl", "arm", false}, + {goosNACL, goarch386, false}, + {goosNACL, goarchAMD64, false}, + {goosNACL, goarchARM, false}, }) Platforms_1_15 = addDrop(Platforms_1_14, []Platform{ - {"android", "arm64", false}, + {goosAndroid, goarchARM64, false}, }, []Platform{ // drop i386 macos - {"darwin", "386", false}, + {goosDarwin, goarch386, false}, }) Platforms_1_16 = addDrop(Platforms_1_15, []Platform{ - {"android", "amd64", false}, - {"darwin", "arm64", true}, - {"openbsd", "mips64", false}, + {goosAndroid, goarchAMD64, false}, + {goosDarwin, goarchARM64, true}, + {goosOpenBSD, goarchMIPS64, false}, }, nil) Platforms_1_17 = addDrop(Platforms_1_16, []Platform{ - {"windows", "arm64", true}, + {goosWindows, goarchARM64, true}, }, nil) // no new platforms in 1.18 Platforms_1_18 = Platforms_1_17 Platforms_1_19 = addDrop(Platforms_1_18, []Platform{ - {"linux", "loong64", true}, + {goosLinux, gooarchLoong64, true}, }, nil) Platforms_1_20 = Platforms_1_19 @@ -193,25 +191,33 @@ var ( // SupportedPlatforms returns the full list of supported platforms for // the version of Go that is -func SupportedPlatforms(v string) []Platform { - // Use latest if we get an unexpected version string - if !strings.HasPrefix(v, "go") { +func SupportedPlatforms(v *version.Version) []Platform { + if v == nil { return PlatformsLatest } - // go-version only cares about version numbers - v = v[2:] - current, err := version.NewVersion(v) - if err != nil { - log.Printf("Unable to parse current go version: %s\n%s", v, err.Error()) - - // Default to latest - return PlatformsLatest + for _, p := range platformConstraints { + if p.Constraints.Check(v) { + return p.Platforms + } } - var platforms = []struct { + // Assume latest + return PlatformsLatest +} + +// A PlatformConstraint describes a constraint for a list of platforms. +type PlatformConstraint struct { + Constraints version.Constraints + Platforms []Platform +} + +var platformConstraints []PlatformConstraint + +func init() { + inputs := []struct { constraint string - plat []Platform + platforms []Platform }{ {"<= 1.0", Platforms_1_0}, {">= 1.1, < 1.3", Platforms_1_1}, @@ -237,16 +243,18 @@ func SupportedPlatforms(v string) []Platform { {">= 1.22, < 1.23", Platforms_1_22}, } - for _, p := range platforms { - constraints, err := version.NewConstraint(p.constraint) - if err != nil { + platformConstraints = make([]PlatformConstraint, len(inputs)) + + var ( + constraint version.Constraints + err error + ) + + for i, input := range inputs { + if constraint, err = version.NewConstraint(input.constraint); err != nil { panic(err) } - if constraints.Check(current) { - return p.plat - } - } - // Assume latest - return PlatformsLatest + platformConstraints[i] = PlatformConstraint{Constraints: constraint, Platforms: input.platforms} + } } diff --git a/platform_test.go b/platform_test.go index 5efb11e..4976a68 100644 --- a/platform_test.go +++ b/platform_test.go @@ -3,130 +3,141 @@ package main import ( "reflect" "testing" + + "github.com/hashicorp/go-version" ) +func MustParseVersion(in string) *version.Version { + v, err := version.NewVersion(in[2:]) + if err != nil { + panic(err) + } + + return v +} + func TestSupportedPlatforms(t *testing.T) { var ps []Platform - ps = SupportedPlatforms("go1.0") + ps = SupportedPlatforms(MustParseVersion("go1.0")) if !reflect.DeepEqual(ps, Platforms_1_0) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.1") + ps = SupportedPlatforms(MustParseVersion("go1.1")) if !reflect.DeepEqual(ps, Platforms_1_1) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.2") + ps = SupportedPlatforms(MustParseVersion("go1.2")) if !reflect.DeepEqual(ps, Platforms_1_1) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.3") + ps = SupportedPlatforms(MustParseVersion("go1.3")) if !reflect.DeepEqual(ps, Platforms_1_3) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.4") + ps = SupportedPlatforms(MustParseVersion("go1.4")) if !reflect.DeepEqual(ps, Platforms_1_4) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.5") + ps = SupportedPlatforms(MustParseVersion("go1.5")) if !reflect.DeepEqual(ps, Platforms_1_5) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.6") + ps = SupportedPlatforms(MustParseVersion("go1.6")) if !reflect.DeepEqual(ps, Platforms_1_6) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.7") + ps = SupportedPlatforms(MustParseVersion("go1.7")) if !reflect.DeepEqual(ps, Platforms_1_7) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.8") + ps = SupportedPlatforms(MustParseVersion("go1.8")) if !reflect.DeepEqual(ps, Platforms_1_8) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.9") + ps = SupportedPlatforms(MustParseVersion("go1.9")) if !reflect.DeepEqual(ps, Platforms_1_9) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.10") + ps = SupportedPlatforms(MustParseVersion("go1.10")) if !reflect.DeepEqual(ps, Platforms_1_10) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.10") + ps = SupportedPlatforms(MustParseVersion("go1.10")) if !reflect.DeepEqual(ps, Platforms_1_10) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.11") + ps = SupportedPlatforms(MustParseVersion("go1.11")) if !reflect.DeepEqual(ps, Platforms_1_11) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.12") + ps = SupportedPlatforms(MustParseVersion("go1.12")) if !reflect.DeepEqual(ps, Platforms_1_12) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.13") + ps = SupportedPlatforms(MustParseVersion("go1.13")) if !reflect.DeepEqual(ps, Platforms_1_13) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.14") + ps = SupportedPlatforms(MustParseVersion("go1.14")) if !reflect.DeepEqual(ps, Platforms_1_14) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.15") + ps = SupportedPlatforms(MustParseVersion("go1.15")) if !reflect.DeepEqual(ps, Platforms_1_15) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.16") + ps = SupportedPlatforms(MustParseVersion("go1.16")) if !reflect.DeepEqual(ps, Platforms_1_16) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.17") + ps = SupportedPlatforms(MustParseVersion("go1.17")) if !reflect.DeepEqual(ps, Platforms_1_17) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.18") + ps = SupportedPlatforms(MustParseVersion("go1.18")) if !reflect.DeepEqual(ps, Platforms_1_18) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.19") + ps = SupportedPlatforms(MustParseVersion("go1.19")) if !reflect.DeepEqual(ps, Platforms_1_19) { t.Fatalf("bad: %#v", ps) } - ps = SupportedPlatforms("go1.20") + ps = SupportedPlatforms(MustParseVersion("go1.20")) if !reflect.DeepEqual(ps, Platforms_1_20) { t.Fatalf("bad: %#v", ps) } // Unknown - ps = SupportedPlatforms("foo") + ps = SupportedPlatforms(nil) if !reflect.DeepEqual(ps, PlatformsLatest) { t.Fatalf("bad: %#v", ps) } } func TestMIPS(t *testing.T) { - g16 := SupportedPlatforms("go1.6") + g16 := SupportedPlatforms(MustParseVersion("go1.6")) found := false for _, p := range g16 { if p.OS == "linux" && p.Arch == "mips64" && !p.Default { @@ -141,7 +152,7 @@ func TestMIPS(t *testing.T) { } found = false - g17 := SupportedPlatforms("go1.7") + g17 := SupportedPlatforms(MustParseVersion("go1.7")) for _, p := range g17 { if p.OS == "linux" && p.Arch == "mips64" && p.Default { found = true diff --git a/toolchain.go b/toolchain.go index bfce05e..5c1d0fc 100644 --- a/toolchain.go +++ b/toolchain.go @@ -10,11 +10,12 @@ import ( "runtime" "sync" + "github.com/hashicorp/go-version" "github.com/mitchellh/iochan" ) // The "main" method for when the toolchain build is requested. -func mainBuildToolchain(parallel int, platformFlag PlatformFlag, verbose bool) int { +func mainBuildToolchain(v *version.Version, parallel int, platformFlag PlatformFlag, verbose bool) int { if _, err := exec.LookPath("go"); err != nil { fmt.Fprintf(os.Stderr, "You must have Go already built for your native platform\n") fmt.Fprintf(os.Stderr, "and the `go` binary on the PATH to build toolchains.\n") @@ -35,12 +36,6 @@ func mainBuildToolchain(parallel int, platformFlag PlatformFlag, verbose bool) i return 1 } - version, err := GoVersion() - if err != nil { - fmt.Fprintf(os.Stderr, "error reading Go version: %s", err) - return 1 - } - root, err := GoRoot() if err != nil { fmt.Fprintf(os.Stderr, "error finding GOROOT: %s\n", err) @@ -53,7 +48,7 @@ func mainBuildToolchain(parallel int, platformFlag PlatformFlag, verbose bool) i } // Determine the platforms we're building the toolchain for. - platforms := platformFlag.Platforms(SupportedPlatforms(version)) + platforms := platformFlag.Platforms(SupportedPlatforms(v)) // The toolchain build can't be parallelized. if parallel > 1 { @@ -98,7 +93,7 @@ func buildToolchain(wg *sync.WaitGroup, semaphore chan int, root string, platfor fmt.Printf("--> Toolchain: %s\n", platform.String()) scriptName := "make.bash" - if runtime.GOOS == "windows" { + if runtime.GOOS == goosWindows { scriptName = "make.bat" } From d7e5d8fec22cbe74bc14d5416eb50304e271a03c Mon Sep 17 00:00:00 2001 From: James Elliott Date: Wed, 3 May 2023 10:03:17 +1000 Subject: [PATCH 2/7] feat: opts builder --- const.go | 4 ++ constraints.go | 97 +++++++++++++++++++++++++++ go.go | 86 ++---------------------- go.mod | 7 ++ go.sum | 17 +++++ main.go | 19 +----- opts.go | 173 +++++++++++++++++++++++++++++++++++++------------ opts_test.go | 51 +++++++++++++++ platform.go | 47 -------------- toolchain.go | 2 +- 10 files changed, 314 insertions(+), 189 deletions(-) create mode 100644 constraints.go create mode 100644 opts_test.go diff --git a/const.go b/const.go index 8066c5b..aeae6aa 100644 --- a/const.go +++ b/const.go @@ -1,5 +1,9 @@ package main +const ( + gobin = "go" +) + const ( flagNameRace = "race" flagNameMSAN = "msan" diff --git a/constraints.go b/constraints.go new file mode 100644 index 0000000..886f6de --- /dev/null +++ b/constraints.go @@ -0,0 +1,97 @@ +package main + +import "github.com/hashicorp/go-version" + +var ( + flagConstraints map[string]version.Constraints + platformConstraints []PlatformConstraint + experimentConstraints map[string]version.Constraints +) + +// Parse all of the constraints as efficiently as possible. +func init() { + var ( + ok bool + constraint version.Constraints + err error + ) + + parsed := map[string]version.Constraints{} + + flagConstraints = map[string]version.Constraints{} + + flagConstraintsInputs := []struct { + name string + constraint string + }{ + {"C", ">= 1.20"}, + {flagNameASAN, ">= 1.18"}, + {flagNameCover, ">= 1.20"}, + {flagNameCoverPKG, ">= 1.20"}, + {flagNameBuildVCS, ">= 1.18"}, + {flagNameModCacheRW, ">= 1.14"}, + {flagNameMod, ">= 1.11"}, + {flagNameModFile, ">= 1.14"}, + {flagNameOverlay, ">= 1.16"}, + {flagNameProfileGuidedOptimization, ">= 1.20"}, + {flagNameTrimPath, ">= 1.13"}, + } + + for _, input := range flagConstraintsInputs { + if constraint, ok = parsed[input.constraint]; ok { + flagConstraints[input.name] = constraint + + continue + } + + if constraint, err = version.NewConstraint(input.constraint); err != nil { + panic(err) + } + + flagConstraints[input.name] = constraint + parsed[input.constraint] = constraint + } + + platformConstraintsInputs := []struct { + constraint string + platforms []Platform + }{ + {"<= 1.0", Platforms_1_0}, + {">= 1.1, < 1.3", Platforms_1_1}, + {">= 1.3, < 1.4", Platforms_1_3}, + {">= 1.4, < 1.5", Platforms_1_4}, + {">= 1.5, < 1.6", Platforms_1_5}, + {">= 1.6, < 1.7", Platforms_1_6}, + {">= 1.7, < 1.8", Platforms_1_7}, + {">= 1.8, < 1.9", Platforms_1_8}, + {">= 1.9, < 1.10", Platforms_1_9}, + {">= 1.10, < 1.11", Platforms_1_10}, + {">= 1.11, < 1.12", Platforms_1_11}, + {">= 1.12, < 1.13", Platforms_1_12}, + {">= 1.13, < 1.14", Platforms_1_13}, + {">= 1.14, < 1.15", Platforms_1_14}, + {">= 1.15, < 1.16", Platforms_1_15}, + {">= 1.16, < 1.17", Platforms_1_16}, + {">= 1.17, < 1.18", Platforms_1_17}, + {">= 1.18, < 1.19", Platforms_1_18}, + {">= 1.19, < 1.20", Platforms_1_19}, + {">= 1.20, < 1.21", Platforms_1_20}, + } + + platformConstraints = make([]PlatformConstraint, len(platformConstraintsInputs)) + + for i, input := range platformConstraintsInputs { + if constraint, ok = parsed[input.constraint]; ok { + platformConstraints[i] = PlatformConstraint{Constraints: constraint, Platforms: input.platforms} + + continue + } + + if constraint, err = version.NewConstraint(input.constraint); err != nil { + panic(err) + } + + platformConstraints[i] = PlatformConstraint{Constraints: constraint, Platforms: input.platforms} + parsed[input.constraint] = constraint + } +} diff --git a/go.go b/go.go index 93b5008..0c9769b 100644 --- a/go.go +++ b/go.go @@ -21,17 +21,6 @@ type OutputTemplateData struct { // GoCrossCompile func GoCrossCompile(opts *CompileOpts) error { - env := append(os.Environ(), - "GOOS="+opts.Platform.OS, - "GOARCH="+opts.Platform.Arch) - - if opts.Cc != "" { - env = append(env, "CC="+opts.Cc) - } - if opts.Cxx != "" { - env = append(env, "CXX="+opts.Cxx) - } - // If we're building for our own platform, then enable cgo always. We // respect the CGO_ENABLED flag if that is explicitly set on the platform. if !opts.Cgo && os.Getenv("CGO_ENABLED") != "0" { @@ -39,13 +28,6 @@ func GoCrossCompile(opts *CompileOpts) error { runtime.GOARCH == opts.Platform.Arch } - // If cgo is enabled then set that env var - if opts.Cgo { - env = append(env, "CGO_ENABLED=1") - } else { - env = append(env, "CGO_ENABLED=0") - } - var outputPath bytes.Buffer tpl, err := template.New("output").Parse(opts.OutputTpl) if err != nil { @@ -98,75 +80,15 @@ func GoCrossCompile(opts *CompileOpts) error { opts.PackagePath = "" } - args := []string{"build"} - - if opts.Rebuild { - args = append(args, "-a") - } - - if opts.TrimPath { - args = append(args, "-trimpath") - } - - if opts.ModMode != "" { - args = append(args, fmtFlag("mod", opts.ModMode)) - } - - if opts.BuildMode != "" { - args = append(args, fmtFlag("buildmode", opts.BuildMode)) - } - - if opts.BuildVCS != "" { - args = append(args, fmtFlag("buildvcs", opts.BuildVCS)) - } - - if opts.Compiler != "" { - args = append(args, fmtFlag("-compiler", opts.Compiler)) - } - - if opts.Race { - args = append(args, "-race") - } - - if opts.GcFlags != "" { - args = append(args, fmtFlagSpaceSeparated("gcflags", opts.GcFlags)) - } - - if opts.GcCGOFlags != "" { - args = append(args, fmtFlagSpaceSeparated("gccgoflags", opts.GcCGOFlags)) - } - - if opts.LDFlags != "" { - args = append(args, fmtFlagSpaceSeparated("ldflags", opts.LDFlags)) - } - - if opts.ASMFlags != "" { - args = append(args, fmtFlagSpaceSeparated("asmflags", opts.ASMFlags)) - } - - if opts.Tags != "" { - args = append(args, fmt.Sprintf("-tags=%s", opts.Tags)) - } + args := append([]string{"build"}, opts.Arguments()...) args = append(args, "-o", outputPathReal, opts.PackagePath) - _, err = execGo(opts.GoCmd, env, chdir, args...) + _, err = execGo(opts.GoCmd, opts.Env(), chdir, args...) return err } -func fmtFlag(name, value string) string { - return fmt.Sprintf(`-%s=%s`, name, value) -} - -func fmtFlagSpaceSeparated(name, value string) string { - if strings.Contains(value, " ") && value[0] != '"' { - return fmt.Sprintf(`-%s="%s"`, name, value) - } - - return fmt.Sprintf(`-%s=%s`, name, value) -} - // GoMainDirs returns the file paths to the packages that are "main" // packages, from the list of packages given. The list of packages can // include relative paths, the special "..." Go keyword, etc. @@ -202,7 +124,7 @@ func GoMainDirs(packages []string, GoCmd string) ([]string, error) { // GoRoot returns the GOROOT value for the compiled `go` binary. func GoRoot() (string, error) { - output, err := execGo("go", nil, "", "env", "GOROOT") + output, err := execGo(gobin, nil, "", "env", "GOROOT") if err != nil { return "", err } @@ -231,7 +153,7 @@ func GoVersion() (string, error) { } // Execute and read the version, which will be the only thing on stdout. - version, err := execGo("go", nil, "", "run", sourcePath) + version, err := execGo(gobin, nil, "", "run", sourcePath) fmt.Printf("Detected Go Version: %s\n", version) diff --git a/go.mod b/go.mod index 35bdc51..508a449 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,11 @@ go 1.20 require ( github.com/hashicorp/go-version v1.6.0 github.com/mitchellh/iochan v1.0.0 + github.com/stretchr/testify v1.8.2 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fd3ac47..74d1838 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,21 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 517d017..c026dc6 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func realMain() int { flags.StringVar(&flagOutput, "output", "{{.Dir}}_{{.OS}}_{{.Arch}}", "") flags.IntVar(&flagParallel, "parallel", -1, "") flags.BoolVar(&flagVerbose, "verbose", false, "") - flags.StringVar(&flagGoCmd, "gocmd", "go", "") + flags.StringVar(&flagGoCmd, "gocmd", gobin, "") // Misc. flags.Var(flagPlatform.ArchFlagValue(), "arch", "") @@ -111,7 +111,7 @@ func realMain() int { var v *version.Version // Use latest if we get an unexpected version string - if strings.HasPrefix(versionStr, "go") { + if strings.HasPrefix(versionStr, gobin) { if v, err = version.NewVersion(versionStr[2:]); err != nil { log.Printf("Unable to parse current go version: %s\n%s", versionStr, err.Error()) } @@ -154,19 +154,6 @@ func realMain() int { return 1 } - // Assume -mod is supported when no version prefix is found - if flagMod != "" { - constraint, err := version.NewConstraint(">= 1.11") - if err != nil { - panic(err) - } - - if !constraint.Check(v) { - fmt.Printf("Go compiler version %s does not support the -mod flag\n", versionStr) - flagMod = "" - } - } - // Build in parallel! fmt.Printf("Number of parallel builds: %d\n\n", flagParallel) @@ -211,7 +198,7 @@ func realMain() int { InstallSuffix: flagInstallSuffix, LDFlags: flagLDFlags, LinkShared: flagLinkShared, - ModMode: flagMod, + Mod: flagMod, ModCacheRW: flagModCacheRW, ModFile: flagModFile, Overlay: flagOverlay, diff --git a/opts.go b/opts.go index 360c2e8..fbf93a8 100644 --- a/opts.go +++ b/opts.go @@ -1,7 +1,10 @@ package main import ( + "fmt" "github.com/hashicorp/go-version" + "os" + "strings" ) type CompileOpts struct { @@ -14,75 +17,159 @@ type CompileOpts struct { GoCmd string GoVersion *version.Version - ChangeDir string // -C (todo) + ChangeDir string // -C Rebuild bool // -a Race bool // -race - MemorySanitizer bool // -msan (todo) - AddressSanitizer bool // -asan (todo) + MemorySanitizer bool // -msan + AddressSanitizer bool // -asan - Cover bool // -cover (todo) MUST SET GOEXPERIMENT=coverageredesign - CoverPackage string // -coverpkg (todo) + Cover bool // -cover + CoverPackage string // -coverpkg ASMFlags string // -asmflags BuildMode string // -buildmode BuildVCS string // -buildvs - Compiler string // -compiler (todo) - GcCGOFlags string // -gccgoflags (todo) + Compiler string // -compiler + GcCGOFlags string // -gccgoflags GcFlags string // -gcflags - InstallSuffix string // -installsuffix (todo) + InstallSuffix string // -installsuffix LDFlags string // -ldflags - LinkShared bool // -linkshared (todo) - ModMode string // -mod - ModCacheRW bool // -modcacherw (todo) - ModFile string // -modfile (todo) - Overlay string // -overlay (todo) + LinkShared bool // -linkshared + Mod string // -mod + ModCacheRW bool // -modcacherw + ModFile string // -modfile + Overlay string // -overlay - ProfileGuidedOptimization string // -pgo (todo) + ProfileGuidedOptimization string // -pgo - PackageDir string // -pkgdir (todo) + PackageDir string // -pkgdir Tags string // -tags TrimPath bool // -trimpath } +func (opts *CompileOpts) Experiments() (exp []string) { + exp = strings.Split(os.Getenv("GOEXPERIMENT"), ",") + + if opts.Cover && (opts.GoVersion == nil || flagConstraints[flagNameCover].Check(opts.GoVersion)) { + if constraints, ok := experimentConstraints[flagNameCover]; !ok || constraints.Check(opts.GoVersion) { + exp = append(exp, "coverageredesign") + } + } + + return exp +} + +func (opts *CompileOpts) Env() []string { + env := append(os.Environ(), + "GOOS="+opts.Platform.OS, + "GOARCH="+opts.Platform.Arch) + + if opts.Cc != "" { + env = append(env, "CC="+opts.Cc) + } + + if opts.Cxx != "" { + env = append(env, "CXX="+opts.Cxx) + } + + if opts.Cgo { + env = append(env, "CGO_ENABLED=1") + } else { + env = append(env, "CGO_ENABLED=0") + } + + if exp := opts.Experiments(); len(exp) != 0 { + env = append(env, fmt.Sprintf("GOEXPERIMENT=%s", strings.Join(exp, ","))) + } + + return env +} + +func (opts *CompileOpts) Arguments() []string { + arguments := &BuildArgFlags{} + + arguments.AddString(opts.GoVersion, "C", opts.ChangeDir) + arguments.AddBoolean(opts.GoVersion, "a", opts.Rebuild) + arguments.AddBoolean(opts.GoVersion, flagNameRace, opts.Race) + arguments.AddBoolean(opts.GoVersion, flagNameMSAN, opts.MemorySanitizer) + arguments.AddBoolean(opts.GoVersion, flagNameASAN, opts.AddressSanitizer) + arguments.AddBoolean(opts.GoVersion, flagNameCover, opts.Cover) + arguments.AddString(opts.GoVersion, flagNameCoverPKG, opts.CoverPackage) + arguments.AddStrings(opts.GoVersion, flagNameASMFlags, opts.ASMFlags) + arguments.AddString(opts.GoVersion, flagNameBuildMode, opts.BuildMode) + arguments.AddString(opts.GoVersion, flagNameBuildVCS, opts.BuildVCS) + arguments.AddString(opts.GoVersion, flagNameCompiler, opts.Compiler) + arguments.AddStrings(opts.GoVersion, flagNameGcCGOFlags, opts.GcCGOFlags) + arguments.AddStrings(opts.GoVersion, flagNameGcFlags, opts.GcFlags) + arguments.AddString(opts.GoVersion, flagNameInstallSuffix, opts.InstallSuffix) + arguments.AddStrings(opts.GoVersion, flagNameLDFlags, opts.LDFlags) + arguments.AddBoolean(opts.GoVersion, flagNameLinkShared, opts.LinkShared) + arguments.AddString(opts.GoVersion, flagNameMod, opts.Mod) + arguments.AddBoolean(opts.GoVersion, flagNameModCacheRW, opts.ModCacheRW) + arguments.AddString(opts.GoVersion, flagNameModFile, opts.ModFile) + arguments.AddString(opts.GoVersion, flagNameOverlay, opts.Overlay) + arguments.AddString(opts.GoVersion, flagNameProfileGuidedOptimization, opts.ProfileGuidedOptimization) + arguments.AddString(opts.GoVersion, flagNamePackageDir, opts.PackageDir) + arguments.AddStrings(opts.GoVersion, flagNameTags, opts.Tags) + arguments.AddBoolean(opts.GoVersion, flagNameTrimPath, opts.TrimPath) + + return arguments.Args() +} + type BuildArgFlags struct { args []string } -func (f *BuildArgFlags) Add(v *version.Version, name, value string, formatter func(string, string) string) { +func (f *BuildArgFlags) Args() []string { + return f.args +} + +func (f *BuildArgFlags) ShouldSkipVersion(v *version.Version, name string) bool { + if v == nil { + return false + } + + if constraints, ok := flagConstraints[name]; ok { + if !constraints.Check(v) { + return true + } + } + + return false +} + +func (f *BuildArgFlags) AddStrings(v *version.Version, name, value string) { + if value == "" { + return + } + if f.ShouldSkipVersion(v, name) { + return + } + + f.args = append(f.args, fmt.Sprintf(`-%s="%s"`, name, value)) } -var flagConstraints map[string]version.Constraints - -func init() { - inputs := []struct { - name string - constraint string - }{ - {"C", ">= 1.20"}, - {"asan", ">= 1.18"}, - {"cover", ">= 1.20"}, - {"coverpkg", ">= 1.20"}, - {"buildvcs", ">= 1.18"}, - {"modcacherw", ">= 1.14"}, - {"modfile", ">= 1.14"}, - {"overlay", ">= 1.16"}, - {"pgo", ">= 1.20"}, - {"trimpath", ">= 1.13"}, +func (f *BuildArgFlags) AddString(v *version.Version, name, value string) { + if value == "" { + return } - var ( - constraint version.Constraints - err error - ) + if f.ShouldSkipVersion(v, name) { + return + } - flagConstraints = map[string]version.Constraints{} + f.args = append(f.args, fmt.Sprintf("-%s=%s", name, value)) +} - for _, input := range inputs { - if constraint, err = version.NewConstraint(input.constraint); err != nil { - panic(err) - } +func (f *BuildArgFlags) AddBoolean(v *version.Version, name string, value bool) { + if !value { + return + } - flagConstraints[input.name] = constraint + if f.ShouldSkipVersion(v, name) { + return } + + f.args = append(f.args, "-"+name) } diff --git a/opts_test.go b/opts_test.go new file mode 100644 index 0000000..6d42996 --- /dev/null +++ b/opts_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestCompileOpts_Arguments(t *testing.T) { + testCases := []struct { + name string + have *CompileOpts + expected []string + }{ + {"ShouldNotReturnAnyArgs", &CompileOpts{}, nil}, + {"ShouldReturnBooleanTrimPath", &CompileOpts{TrimPath: true}, []string{"-trimpath"}}, + {"ShouldReturnBooleanRace", &CompileOpts{Race: true}, []string{"-race"}}, + {"ShouldReturnBooleanCover", &CompileOpts{Cover: true}, []string{"-cover"}}, + {"ShouldReturnBooleanCoverWithVersion", &CompileOpts{GoVersion: MustParseVersion("go1.20"), Cover: true}, []string{"-cover"}}, + {"ShouldReturnBooleanCoverWithBadVersion", &CompileOpts{GoVersion: MustParseVersion("go1.19"), Cover: true}, nil}, + {"ShouldReturnBooleanRebuild", &CompileOpts{Rebuild: true}, []string{"-a"}}, + {"ShouldReturnBooleanMSAN", &CompileOpts{MemorySanitizer: true}, []string{"-msan"}}, + {"ShouldReturnBooleanASAN", &CompileOpts{AddressSanitizer: true}, []string{"-asan"}}, + {"ShouldReturnBooleanLinkShared", &CompileOpts{LinkShared: true}, []string{"-linkshared"}}, + {"ShouldReturnBooleanLinkModCacheRW", &CompileOpts{ModCacheRW: true}, []string{"-modcacherw"}}, + {"ShouldReturnBooleanLinkModCacheRWWithVersion", &CompileOpts{GoVersion: MustParseVersion("go1.19"), ModCacheRW: true}, []string{"-modcacherw"}}, + {"ShouldReturnBooleanLinkModCacheRWWithBadVersion", &CompileOpts{GoVersion: MustParseVersion("go1.13"), ModCacheRW: true}, nil}, + {"ShouldReturnBooleanMiscMixed", &CompileOpts{GoVersion: MustParseVersion("go1.13"), ModCacheRW: true, TrimPath: true, Rebuild: true}, []string{"-a", "-trimpath"}}, + {"ShouldReturnStringC", &CompileOpts{GoVersion: MustParseVersion("go1.20"), ChangeDir: "foo"}, []string{"-C=foo"}}, + {"ShouldReturnStringCoverPackage", &CompileOpts{GoVersion: MustParseVersion("go1.20"), CoverPackage: "foo"}, []string{"-coverpkg=foo"}}, + {"ShouldReturnStringsASMFlags", &CompileOpts{GoVersion: MustParseVersion("go1.20"), ASMFlags: "foo"}, []string{`-asmflags="foo"`}}, + {"ShouldReturnStringBuildMode", &CompileOpts{GoVersion: MustParseVersion("go1.20"), BuildMode: "foo"}, []string{`-buildmode=foo`}}, + {"ShouldReturnStringBuildVCS", &CompileOpts{GoVersion: MustParseVersion("go1.20"), BuildVCS: "foo"}, []string{`-buildvcs=foo`}}, + {"ShouldReturnStringCompiler", &CompileOpts{GoVersion: MustParseVersion("go1.20"), Compiler: "foo"}, []string{`-compiler=foo`}}, + {"ShouldReturnStringsGcCGOFlags", &CompileOpts{GoVersion: MustParseVersion("go1.20"), GcCGOFlags: "foo"}, []string{`-gccgoflags="foo"`}}, + {"ShouldReturnStringsGcFlags", &CompileOpts{GoVersion: MustParseVersion("go1.20"), GcFlags: "foo"}, []string{`-gcflags="foo"`}}, + {"ShouldReturnStringInstallSuffix", &CompileOpts{GoVersion: MustParseVersion("go1.20"), InstallSuffix: "foo"}, []string{`-installsuffix=foo`}}, + {"ShouldReturnStringsLDFlags", &CompileOpts{GoVersion: MustParseVersion("go1.20"), LDFlags: "foo"}, []string{`-ldflags="foo"`}}, + {"ShouldReturnStringMod", &CompileOpts{GoVersion: MustParseVersion("go1.20"), Mod: "foo"}, []string{`-mod=foo`}}, + {"ShouldReturnStringModFile", &CompileOpts{GoVersion: MustParseVersion("go1.20"), ModFile: "foo"}, []string{`-modfile=foo`}}, + {"ShouldReturnStringOverlay", &CompileOpts{GoVersion: MustParseVersion("go1.20"), Overlay: "foo"}, []string{`-overlay=foo`}}, + {"ShouldReturnStringPGO", &CompileOpts{GoVersion: MustParseVersion("go1.20"), ProfileGuidedOptimization: "foo"}, []string{`-pgo=foo`}}, + {"ShouldReturnStringPkgDir", &CompileOpts{GoVersion: MustParseVersion("go1.20"), PackageDir: "foo"}, []string{`-pkgdir=foo`}}, + {"ShouldReturnStringsTags", &CompileOpts{GoVersion: MustParseVersion("go1.20"), Tags: "foo"}, []string{`-tags="foo"`}}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.expected, tc.have.Arguments()) + }) + } +} diff --git a/platform.go b/platform.go index 5a9c5d8..ac566f3 100644 --- a/platform.go +++ b/platform.go @@ -211,50 +211,3 @@ type PlatformConstraint struct { Constraints version.Constraints Platforms []Platform } - -var platformConstraints []PlatformConstraint - -func init() { - inputs := []struct { - constraint string - platforms []Platform - }{ - {"<= 1.0", Platforms_1_0}, - {">= 1.1, < 1.3", Platforms_1_1}, - {">= 1.3, < 1.4", Platforms_1_3}, - {">= 1.4, < 1.5", Platforms_1_4}, - {">= 1.5, < 1.6", Platforms_1_5}, - {">= 1.6, < 1.7", Platforms_1_6}, - {">= 1.7, < 1.8", Platforms_1_7}, - {">= 1.8, < 1.9", Platforms_1_8}, - {">= 1.9, < 1.10", Platforms_1_9}, - {">= 1.10, < 1.11", Platforms_1_10}, - {">= 1.11, < 1.12", Platforms_1_11}, - {">= 1.12, < 1.13", Platforms_1_12}, - {">= 1.13, < 1.14", Platforms_1_13}, - {">= 1.14, < 1.15", Platforms_1_14}, - {">= 1.15, < 1.16", Platforms_1_15}, - {">= 1.16, < 1.17", Platforms_1_16}, - {">= 1.17, < 1.18", Platforms_1_17}, - {">= 1.18, < 1.19", Platforms_1_18}, - {">= 1.19, < 1.20", Platforms_1_19}, - {">= 1.20, < 1.21", Platforms_1_20}, - {">= 1.21, < 1.22", Platforms_1_21}, - {">= 1.22, < 1.23", Platforms_1_22}, - } - - platformConstraints = make([]PlatformConstraint, len(inputs)) - - var ( - constraint version.Constraints - err error - ) - - for i, input := range inputs { - if constraint, err = version.NewConstraint(input.constraint); err != nil { - panic(err) - } - - platformConstraints[i] = PlatformConstraint{Constraints: constraint, Platforms: input.platforms} - } -} diff --git a/toolchain.go b/toolchain.go index 5c1d0fc..8823326 100644 --- a/toolchain.go +++ b/toolchain.go @@ -16,7 +16,7 @@ import ( // The "main" method for when the toolchain build is requested. func mainBuildToolchain(v *version.Version, parallel int, platformFlag PlatformFlag, verbose bool) int { - if _, err := exec.LookPath("go"); err != nil { + if _, err := exec.LookPath(gobin); err != nil { fmt.Fprintf(os.Stderr, "You must have Go already built for your native platform\n") fmt.Fprintf(os.Stderr, "and the `go` binary on the PATH to build toolchains.\n") return 1 From 3185b1fda802766031e53a3470e8ac11816f32ba Mon Sep 17 00:00:00 2001 From: James Elliott Date: Wed, 3 May 2023 12:18:44 +1000 Subject: [PATCH 3/7] fix: deprecations --- go.go | 28 ---------------------------- meta.go | 3 +++ version.go | 37 ++++++++++++++++++++++++++++++++++++- version_legacy.go | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 meta.go create mode 100644 version_legacy.go diff --git a/go.go b/go.go index 0c9769b..9caa338 100644 --- a/go.go +++ b/go.go @@ -132,34 +132,6 @@ func GoRoot() (string, error) { return strings.TrimSpace(output), nil } -// GoVersion reads the version of `go` that is on the PATH. This is done -// instead of `runtime.Version()` because it is possible to run gox against -// another Go version. -func GoVersion() (string, error) { - // NOTE: We use `go run` instead of `go version` because the output - // of `go version` might change whereas the source is guaranteed to run - // for some time thanks to Go's compatibility guarantee. - - td, err := os.MkdirTemp("", "gox") - if err != nil { - return "", err - } - defer os.RemoveAll(td) - - // Write the source code for the program that will generate the version - sourcePath := filepath.Join(td, "version.go") - if err := os.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { - return "", err - } - - // Execute and read the version, which will be the only thing on stdout. - version, err := execGo(gobin, nil, "", "run", sourcePath) - - fmt.Printf("Detected Go Version: %s\n", version) - - return version, err -} - // GoVersionParts parses the version numbers from the version itself // into major and minor: 1.5, 1.4, etc. func GoVersionParts() (result [2]int, err error) { diff --git a/meta.go b/meta.go new file mode 100644 index 0000000..a900207 --- /dev/null +++ b/meta.go @@ -0,0 +1,3 @@ +package main + +const metaVersion = "1.1.1" diff --git a/version.go b/version.go index 3c29eb3..4aeb539 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,38 @@ +//go:build go1.16 +// +build go1.16 + package main -const metaVersion = "1.1.2" +import ( + "fmt" + "os" + "path/filepath" +) + +// GoVersion reads the version of `go` that is on the PATH. This is done +// instead of `runtime.Version()` because it is possible to run gox against +// another Go version. +func GoVersion() (string, error) { + // NOTE: We use `go run` instead of `go version` because the output + // of `go version` might change whereas the source is guaranteed to run + // for some time thanks to Go's compatibility guarantee. + + td, err := os.MkdirTemp("", "gox") + if err != nil { + return "", err + } + defer os.RemoveAll(td) + + // Write the source code for the program that will generate the version + sourcePath := filepath.Join(td, "version.go") + if err := os.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { + return "", err + } + + // Execute and read the version, which will be the only thing on stdout. + version, err := execGo(gobin, nil, "", "run", sourcePath) + + fmt.Printf("Detected Go Version: %s\n", version) + + return version, err +} diff --git a/version_legacy.go b/version_legacy.go new file mode 100644 index 0000000..222de6a --- /dev/null +++ b/version_legacy.go @@ -0,0 +1,39 @@ +//go:build !go1.16 +// +build !go1.16 + +package main + +import ( + "fmt" + "io/ioutil" + "os" + "path/filepath" +) + +// GoVersion reads the version of `go` that is on the PATH. This is done +// instead of `runtime.Version()` because it is possible to run gox against +// another Go version. +func GoVersion() (string, error) { + // NOTE: We use `go run` instead of `go version` because the output + // of `go version` might change whereas the source is guaranteed to run + // for some time thanks to Go's compatibility guarantee. + + td, err := ioutil.TempDir("", "gox") + if err != nil { + return "", err + } + defer os.RemoveAll(td) + + // Write the source code for the program that will generate the version + sourcePath := filepath.Join(td, "version.go") + if err := ioutil.WriteFile(sourcePath, []byte(versionSource), 0644); err != nil { + return "", err + } + + // Execute and read the version, which will be the only thing on stdout. + version, err := execGo(gobin, nil, "", "run", sourcePath) + + fmt.Printf("Detected Go Version: %s\n", version) + + return version, err +} From a0103a12f92deae03165e9d9e13d8f96114a6562 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Wed, 3 May 2023 13:27:59 +1000 Subject: [PATCH 4/7] fix: quoting --- opts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opts.go b/opts.go index fbf93a8..01da452 100644 --- a/opts.go +++ b/opts.go @@ -147,7 +147,7 @@ func (f *BuildArgFlags) AddStrings(v *version.Version, name, value string) { return } - f.args = append(f.args, fmt.Sprintf(`-%s="%s"`, name, value)) + f.args = append(f.args, "-"+name, value) } func (f *BuildArgFlags) AddString(v *version.Version, name, value string) { From 476994eb2c7f6351c3997d391b8ad64a199533b4 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 12 Aug 2023 20:03:21 +1000 Subject: [PATCH 5/7] docs: add docs Signed-off-by: James Elliott --- const.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/const.go b/const.go index aeae6aa..5620172 100644 --- a/const.go +++ b/const.go @@ -29,6 +29,7 @@ const ( flagNameTrimPath = "trimpath" ) +// Go Operating System values for GOOS. const ( goosWindows = "windows" goosLinux = "linux" @@ -46,6 +47,7 @@ const ( goosIllumos = "illumos" ) +// Go Architecture values for GOARCH. const ( goarch386 = "386" goarchAMD64 = "amd64" From f5cf9425abfe336486263686c6714f7d39af8576 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sun, 13 Aug 2023 09:53:52 +1000 Subject: [PATCH 6/7] test: add tests for go output Signed-off-by: James Elliott --- const.go | 32 +- constraints.go | 4 +- platform.go | 303 +++++++++++------- platform_test.go | 41 +++ platforms_output_test.go | 674 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 923 insertions(+), 131 deletions(-) create mode 100644 platforms_output_test.go diff --git a/const.go b/const.go index 5620172..6a54f01 100644 --- a/const.go +++ b/const.go @@ -34,6 +34,7 @@ const ( goosWindows = "windows" goosLinux = "linux" goosDarwin = "darwin" + goosIOS = "ios" goosFreeBSD = "freebsd" goosNetBSD = "netbsd" goosOpenBSD = "openbsd" @@ -45,23 +46,24 @@ const ( goosJavaScript = "js" goosAIX = "aix" goosIllumos = "illumos" + goosWASIP1 = "wasip1" ) // Go Architecture values for GOARCH. const ( - goarch386 = "386" - goarchAMD64 = "amd64" - goarchAMD64P32 = "amd64p32" - goarchARM = "arm" - goarchARM64 = "arm64" - gooarchMIPS = "mips" - gooarchMIPSLE = "mipsle" - goarchMIPS64 = "mips64" - goarchMIPS64LE = "mips64le" - goarchS390X = "s390x" - gooarchPowerPC64 = "ppc64" - gooarchPowerPC64LE = "ppc64le" - gooarchRISCV64 = "riscv64" - gooarchLoong64 = "loong64" - gooarchWebAssembly = "wasm" + goarch386 = "386" + goarchAMD64 = "amd64" + goarchAMD64P32 = "amd64p32" + goarchARM = "arm" + goarchARM64 = "arm64" + goarchMIPS = "mips" + goarchMIPSLE = "mipsle" + goarchMIPS64 = "mips64" + goarchMIPS64LE = "mips64le" + goarchS390X = "s390x" + goarchPowerPC64 = "ppc64" + goarchPowerPC64LE = "ppc64le" + goarchRISCV64 = "riscv64" + goarchLoong64 = "loong64" + goarchWebAssembly = "wasm" ) diff --git a/constraints.go b/constraints.go index 886f6de..ef6c0f5 100644 --- a/constraints.go +++ b/constraints.go @@ -57,7 +57,8 @@ func init() { platforms []Platform }{ {"<= 1.0", Platforms_1_0}, - {">= 1.1, < 1.3", Platforms_1_1}, + {">= 1.1, < 1.2", Platforms_1_1}, + {">= 1.2, < 1.3", Platforms_1_2}, {">= 1.3, < 1.4", Platforms_1_3}, {">= 1.4, < 1.5", Platforms_1_4}, {">= 1.5, < 1.6", Platforms_1_5}, @@ -76,6 +77,7 @@ func init() { {">= 1.18, < 1.19", Platforms_1_18}, {">= 1.19, < 1.20", Platforms_1_19}, {">= 1.20, < 1.21", Platforms_1_20}, + {">= 1.21, < 1.22", Platforms_1_21}, } platformConstraints = make([]PlatformConstraint, len(platformConstraintsInputs)) diff --git a/platform.go b/platform.go index ac566f3..181c4fc 100644 --- a/platform.go +++ b/platform.go @@ -42,11 +42,13 @@ func addDrop(base []Platform, add []Platform, drop []Platform) []Platform { if found < 0 { panic(fmt.Sprintf("Expected to remove %+v but not found in list %+v", platform, newPlatforms)) } - if found == len(newPlatforms)-1 { + + switch found { + case 0: + newPlatforms = newPlatforms[1:] + case len(newPlatforms) - 1: newPlatforms = newPlatforms[:found] - } else if found == 0 { - newPlatforms = newPlatforms[found:] - } else { + default: newPlatforms = append(newPlatforms[:found], newPlatforms[found+1:]...) } } @@ -68,121 +70,192 @@ var ( {goosWindows, goarchAMD64, true}, } - Platforms_1_1 = addDrop(Platforms_1_0, []Platform{ - {goosFreeBSD, goarchARM, true}, - {goosNetBSD, goarch386, true}, - {goosNetBSD, goarchAMD64, true}, - {goosNetBSD, goarchARM, true}, - {goosPlan9, goarch386, false}, - }, nil) - - Platforms_1_3 = addDrop(Platforms_1_1, []Platform{ - {goosDragonfly, goarch386, false}, - {goosDragonfly, goarchAMD64, false}, - {goosNACL, goarchAMD64, false}, - {goosNACL, goarchAMD64P32, false}, - {goosNACL, goarchARM, false}, - {goosSolaris, goarchAMD64, false}, - }, nil) - - Platforms_1_4 = addDrop(Platforms_1_3, []Platform{ - {goosAndroid, goarchARM, false}, - {goosPlan9, goarchAMD64, false}, - }, nil) - - Platforms_1_5 = addDrop(Platforms_1_4, []Platform{ - {goosDarwin, goarchARM, false}, - {goosDarwin, goarchARM64, false}, - {goosLinux, goarchARM64, false}, - {goosLinux, gooarchPowerPC64, false}, - {goosLinux, gooarchPowerPC64LE, false}, - }, nil) - - Platforms_1_6 = addDrop(Platforms_1_5, []Platform{ - {goosAndroid, goarch386, false}, - {goosAndroid, goarchAMD64, false}, - {goosLinux, goarchMIPS64, false}, - {goosLinux, goarchMIPS64LE, false}, - {goosNACL, goarch386, false}, - {goosOpenBSD, goarchARM, true}, - }, nil) - - Platforms_1_7 = addDrop(Platforms_1_5, []Platform{ - // While not fully supported s390x is generally useful - {goosLinux, goarchS390X, true}, - {goosPlan9, goarchARM, false}, - // Add the 1.6 Platforms, but reflect full support for mips64 and mips64le - {goosAndroid, goarch386, false}, - {goosAndroid, goarchAMD64, false}, - {goosLinux, goarchMIPS64, true}, - {goosLinux, goarchMIPS64LE, true}, - {goosNACL, goarch386, false}, - {goosOpenBSD, goarchARM, true}, - }, nil) - - Platforms_1_8 = addDrop(Platforms_1_7, []Platform{ - {goosLinux, gooarchMIPS, true}, - {goosLinux, gooarchMIPSLE, true}, - }, nil) + Platforms_1_1 = addDrop(Platforms_1_0, + []Platform{ + {goosFreeBSD, goarchARM, true}, + {goosNetBSD, goarch386, true}, + {goosNetBSD, goarchAMD64, true}, + {goosNetBSD, goarchARM, true}, + {goosPlan9, goarch386, false}, + }, + nil, + ) + + // no new platforms in 1.2 + Platforms_1_2 = Platforms_1_1 + + Platforms_1_3 = addDrop(Platforms_1_2, + []Platform{ + {goosDragonfly, goarch386, false}, + {goosDragonfly, goarchAMD64, false}, + {goosNACL, goarchAMD64, false}, + {goosNACL, goarchAMD64P32, false}, + {goosNACL, goarchARM, false}, + {goosSolaris, goarchAMD64, false}, + }, + nil, + ) + + Platforms_1_4 = addDrop(Platforms_1_3, + []Platform{ + {goosAndroid, goarchARM, false}, + {goosPlan9, goarchAMD64, false}, + }, + nil, + ) + + Platforms_1_5 = addDrop(Platforms_1_4, + []Platform{ + {goosDarwin, goarchARM, false}, + {goosDarwin, goarchARM64, false}, + {goosLinux, goarchARM64, false}, + {goosLinux, goarchPowerPC64, false}, + {goosLinux, goarchPowerPC64LE, false}, + }, + nil, + ) + + Platforms_1_6 = addDrop(Platforms_1_5, + []Platform{ + {goosAndroid, goarch386, false}, + {goosAndroid, goarchAMD64, false}, + {goosLinux, goarchMIPS64, false}, + {goosLinux, goarchMIPS64LE, false}, + {goosNACL, goarch386, false}, + {goosOpenBSD, goarchARM, true}, + }, + nil, + ) + + Platforms_1_7 = addDrop(Platforms_1_5, + []Platform{ + // Add the 1.6 Platforms, but reflect full support for mips64 and mips64le + {goosAndroid, goarch386, false}, + {goosAndroid, goarchAMD64, false}, + {goosLinux, goarchMIPS64, true}, + {goosLinux, goarchMIPS64LE, true}, + {goosNACL, goarch386, false}, + {goosOpenBSD, goarchARM, true}, + + {goosAndroid, goarchARM64, false}, + {goosLinux, goarchS390X, true}, + {goosPlan9, goarchARM, false}, + }, + []Platform{ + {goosNACL, goarchAMD64, false}, + {goosDragonfly, goarch386, false}, + }, + ) + + Platforms_1_8 = addDrop(Platforms_1_7, + []Platform{ + {goosLinux, goarchMIPS, true}, + {goosLinux, goarchMIPSLE, true}, + }, + nil, + ) // no new platforms in 1.9 Platforms_1_9 = Platforms_1_8 - // unannounced, but dropped support for android/amd64 - Platforms_1_10 = addDrop(Platforms_1_9, nil, []Platform{{goosAndroid, goarchAMD64, false}}) - - Platforms_1_11 = addDrop(Platforms_1_10, []Platform{ - {goosJavaScript, gooarchWebAssembly, true}, - }, nil) - - Platforms_1_12 = addDrop(Platforms_1_11, []Platform{ - {goosAIX, gooarchPowerPC64, false}, - {goosWindows, goarchARM, true}, - }, nil) - - Platforms_1_13 = addDrop(Platforms_1_12, []Platform{ - {goosIllumos, goarchAMD64, false}, - {goosNetBSD, goarchARM64, true}, - {goosOpenBSD, goarchARM64, true}, - }, nil) - - Platforms_1_14 = addDrop(Platforms_1_13, []Platform{ - {goosFreeBSD, goarchARM64, true}, - {goosLinux, gooarchRISCV64, true}, - }, []Platform{ - // drop nacl - {goosNACL, goarch386, false}, - {goosNACL, goarchAMD64, false}, - {goosNACL, goarchARM, false}, - }) - - Platforms_1_15 = addDrop(Platforms_1_14, []Platform{ - {goosAndroid, goarchARM64, false}, - }, []Platform{ - // drop i386 macos - {goosDarwin, goarch386, false}, - }) - - Platforms_1_16 = addDrop(Platforms_1_15, []Platform{ - {goosAndroid, goarchAMD64, false}, - {goosDarwin, goarchARM64, true}, - {goosOpenBSD, goarchMIPS64, false}, - }, nil) - - Platforms_1_17 = addDrop(Platforms_1_16, []Platform{ - {goosWindows, goarchARM64, true}, - }, nil) - - // no new platforms in 1.18 - Platforms_1_18 = Platforms_1_17 - - Platforms_1_19 = addDrop(Platforms_1_18, []Platform{ - {goosLinux, gooarchLoong64, true}, - }, nil) - - Platforms_1_20 = Platforms_1_19 - - Platforms_1_21 = Platforms_1_20 + // no new platforms in 1.10 + Platforms_1_10 = Platforms_1_9 + + Platforms_1_11 = addDrop(Platforms_1_10, + []Platform{ + {goosJavaScript, goarchWebAssembly, true}, + {goosLinux, goarchRISCV64, false}, + }, + nil, + ) + + Platforms_1_12 = addDrop(Platforms_1_11, + []Platform{ + {goosAIX, goarchPowerPC64, false}, + {goosWindows, goarchARM, true}, + }, + []Platform{ + {goosLinux, goarchRISCV64, false}, + }, + ) + + Platforms_1_13 = addDrop(Platforms_1_12, + []Platform{ + {goosIllumos, goarchAMD64, false}, + {goosNetBSD, goarchARM64, true}, + {goosOpenBSD, goarchARM64, true}, + }, + nil, + ) + + Platforms_1_14 = addDrop(Platforms_1_13, + []Platform{ + {goosFreeBSD, goarchARM64, true}, + {goosLinux, goarchRISCV64, true}, + }, + []Platform{ + // drop nacl + {goosNACL, goarch386, false}, + {goosNACL, goarchARM, false}, + {goosNACL, goarchAMD64P32, false}, + }, + ) + + Platforms_1_15 = addDrop(Platforms_1_14, + nil, + []Platform{ + {goosDarwin, goarch386, false}, + {goosDarwin, goarchARM, false}, + }, + ) + + Platforms_1_16 = addDrop(Platforms_1_15, + []Platform{ + {goosAndroid, goarchAMD64, false}, + {goosDarwin, goarchARM64, true}, + {goosIOS, goarchARM64, false}, + {goosIOS, goarchAMD64, false}, + {goosOpenBSD, goarchMIPS64, false}, + }, + nil, + ) + + Platforms_1_17 = addDrop(Platforms_1_16, + []Platform{ + {goosWindows, goarchARM64, true}, + }, + nil, + ) + + Platforms_1_18 = addDrop(Platforms_1_17, + []Platform{ + {goosIllumos, goarchAMD64, false}, + }, + nil, + ) + + Platforms_1_19 = addDrop(Platforms_1_18, + []Platform{ + {goosLinux, goarchLoong64, true}, + }, + nil, + ) + + Platforms_1_20 = addDrop(Platforms_1_19, + []Platform{ + {goosFreeBSD, goarchRISCV64, false}, + }, + nil, + ) + + Platforms_1_21 = addDrop(Platforms_1_20, + []Platform{ + {goosWASIP1, goarchWebAssembly, false}, + }, + []Platform{ + {goosOpenBSD, goarchMIPS64, false}, + }, + ) Platforms_1_22 = Platforms_1_21 diff --git a/platform_test.go b/platform_test.go index 4976a68..407ae78 100644 --- a/platform_test.go +++ b/platform_test.go @@ -2,9 +2,11 @@ package main import ( "reflect" + "sort" "testing" "github.com/hashicorp/go-version" + "github.com/stretchr/testify/assert" ) func MustParseVersion(in string) *version.Version { @@ -165,3 +167,42 @@ func TestMIPS(t *testing.T) { t.Fatal("Expected to find linux/mips64/true in go1.7 supported platforms") } } + +func TestPlatformsGoOutput(t *testing.T) { + var versions []string + + for v, _ := range goToolDistListOutput { + versions = append(versions, v) + } + + sort.Slice(versions, func(i, j int) bool { + return version.Must(version.NewSemver(versions[i])).LessThan(version.Must(version.NewSemver(versions[j]))) + }) + + for _, v := range versions { + platforms := SupportedPlatforms(version.Must(version.NewVersion(v))) + + t.Run(v, func(t *testing.T) { + platformsOutput, ok := goToolDistListOutput[v] + + if !ok { + return + } + + var platformList []string + + t.Run("ShouldNotContainPlatformsAbsentFromOutput", func(t *testing.T) { + for _, platform := range platforms { + platformList = append(platformList, platform.String()) + assert.Contains(t, platformsOutput, platform.String()) + } + }) + + t.Run("ShouldContainAllPlatformsFromOutput", func(t *testing.T) { + for _, platform := range platformsOutput { + assert.Contains(t, platformList, platform) + } + }) + }) + } +} diff --git a/platforms_output_test.go b/platforms_output_test.go new file mode 100644 index 0000000..e49ea25 --- /dev/null +++ b/platforms_output_test.go @@ -0,0 +1,674 @@ +package main + +// The following vars include the values from the go tool dist list command. This information is used for testing to +// ensure the platforms values at least have all of the values in this list for a given version. +// +// This command was only introduced in go 1.7 so the information is incomplete. +// +// It would be useful at some stage to leverage this for a code generator for versions above 1.7. + +var goToolDistListOutput = map[string][]string{ + "1.7": { + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips64", + "linux/mips64le", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + }, + "1.8": { + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + }, + "1.9": { + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + }, + "1.10": { + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + }, + "1.11": { + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + }, + "1.12": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + }, + "1.13": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "illumos/amd64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/s390x", + "nacl/386", + "nacl/amd64p32", + "nacl/arm", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + }, + "1.14": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/386", + "darwin/amd64", + "darwin/arm", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + }, + "1.15": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + }, + "1.16": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "openbsd/mips64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + }, + "1.17": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "openbsd/mips64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + "windows/arm64", + }, + "1.18": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "openbsd/mips64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + "windows/arm64", + }, + "1.19": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/loong64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "openbsd/mips64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + "windows/arm64", + }, + "1.20": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "freebsd/riscv64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/loong64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "openbsd/mips64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "windows/386", + "windows/amd64", + "windows/arm", + "windows/arm64", + }, + "1.21": { + "aix/ppc64", + "android/386", + "android/amd64", + "android/arm", + "android/arm64", + "darwin/amd64", + "darwin/arm64", + "dragonfly/amd64", + "freebsd/386", + "freebsd/amd64", + "freebsd/arm", + "freebsd/arm64", + "freebsd/riscv64", + "illumos/amd64", + "ios/amd64", + "ios/arm64", + "js/wasm", + "linux/386", + "linux/amd64", + "linux/arm", + "linux/arm64", + "linux/loong64", + "linux/mips", + "linux/mips64", + "linux/mips64le", + "linux/mipsle", + "linux/ppc64", + "linux/ppc64le", + "linux/riscv64", + "linux/s390x", + "netbsd/386", + "netbsd/amd64", + "netbsd/arm", + "netbsd/arm64", + "openbsd/386", + "openbsd/amd64", + "openbsd/arm", + "openbsd/arm64", + "plan9/386", + "plan9/amd64", + "plan9/arm", + "solaris/amd64", + "wasip1/wasm", + "windows/386", + "windows/amd64", + "windows/arm", + "windows/arm64", + }, +} From a9fdb9c5b5b92c1f93d3abc2ebf4bf17da1b84c0 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sun, 13 Aug 2023 16:03:51 +1000 Subject: [PATCH 7/7] meta: update version Signed-off-by: James Elliott --- meta.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta.go b/meta.go index a900207..d574943 100644 --- a/meta.go +++ b/meta.go @@ -1,3 +1,3 @@ package main -const metaVersion = "1.1.1" +const metaVersion = "1.2.0"