moved compiler flags out of code into flags.yaml

This commit is contained in:
Giovanni Harting 2022-06-18 23:57:53 +02:00
parent c0a4cb555b
commit 622ba6ad1a
5 changed files with 191 additions and 60 deletions

35
flags.yaml Normal file
View File

@ -0,0 +1,35 @@
# template values get replaced on makepkg.conf generation
# $level$ -> march x86-64 level, e.g. v3
# $march$ -> full march, e.g. x86-64-v3
# $buildproc$ -> number of threads to build with
common:
cflags:
- "-mtune=generic": ~
- "-O2": "-O3"
- "-mpclmul" # https://git.harting.dev/ALHP/ALHP.GO/issues/92
- "-march=x86-64": "-march=$march$"
options:
- "lto": "!lto" # disable lto; see 'lto' section below
buildenv:
- "color": "!color" # color messes up the log output
goamd64: "$level$" # https://git.harting.dev/ALHP/ALHP.GO/issues/116
packager: "ALHP $march$ <alhp@harting.dev>"
makeflags: "-j$buildproc$"
# https://git.harting.dev/ALHP/ALHP.GO/issues/110
rustflags: |-
-Copt-level=3 -Ctarget-cpu=$march$
ltoflags:
- "-falign-functions=32" # https://github.com/InBetweenNames/gentooLTO/issues/164
lto:
rustflags:
- "-Clto=fat"
- "codegen-units=1"
- "-Clinker-plugin-lto"
options:
- "lto"

10
go.mod
View File

@ -11,13 +11,13 @@ require (
github.com/jackc/pgx/v4 v4.16.1
github.com/sirupsen/logrus v1.8.1
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
gopkg.in/yaml.v2 v2.4.0
lukechampine.com/blake3 v1.1.7
)
require (
ariga.io/atlas v0.3.8 // indirect
ariga.io/atlas v0.4.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
@ -31,11 +31,11 @@ require (
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/klauspost/cpuid/v2 v2.0.13 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
golang.org/x/text v0.3.7 // indirect
)

20
go.sum
View File

@ -1,5 +1,5 @@
ariga.io/atlas v0.3.8 h1:O1JH6fmCc1P8nUtEMVW6Xju/ASiTeqG2JCgxzaj0SaE=
ariga.io/atlas v0.3.8/go.mod h1:D/d0a5QyMFU2R5E8ArmpnWbMjFP9LOr0TsQNbKqhT20=
ariga.io/atlas v0.4.2 h1:6p4jRJq0mmm2LfaY9y5H4/hI4D/wtCVv1UrFylTwSqg=
ariga.io/atlas v0.4.2/go.mod h1:0eSMrFg/pqF2qZ+bjM3yRvlzKROYaLbKbSVaU0RKr5g=
entgo.io/ent v0.10.2-0.20220502113020-4ac82f5bb3f0 h1:qHA4+ANAzDj6BcDLxNgZuzKxFre/RI9r5wwsI2O+1M4=
entgo.io/ent v0.10.2-0.20220502113020-4ac82f5bb3f0/go.mod h1:Zh61BPvB+cL6VWEyN8f1YoDacrMjQf2KDlDeX26xq2k=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@ -98,8 +98,8 @@ github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv
github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.13 h1:1XxvOiqXZ8SULZUKim/wncr3wZ38H4yCuVDvKdK9OGs=
github.com/klauspost/cpuid/v2 v2.0.13/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@ -184,8 +184,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8=
golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
@ -201,8 +201,8 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -216,8 +216,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -51,17 +51,18 @@ func (p *ProtoPackage) isEligible(ctx context.Context) (bool, error) {
p.toDbPackage(true)
skipping := false
if contains(p.Srcinfo.Arch, "any") {
if Contains(p.Srcinfo.Arch, "any") {
log.Debugf("Skipped %s: any-Package", p.Srcinfo.Pkgbase)
p.DbPackage.SkipReason = "arch = any"
p.DbPackage.Status = dbpackage.StatusSkipped
skipping = true
} else if contains(conf.Blacklist.Packages, p.Srcinfo.Pkgbase) {
} else if Contains(conf.Blacklist.Packages, p.Srcinfo.Pkgbase) {
log.Debugf("Skipped %s: blacklisted package", p.Srcinfo.Pkgbase)
p.DbPackage.SkipReason = "blacklisted"
p.DbPackage.Status = dbpackage.StatusSkipped
skipping = true
} else if contains(p.Srcinfo.MakeDepends, "ghc") || contains(p.Srcinfo.MakeDepends, "haskell-ghc") || contains(p.Srcinfo.Depends, "ghc") || contains(p.Srcinfo.Depends, "haskell-ghc") {
} else if Contains(p.Srcinfo.MakeDepends, "ghc") || Contains(p.Srcinfo.MakeDepends, "haskell-ghc") ||
Contains(p.Srcinfo.Depends, "ghc") || Contains(p.Srcinfo.Depends, "haskell-ghc") {
// Skip Haskell packages for now, as we are facing linking problems with them,
// most likely caused by not having a dependency check implemented yet and building at random.
// https://git.harting.dev/anonfunc/ALHP.GO/issues/11
@ -83,7 +84,7 @@ func (p *ProtoPackage) isEligible(ctx context.Context) (bool, error) {
p.DbPackage = p.DbPackage.Update().SetUpdated(time.Now()).SetPackages(packages2slice(p.Srcinfo.Packages)).SetVersion(p.Version).SaveX(ctx)
}
if contains(conf.Blacklist.LTO, p.Pkgbase) {
if Contains(conf.Blacklist.LTO, p.Pkgbase) {
p.DbPackage = p.DbPackage.Update().SetLto(dbpackage.LtoDisabled).SaveX(ctx)
}
@ -181,7 +182,7 @@ func (p *ProtoPackage) build(ctx context.Context) (time.Duration, error) {
return time.Since(start), fmt.Errorf("error while increasing pkgrel: %w", err)
}
if contains(conf.KernelToPatch, p.Pkgbase) {
if Contains(conf.KernelToPatch, p.Pkgbase) {
err = p.prepareKernelPatches()
if err != nil {
p.DbPackage.Update().SetStatus(dbpackage.StatusFailed).SetSkipReason("failed to apply patch").SetHash(p.Hash).ExecX(ctx)
@ -590,7 +591,7 @@ func (p *ProtoPackage) SVN2GITVersion(h *alpm.Handle) (string, error) {
continue
}
if !contains(fPkgbuilds, pkgbuild) {
if !Contains(fPkgbuilds, pkgbuild) {
fPkgbuilds = append(fPkgbuilds, pkgbuild)
}
}
@ -718,7 +719,7 @@ func (p *ProtoPackage) findPkgFiles() error {
if !file.IsDir() && !strings.HasSuffix(file.Name(), ".sig") {
matches := rePkgFile.FindStringSubmatch(file.Name())
if len(matches) > 1 && contains(realPkgs, matches[1]) {
if len(matches) > 1 && Contains(realPkgs, matches[1]) {
fPkg = append(fPkg, filepath.Join(conf.Basedir.Repo, p.FullRepo, "os", conf.Arch, file.Name()))
}
}

171
utils.go
View File

@ -11,6 +11,7 @@ import (
"github.com/Morganamilo/go-srcinfo"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/semaphore"
"gopkg.in/yaml.v2"
"io"
"io/fs"
"lukechampine.com/blake3"
@ -38,10 +39,12 @@ const (
waitingDir = "to_be_moved"
makepkgLTO = "makepkg-%s-non-lto.conf"
makepkg = "makepkg-%s.conf"
flagConfig = "flags.yaml"
)
var (
reMarch = regexp.MustCompile(`(-march=)(.+?) `)
reVar = regexp.MustCompile(`(?mU)^#?[^\S\r\n]*(\w+)[^\S\r\n]*=[^\S\r\n]*([("])([^)"]+)([)"])[^\S\r\n]*$`)
reEnvClean = regexp.MustCompile(`(?m) ([\s\\]+) `)
rePkgRel = regexp.MustCompile(`(?m)^pkgrel\s*=\s*(.+)$`)
rePkgSource = regexp.MustCompile(`(?msU)^source.*=.*\((.+)\)$`)
rePkgSum = regexp.MustCompile(`(?msU)^sha256sums.*=.*\((.+)\)$`)
@ -224,7 +227,7 @@ func genQueue(path string) ([]*ProtoPackage, error) {
var pkgbuilds []*ProtoPackage
for _, pkgbuild := range pkgBuilds {
mPkgbuild := PKGBUILD(pkgbuild)
if mPkgbuild.FullRepo() == "trunk" || !contains(conf.Repos, mPkgbuild.Repo()) || containsSubStr(mPkgbuild.FullRepo(), conf.Blacklist.Repo) {
if mPkgbuild.FullRepo() == "trunk" || !Contains(conf.Repos, mPkgbuild.Repo()) || containsSubStr(mPkgbuild.FullRepo(), conf.Blacklist.Repo) {
continue
}
@ -673,8 +676,18 @@ func syncMarchs() error {
}
}
flagConfigRaw, err := os.ReadFile(flagConfig)
if err != nil {
return err
}
var flagCfg map[string]interface{}
err = yaml.Unmarshal(flagConfigRaw, &flagCfg)
if err != nil {
return err
}
for _, march := range conf.March {
err := setupMakepkg(march)
err := setupMakepkg(march, flagCfg)
if err != nil {
log.Fatalf("Can't generate makepkg for %s: %v", march, err)
}
@ -694,7 +707,7 @@ func syncMarchs() error {
}
}
if i := find(eRepos, fRepo); i != -1 {
if i := Find(eRepos, fRepo); i != -1 {
eRepos = append(eRepos[:i], eRepos[i+1:]...)
}
}
@ -712,8 +725,82 @@ func syncMarchs() error {
return nil
}
func replaceStringsFromMap(str string, replace map[string]string) string {
for k, v := range replace {
str = strings.ReplaceAll(str, k, v)
}
return str
}
func parseFlagSubSection(list interface{}, res []string, replaceMap map[string]string) []string {
for _, cEntry := range list.([]interface{}) {
switch ce := cEntry.(type) {
case map[interface{}]interface{}:
for k, v := range ce {
if v == nil {
res = append(res[:Find(res, k.(string))], res[Find(res, k.(string))+1:]...)
} else if s, ok := v.(string); ok {
Replace(res, k.(string), replaceStringsFromMap(s, replaceMap))
} else {
log.Warningf("malformated flag-config: unable to handle %v:%v", replaceStringsFromMap(k.(string), replaceMap), v)
}
}
case string:
res = append(res, replaceStringsFromMap(ce, replaceMap))
default:
log.Warningf("malformated flag-config: unable to handle %v (%T)", cEntry, cEntry)
}
}
return res
}
func parseFlagSection(section interface{}, makepkgConf string, march string) (string, error) {
replaceMap := map[string]string{"$level$": march[len(march)-2:], "$march$": march, "$buildproc$": strconv.Itoa(conf.Build.Makej)}
if ct, ok := section.(map[interface{}]interface{}); ok {
for subSec, subMap := range ct {
varsReg := reVar.FindAllStringSubmatch(makepkgConf, -1)
if varsReg == nil {
return "", fmt.Errorf("no match in config found")
}
var flags []string
var orgMatch []string
for _, match := range varsReg {
if strings.ToLower(match[1]) == subSec.(string) {
flags = strings.Split(reEnvClean.ReplaceAllString(match[3], ""), " ")
orgMatch = match
}
}
if _, ok := subMap.(string); ok && len(orgMatch) > 0 {
makepkgConf = strings.ReplaceAll(makepkgConf, orgMatch[0], fmt.Sprintf("\n%s=%s%s%s",
strings.ToUpper(subSec.(string)), orgMatch[2], replaceStringsFromMap(subMap.(string), replaceMap), orgMatch[4]))
continue
}
if len(orgMatch) == 0 {
// no match found, assume env var and append it
log.Debugf("no match found for %s:%v, appending", subSec, subMap)
makepkgConf += fmt.Sprintf("\n%s=%s", strings.ToUpper(subSec.(string)), replaceStringsFromMap(subMap.(string), replaceMap))
continue
}
log.Debugf("original %s: %v (%d)", subSec, flags, len(flags))
flags = parseFlagSubSection(subMap, flags, replaceMap)
log.Debugf("new %s: %v (%d)", subSec, flags, len(flags))
makepkgConf = strings.ReplaceAll(makepkgConf, orgMatch[0], fmt.Sprintf(`%s=%s%s%s`, orgMatch[1], orgMatch[2], strings.Join(flags, " "), orgMatch[4]))
}
}
return makepkgConf, nil
}
//goland:noinspection SpellCheckingInspection
func setupMakepkg(march string) error {
func setupMakepkg(march string, flags map[string]interface{}) error {
lMakepkg := filepath.Join(conf.Basedir.Work, makepkgDir, fmt.Sprintf(makepkg, march))
lMakepkgLTO := filepath.Join(conf.Basedir.Work, makepkgDir, fmt.Sprintf(makepkgLTO, march))
@ -727,50 +814,35 @@ func setupMakepkg(march string) error {
}
makepkgStr := string(t)
makepkgStr = strings.ReplaceAll(makepkgStr, "-mtune=generic", "")
if !conf.Build.Checks {
makepkgStr = strings.ReplaceAll(makepkgStr, " check ", " !check ")
}
makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ")
// set Go optimization flag
makepkgStr = strings.ReplaceAll(makepkgStr, "LDFLAGS=", "GOAMD64="+march[len(march)-2:]+"\nLDFLAGS=")
// Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more
makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32 -mpclmul")
makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"")
makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march)
makepkgStr = strings.ReplaceAll(makepkgStr, "#PACKAGER=\"John Doe <john@doe.com>\"", "PACKAGER=\"ALHP "+march+" <alhp@harting.dev>\"")
// enable rust flags and patch them
makepkgStr = strings.ReplaceAll(makepkgStr, "#RUSTFLAGS=", "RUSTFLAGS=")
makepkgStr = strings.ReplaceAll(makepkgStr, "-C opt-level=2", "-C opt-level=3")
makepkgStr = strings.ReplaceAll(makepkgStr, "-C opt-level=3", "-C opt-level=3 -C target-cpu="+march+" -C lto=fat -C codegen-units=1 -C strip=symbols -C linker-plugin-lto")
// write makepkg
err = os.WriteFile(lMakepkg, []byte(makepkgStr), 0644)
makepkgStr, err = parseFlagSection(flags["common"], makepkgStr, march)
if err != nil {
return err
}
// Remove LTO. Since lto is enabled pre default in devtools since 20211129-1, remove it.
// See https://git.harting.dev/anonfunc/ALHP.GO/issues/52 for more
makepkgStr = strings.ReplaceAll(makepkgStr, "lto", "!lto")
// Remove align-functions=32, which is enabled because of LTO and not needed without
makepkgStr = strings.ReplaceAll(makepkgStr, "-falign-functions=32", "")
// Remove devirtualize-at-ltrans, which is only helpful when using LTO and not needed without
makepkgStr = strings.ReplaceAll(makepkgStr, "-fdevirtualize-at-ltrans", "")
// write non-lto makepkg
err = os.WriteFile(lMakepkgLTO, []byte(makepkgStr), 0644)
if err != nil {
return err
}
makepkgStr, err = parseFlagSection(flags["lto"], makepkgStr, march)
if err != nil {
return err
}
// write makepkg
err = os.WriteFile(lMakepkg, []byte(makepkgStr), 0644)
if err != nil {
return err
}
return nil
}
func contains(s interface{}, str string) bool {
func Contains(s interface{}, str string) bool {
switch v := s.(type) {
case []string:
if i := find(v, str); i != -1 {
if i := Find(v, str); i != -1 {
return true
}
case []srcinfo.ArchString:
@ -779,7 +851,7 @@ func contains(s interface{}, str string) bool {
n = append(n, as.Value)
}
if i := find(n, str); i != -1 {
if i := Find(n, str); i != -1 {
return true
}
default:
@ -789,9 +861,9 @@ func contains(s interface{}, str string) bool {
return false
}
func find(s []string, str string) int {
for i, v := range s {
if v == str {
func Find[T comparable](arr []T, match T) int {
for i, v := range arr {
if v == match {
return i
}
}
@ -799,6 +871,29 @@ func find(s []string, str string) int {
return -1
}
func Unique[T comparable](arr []T) []T {
occurred := map[T]bool{}
var result []T
for e := range arr {
if occurred[arr[e]] != true {
occurred[arr[e]] = true
result = append(result, arr[e])
}
}
return result
}
func Replace[T comparable](arr []T, replace T, with T) []T {
for i, v := range arr {
if v == replace {
arr[i] = with
}
}
return arr
}
func copyFile(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {