gocc/compile_config.go

64 lines
1.1 KiB
Go

package main
import (
"fmt"
"os/exec"
"strings"
"git.milar.in/milarin/gmath"
"golang.org/x/exp/slices"
)
var CompileConfigs = []*CompileConfig{}
type CompileConfig struct {
OS string
Arch string
FileExt string
Compress bool
}
func (cfg CompileConfig) String() string {
return fmt.Sprintf("%s/%s:", cfg.OS, cfg.Arch)
}
func FillCompileConfigs() error {
cmd := exec.Command("go", "tool", "dist", "list")
systems := strings.Split(*OS, ",")
arches := strings.Split(*Arch, ",")
out, err := cmd.Output()
if err != nil {
return err
}
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
for _, line := range lines {
splits := strings.Split(line, "/")
os, arch := splits[0], splits[1]
if (*OS != "" && !slices.Contains(systems, os)) || (*Arch != "" && !slices.Contains(arches, arch)) {
continue
}
ext := ""
if os == "windows" {
ext = ".exe"
}
cfg := &CompileConfig{
OS: os,
Arch: arch,
Compress: true,
FileExt: ext,
}
MaxConfigStringLength = gmath.Max(MaxConfigStringLength, len(cfg.String()))
CompileConfigs = append(CompileConfigs, cfg)
}
return nil
}