switched to KCFLAGS/KCPPFLAGS to build kernels instead of patching

This commit is contained in:
Giovanni Harting 2023-05-16 02:53:04 +02:00
parent e0a4e0031b
commit 57acc40a56
3 changed files with 2 additions and 118 deletions

View File

@ -8,19 +8,6 @@ svn2git:
upstream-core-extra: "https://github.com/archlinux/svntogit-packages.git"
upstream-community: "https://github.com/archlinux/svntogit-community.git"
kernel_to_patch:
- linux
- linux-lts
- linux-zen
- linux-hardened
kernel_patches:
4.19: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-4.19-5.4.patch"
5.5: "none"
5.8: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-5.8-5.14.patch"
5.15: "https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master/more-uarches-for-kernel-5.15%2B.patch"
linux-zen: "skip"
db:
driver: pgx
connect_to: "postgres://username:password@localhost:5432/database_name"

View File

@ -23,6 +23,8 @@ common:
rustflags: "-Copt-level=3 -Ctarget-cpu=$march$"
ltoflags:
- "-falign-functions=32" # https://github.com/InBetweenNames/gentooLTO/issues/164
kcflags: " -march=$march$ -O3"
kcppflags: " -march=$march$ -O3"
lto:
rustflags:

View File

@ -3,8 +3,6 @@ package main
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"github.com/Jguer/go-alpm/v2"
@ -14,7 +12,6 @@ import (
"github.com/otiai10/copy"
log "github.com/sirupsen/logrus"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
@ -198,14 +195,6 @@ 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) {
err = p.prepareKernelPatches()
if err != nil {
p.DBPackage.Update().SetStatus(dbpackage.StatusFailed).SetSkipReason("failed to apply patch").SetHash(p.Hash).ExecX(ctx)
return time.Since(start), fmt.Errorf("error modifying PKGBUILD for kernel patch: %w", err)
}
}
p.PkgFiles = []string{}
// default to LTO
@ -431,100 +420,6 @@ func (p *ProtoPackage) increasePkgRel(buildNo int) error {
return nil
}
func (p *ProtoPackage) prepareKernelPatches() error {
f, err := os.OpenFile(p.Pkgbuild, os.O_RDWR, 0o644)
if err != nil {
return err
}
defer func(f *os.File) {
err := f.Close()
if err != nil {
panic(err)
}
}(f)
fStr, err := io.ReadAll(f)
if err != nil {
return err
}
// choose best suited patch based on kernel version
var curVer string
for k := range conf.KernelPatches {
if k == p.Pkgbase {
curVer = k
break
}
if alpm.VerCmp(p.Srcinfo.Pkgver, k) >= 0 && alpm.VerCmp(k, curVer) >= 0 {
curVer = k
}
}
newPKGBUILD := string(fStr)
switch {
case conf.KernelPatches[curVer] == "none":
return fmt.Errorf("no patch available")
case conf.KernelPatches[curVer] == "skip":
log.Debugf("[KP] skipped patching for %s", p.Pkgbase)
default:
log.Debugf("[KP] choose patch %s for kernel %s", curVer, p.Srcinfo.Pkgver)
orgSource := rePkgSource.FindStringSubmatch(newPKGBUILD)
if orgSource == nil || len(orgSource) < 1 {
return fmt.Errorf("no source=() found")
}
sources := strings.Split(orgSource[1], "\n")
sources = append(sources, fmt.Sprintf("%q", conf.KernelPatches[curVer]))
newPKGBUILD = rePkgSource.ReplaceAllLiteralString(newPKGBUILD, fmt.Sprintf("source=(%s)", strings.Join(sources, "\n")))
resp, err := http.Get(conf.KernelPatches[curVer]) //nolint:bodyclose,noctx
if err != nil || resp.StatusCode != 200 {
return err
}
h := sha256.New()
_, err = io.Copy(h, resp.Body)
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
if err != nil {
return err
}
orgSums := rePkgSum.FindStringSubmatch(newPKGBUILD)
if orgSums == nil || len(orgSums) < 1 {
return fmt.Errorf("no sha256sums=() found")
}
sums := strings.Split(orgSums[1], "\n")
sums = append(sums, fmt.Sprintf("'%s'", hex.EncodeToString(h.Sum(nil))))
newPKGBUILD = rePkgSum.ReplaceAllLiteralString(newPKGBUILD, fmt.Sprintf("sha256sums=(\n%s\n)", strings.Join(sums, "\n")))
}
// enable config option
switch {
case strings.Contains(p.March, "v4"):
newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU4=y >> .config\nmake olddefconfig\n", 1)
case strings.Contains(p.March, "v3"):
newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU3=y >> .config\nmake olddefconfig\n", 1)
case strings.Contains(p.March, "v2"):
newPKGBUILD = strings.Replace(newPKGBUILD, "make olddefconfig\n", "echo CONFIG_GENERIC_CPU2=y >> .config\nmake olddefconfig\n", 1)
}
// empty file before writing
_, err = f.Seek(0, 0)
if err != nil {
return err
}
err = f.Truncate(0)
if err != nil {
return err
}
_, err = f.WriteString(newPKGBUILD)
if err != nil {
return err
}
return nil
}
func (p *ProtoPackage) importKeys() error {
if p.Srcinfo == nil {
err := p.genSrcinfo()