From 8db4a3cdb1d75a1355007f5df32b2c1bade91c2b Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Thu, 7 Mar 2024 16:21:50 +0100 Subject: [PATCH] chore(pkg/driverbuiler): avoid overriding `CC` at build time. Instead, set CMAKE_C_COMPILER variable at cmake configure step. Signed-off-by: Federico Di Pierro --- pkg/driverbuilder/builder/builders.go | 4 ++-- pkg/driverbuilder/builder/local.go | 4 +++- pkg/driverbuilder/builder/templates/alinux.sh | 2 +- pkg/driverbuilder/builder/templates/almalinux.sh | 2 +- pkg/driverbuilder/builder/templates/amazonlinux.sh | 2 +- pkg/driverbuilder/builder/templates/archlinux.sh | 2 +- pkg/driverbuilder/builder/templates/centos.sh | 2 +- pkg/driverbuilder/builder/templates/debian.sh | 2 +- pkg/driverbuilder/builder/templates/fedora.sh | 2 +- pkg/driverbuilder/builder/templates/flatcar.sh | 2 +- pkg/driverbuilder/builder/templates/local.sh | 6 +++--- pkg/driverbuilder/builder/templates/opensuse.sh | 2 +- pkg/driverbuilder/builder/templates/oracle.sh | 2 +- pkg/driverbuilder/builder/templates/photonos.sh | 2 +- pkg/driverbuilder/builder/templates/redhat.sh | 2 +- pkg/driverbuilder/builder/templates/rocky.sh | 2 +- pkg/driverbuilder/builder/templates/sles.sh | 2 +- pkg/driverbuilder/builder/templates/ubuntu.sh | 2 +- pkg/driverbuilder/builder/templates/vanilla.sh | 2 +- 19 files changed, 24 insertions(+), 22 deletions(-) diff --git a/pkg/driverbuilder/builder/builders.go b/pkg/driverbuilder/builder/builders.go index 36a24cb2..730c7c8e 100644 --- a/pkg/driverbuilder/builder/builders.go +++ b/pkg/driverbuilder/builder/builders.go @@ -47,6 +47,7 @@ const ( -DGIT_COMMIT=%s \ -DDRIVER_DEVICE_NAME=%s \ -DPROBE_DEVICE_NAME=%s \ + -DCMAKE_C_COMPILER=%s \ .. && \ sed -i s/'DRIVER_COMMIT ""'/'DRIVER_COMMIT "%s"'/g driver/src/driver_config.h` ) @@ -76,7 +77,6 @@ type commonTemplateData struct { ModuleFullPath string BuildModule bool BuildProbe bool - GCCVersion string CmakeCmd string } @@ -311,7 +311,6 @@ func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) common ModuleFullPath: c.ToDriverFullPath(), BuildModule: len(c.ModuleFilePath) > 0, BuildProbe: len(c.ProbeFilePath) > 0, - GCCVersion: c.GCCVersion, CmakeCmd: fmt.Sprintf(cmakeCmdFmt, c.DriverName, c.DriverName, @@ -320,6 +319,7 @@ func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) common c.DriverVersion, c.DeviceName, c.DeviceName, + "/usr/bin/gcc-"+c.GCCVersion, c.DriverVersion), } } diff --git a/pkg/driverbuilder/builder/local.go b/pkg/driverbuilder/builder/local.go index 95d7e0ab..1ecdaa1b 100644 --- a/pkg/driverbuilder/builder/local.go +++ b/pkg/driverbuilder/builder/local.go @@ -43,6 +43,7 @@ type localTemplateData struct { DownloadSrc bool DriverVersion string KernelRelease string + GCCPath string } func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _ []string) interface{} { @@ -54,7 +55,6 @@ func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _ ModuleFullPath: l.GetModuleFullPath(c, kr), BuildModule: len(c.ModuleFilePath) > 0, BuildProbe: len(c.ProbeFilePath) > 0, - GCCVersion: l.GccPath, CmakeCmd: fmt.Sprintf(cmakeCmdFmt, c.DriverName, c.DriverName, @@ -63,12 +63,14 @@ func (l *LocalBuilder) TemplateData(c Config, kr kernelrelease.KernelRelease, _ c.DriverVersion, c.DeviceName, c.DeviceName, + l.GccPath, c.DriverVersion), }, UseDKMS: l.UseDKMS, DownloadSrc: len(l.SrcDir) == 0, // if no srcdir is provided, download src! DriverVersion: c.DriverVersion, KernelRelease: c.KernelRelease, + GCCPath: l.GccPath, } } diff --git a/pkg/driverbuilder/builder/templates/alinux.sh b/pkg/driverbuilder/builder/templates/alinux.sh index 07b84717..391ae6bd 100644 --- a/pkg/driverbuilder/builder/templates/alinux.sh +++ b/pkg/driverbuilder/builder/templates/alinux.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/almalinux.sh b/pkg/driverbuilder/builder/templates/almalinux.sh index 07b84717..391ae6bd 100644 --- a/pkg/driverbuilder/builder/templates/almalinux.sh +++ b/pkg/driverbuilder/builder/templates/almalinux.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/amazonlinux.sh b/pkg/driverbuilder/builder/templates/amazonlinux.sh index 13818b87..9cf8d41e 100644 --- a/pkg/driverbuilder/builder/templates/amazonlinux.sh +++ b/pkg/driverbuilder/builder/templates/amazonlinux.sh @@ -48,7 +48,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel LD=/usr/bin/ld.bfd CROSS_COMPILE="" driver +make KERNELDIR=/tmp/kernel LD=/usr/bin/ld.bfd CROSS_COMPILE="" driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/archlinux.sh b/pkg/driverbuilder/builder/templates/archlinux.sh index 90c53e1c..f15ccfef 100644 --- a/pkg/driverbuilder/builder/templates/archlinux.sh +++ b/pkg/driverbuilder/builder/templates/archlinux.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/centos.sh b/pkg/driverbuilder/builder/templates/centos.sh index ed85ad52..30ac3bac 100644 --- a/pkg/driverbuilder/builder/templates/centos.sh +++ b/pkg/driverbuilder/builder/templates/centos.sh @@ -46,7 +46,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/debian.sh b/pkg/driverbuilder/builder/templates/debian.sh index dbcd1d4e..c0a14e5f 100644 --- a/pkg/driverbuilder/builder/templates/debian.sh +++ b/pkg/driverbuilder/builder/templates/debian.sh @@ -53,7 +53,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver +make KERNELDIR=$sourcedir driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/fedora.sh b/pkg/driverbuilder/builder/templates/fedora.sh index 07b84717..391ae6bd 100644 --- a/pkg/driverbuilder/builder/templates/fedora.sh +++ b/pkg/driverbuilder/builder/templates/fedora.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/flatcar.sh b/pkg/driverbuilder/builder/templates/flatcar.sh index a9c8edf6..adef3298 100644 --- a/pkg/driverbuilder/builder/templates/flatcar.sh +++ b/pkg/driverbuilder/builder/templates/flatcar.sh @@ -52,7 +52,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/local.sh b/pkg/driverbuilder/builder/templates/local.sh index f23b10a1..15500a34 100644 --- a/pkg/driverbuilder/builder/templates/local.sh +++ b/pkg/driverbuilder/builder/templates/local.sh @@ -48,7 +48,7 @@ mkdir -p build && cd build echo "* Building kmod with DKMS" # Build the module using DKMS echo "#!/usr/bin/env bash" > "/tmp/falco-dkms-make" -echo "make CC={{ .GCCVersion }} \$@" >> "/tmp/falco-dkms-make" +echo "make CC={{ .GCCPath }} \$@" >> "/tmp/falco-dkms-make" chmod +x "/tmp/falco-dkms-make" dkms install --directive="MAKE='/tmp/falco-dkms-make'" -m "{{ .ModuleDriverName }}" -v "{{ .DriverVersion }}" -k "{{ .KernelRelease }}" rm -Rf "/tmp/falco-dkms-make" @@ -56,10 +56,10 @@ rm -Rf "/tmp/falco-dkms-make" echo "* Building kmod" {{ if .DownloadSrc }} # Build the module - cmake configured -make CC={{ .GCCVersion }} driver +make driver {{ else }} # Build the module - preconfigured sources -make CC={{ .GCCVersion }} +make CC={{ .GCCPath }} {{ end }} strip -g {{ .ModuleFullPath }} # Print results diff --git a/pkg/driverbuilder/builder/templates/opensuse.sh b/pkg/driverbuilder/builder/templates/opensuse.sh index 1874f2cc..c831c752 100644 --- a/pkg/driverbuilder/builder/templates/opensuse.sh +++ b/pkg/driverbuilder/builder/templates/opensuse.sh @@ -48,7 +48,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver +make KERNELDIR=$sourcedir driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/oracle.sh b/pkg/driverbuilder/builder/templates/oracle.sh index 07b84717..391ae6bd 100644 --- a/pkg/driverbuilder/builder/templates/oracle.sh +++ b/pkg/driverbuilder/builder/templates/oracle.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/photonos.sh b/pkg/driverbuilder/builder/templates/photonos.sh index f83d4209..61e8f7b2 100644 --- a/pkg/driverbuilder/builder/templates/photonos.sh +++ b/pkg/driverbuilder/builder/templates/photonos.sh @@ -48,7 +48,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/redhat.sh b/pkg/driverbuilder/builder/templates/redhat.sh index dbbfc06b..8fcfe2fc 100644 --- a/pkg/driverbuilder/builder/templates/redhat.sh +++ b/pkg/driverbuilder/builder/templates/redhat.sh @@ -47,7 +47,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/rocky.sh b/pkg/driverbuilder/builder/templates/rocky.sh index 07b84717..391ae6bd 100644 --- a/pkg/driverbuilder/builder/templates/rocky.sh +++ b/pkg/driverbuilder/builder/templates/rocky.sh @@ -45,7 +45,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/sles.sh b/pkg/driverbuilder/builder/templates/sles.sh index d784dfcd..22cb608d 100644 --- a/pkg/driverbuilder/builder/templates/sles.sh +++ b/pkg/driverbuilder/builder/templates/sles.sh @@ -50,7 +50,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver +make KERNELDIR=$sourcedir driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/ubuntu.sh b/pkg/driverbuilder/builder/templates/ubuntu.sh index e784a8ad..57fa5dde 100644 --- a/pkg/driverbuilder/builder/templates/ubuntu.sh +++ b/pkg/driverbuilder/builder/templates/ubuntu.sh @@ -49,7 +49,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=$sourcedir driver +make KERNELDIR=$sourcedir driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }} diff --git a/pkg/driverbuilder/builder/templates/vanilla.sh b/pkg/driverbuilder/builder/templates/vanilla.sh index 64085553..8a723309 100644 --- a/pkg/driverbuilder/builder/templates/vanilla.sh +++ b/pkg/driverbuilder/builder/templates/vanilla.sh @@ -62,7 +62,7 @@ mkdir -p build && cd build {{ if .BuildModule }} # Build the module -make CC=/usr/bin/gcc-{{ .GCCVersion }} KERNELDIR=/tmp/kernel driver +make KERNELDIR=/tmp/kernel driver strip -g {{ .ModuleFullPath }} # Print results modinfo {{ .ModuleFullPath }}