diff --git a/config_dist.yaml b/config_dist.yaml index 9df68cf..e50b40d 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -23,7 +23,6 @@ march: blacklist: packages: - - pacman - tensorflow - tensorflow-cuda - gcc @@ -32,6 +31,9 @@ blacklist: - i686 - staging - unstable + lto: + - llvm + - rust build: worker: 4 diff --git a/main.go b/main.go index 8b83c0d..588ac64 100644 --- a/main.go +++ b/main.go @@ -77,9 +77,15 @@ func (b *BuildManager) buildWorker(id int) { } pkg.PkgFiles = []string{} + // default to LTO + makepkgFile := "makepkg-%s-lto.conf" + if contains(conf.Blacklist.LTO, pkg.Pkgbase) { + // use non-lto makepkg.conf if LTO is blacklisted for this package + makepkgFile = "makepkg-%s.conf" + } cmd := exec.Command("sh", "-c", "cd "+filepath.Dir(pkg.Pkgbuild)+"&&makechrootpkg -c -D "+conf.Basedir.Makepkg+" -l worker-"+strconv.Itoa(id)+" -r "+conf.Basedir.Chroot+" -- "+ - "--config "+filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s.conf", pkg.March))) + "--config "+filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf(makepkgFile, pkg.March))) var out bytes.Buffer cmd.Stdout = &out cmd.Stderr = &out diff --git a/utils.go b/utils.go index 1bf298e..649e634 100644 --- a/utils.go +++ b/utils.go @@ -83,6 +83,7 @@ type Conf struct { Blacklist struct { Packages []string Repo []string + LTO []string `yaml:"lto"` } } @@ -584,7 +585,10 @@ func syncMarchs() { } for _, march := range conf.March { - setupMakepkg(march) + err := setupMakepkg(march) + if err != nil { + log.Errorf("Can't generate makepkg for %s: %v", march, err) + } for _, repo := range conf.Repos { fRepo := fmt.Sprintf("%s-%s", repo, march) repos = append(repos, fRepo) @@ -612,28 +616,47 @@ func syncMarchs() { } //goland:noinspection SpellCheckingInspection -func setupMakepkg(march string) { +func setupMakepkg(march string) error { lMakepkg := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s.conf", march)) + lMakepkgLTO := filepath.Join(conf.Basedir.Makepkg, fmt.Sprintf("makepkg-%s-lto.conf", march)) - check(os.MkdirAll(conf.Basedir.Makepkg, 0755)) + err := os.MkdirAll(conf.Basedir.Makepkg, 0755) + if err != nil { + return err + } t, err := os.ReadFile(makepkgConf) - check(err) + if err != nil { + return err + } makepkgStr := string(t) makepkgStr = strings.ReplaceAll(makepkgStr, "-mtune=generic", "") - makepkgStr = strings.ReplaceAll(makepkgStr, "!lto", "") - // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3 -falign-functions=32") makepkgStr = strings.ReplaceAll(makepkgStr, " check ", " !check ") makepkgStr = strings.ReplaceAll(makepkgStr, " color ", " !color ") - // Add LTO. Since it's (!lto) not in devtools yet, add it instead. - // See https://git.harting.dev/anonfunc/ALHP.GO/issues/52 for more - makepkgStr = strings.ReplaceAll(makepkgStr, "!debug", "!debug lto") - + makepkgStr = strings.ReplaceAll(makepkgStr, "-O2", "-O3") makepkgStr = strings.ReplaceAll(makepkgStr, "#MAKEFLAGS=\"-j2\"", "MAKEFLAGS=\"-j"+strconv.Itoa(conf.Build.Makej)+"\"") makepkgStr = reMarch.ReplaceAllString(makepkgStr, "${1}"+march) - check(os.WriteFile(lMakepkg, []byte(makepkgStr), 0644)) + // write non-lto makepkg + err = os.WriteFile(lMakepkg, []byte(makepkgStr), 0644) + if err != nil { + return err + } + + // Add LTO. Since (lto) not in devtools yet, add it instead. + // See https://git.harting.dev/anonfunc/ALHP.GO/issues/52 for more + makepkgStr = strings.ReplaceAll(makepkgStr, "!lto", "") + makepkgStr = strings.ReplaceAll(makepkgStr, "!debug", "!debug lto") + // Add align-functions=32, see https://github.com/InBetweenNames/gentooLTO/issues/164 for more + makepkgStr = strings.ReplaceAll(makepkgStr, "-O3", "-O3 -falign-functions=32") + + // write lto makepkg + err = os.WriteFile(lMakepkgLTO, []byte(makepkgStr), 0644) + if err != nil { + return err + } + + return nil } func isMirrorLatest(h *alpm.Handle, buildPkg *BuildPackage) (bool, alpm.IPackage, string, error) {