Skip to content

Commit

Permalink
pkg/build/linux: support building with a custom make binary
Browse files Browse the repository at this point in the history
Certain environments might need a specific make command or wrap make
calls with extra logic. This lets users provide a path to a custom make
binary.
  • Loading branch information
FlorentRevest committed Oct 2, 2024
1 parent ea2b66a commit 377a0ea
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pkg/bisect/bisect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
Fix bool
DefaultCompiler string
CompilerType string
Make string
Linker string
BinDir string
Ccache string
Expand Down Expand Up @@ -612,6 +613,7 @@ func (env *env) build() (*vcs.Commit, string, error) {
kern := &env.cfg.Kernel
_, imageDetails, err := env.inst.BuildKernel(&instance.BuildKernelConfig{
CompilerBin: bisectEnv.Compiler,
MakeBin: env.cfg.Make,
LinkerBin: env.cfg.Linker,
CcacheBin: env.cfg.Ccache,
UserspaceDir: kern.Userspace,
Expand Down
1 change: 1 addition & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Params struct {
KernelDir string
OutputDir string
Compiler string
Make string
Linker string
Ccache string
UserspaceDir string
Expand Down
13 changes: 8 additions & 5 deletions pkg/build/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (linux) createImage(params Params, kernelPath string) error {
}

func (linux) clean(kernelDir, targetArch string) error {
return runMakeImpl(targetArch, "", "", "", kernelDir, runtime.NumCPU(), []string{"distclean"})
return runMakeImpl(targetArch, "", "", "", "", kernelDir, runtime.NumCPU(), []string{"distclean"})
}

func (linux) writeFile(file string, data []byte) error {
Expand All @@ -152,11 +152,14 @@ func (linux) writeFile(file string, data []byte) error {
return osutil.SandboxChown(file)
}

func runMakeImpl(arch, compiler, linker, ccache, kernelDir string, jobs int, extraArgs []string) error {
func runMakeImpl(arch, compiler, linker, ccache, make, kernelDir string, jobs int, extraArgs []string) error {
target := targets.Get(targets.Linux, arch)
args := LinuxMakeArgs(target, compiler, linker, ccache, "", jobs)
args = append(args, extraArgs...)
cmd := osutil.Command("make", args...)
if make == "" {
make = "make"
}
cmd := osutil.Command(make, args...)
if err := osutil.Sandbox(cmd, true, true); err != nil {
return err
}
Expand All @@ -179,8 +182,8 @@ func runMakeImpl(arch, compiler, linker, ccache, kernelDir string, jobs int, ext
}

func runMake(params Params, extraArgs ...string) error {
return runMakeImpl(params.TargetArch, params.Compiler, params.Linker, params.Ccache,
params.KernelDir, params.BuildCPUs, extraArgs)
return runMakeImpl(params.TargetArch, params.Compiler, params.Linker,
params.Ccache, params.Make, params.KernelDir, params.BuildCPUs, extraArgs)
}

func LinuxMakeArgs(target *targets.Target, compiler, linker, ccache, buildDir string, jobs int) []string {
Expand Down
2 changes: 2 additions & 0 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type env struct {
}

type BuildKernelConfig struct {
MakeBin string
CompilerBin string
LinkerBin string
CcacheBin string
Expand Down Expand Up @@ -147,6 +148,7 @@ func (env *env) BuildKernel(buildCfg *BuildKernelConfig) (
VMType: env.cfg.Type,
KernelDir: env.cfg.KernelSrc,
OutputDir: imageDir,
Make: buildCfg.MakeBin,
Compiler: buildCfg.CompilerBin,
Linker: buildCfg.LinkerBin,
Ccache: buildCfg.CcacheBin,
Expand Down
1 change: 1 addition & 0 deletions syz-ci/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func (jp *JobProcessor) testPatch(job *Job, mgrcfg *mgrconfig.Config) error {
log.Logf(0, "job: building kernel...")
kernelConfig, details, err := env.BuildKernel(&instance.BuildKernelConfig{
CompilerBin: mgr.mgrcfg.Compiler,
MakeBin: mgr.mgrcfg.Make,
LinkerBin: mgr.mgrcfg.Linker,
CcacheBin: mgr.mgrcfg.Ccache,
UserspaceDir: mgr.mgrcfg.Userspace,
Expand Down
1 change: 1 addition & 0 deletions syz-ci/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (mgr *Manager) build(kernelCommit *vcs.Commit) error {
VMType: mgr.managercfg.Type,
KernelDir: mgr.kernelBuildDir,
OutputDir: tmpDir,
Make: mgr.mgrcfg.Make,
Compiler: mgr.mgrcfg.Compiler,
Linker: mgr.mgrcfg.Linker,
Ccache: mgr.mgrcfg.Ccache,
Expand Down
1 change: 1 addition & 0 deletions syz-ci/syz-ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type ManagerConfig struct {
// explicit plumbing for every os/compiler combination.
CompilerType string `json:"compiler_type"` // Defaults to "gcc"
Compiler string `json:"compiler"`
Make string `json:"make"`
Linker string `json:"linker"`
Ccache string `json:"ccache"`
Userspace string `json:"userspace"`
Expand Down
4 changes: 3 additions & 1 deletion tools/syz-build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var (
flagArch = flag.String("arch", runtime.GOARCH, "arch to build")
flagVM = flag.String("vm", "gce", "VM type to build")
flagKernelSrc = flag.String("kernel_src", "", "path to kernel checkout")
flagCompiler = flag.String("compiler", "", "non-defult compiler")
flagMake = flag.String("make", "", "non-default make")
flagCompiler = flag.String("compiler", "", "non-default compiler")
flagLinker = flag.String("linker", "", "non-default linker")
flagKernelConfig = flag.String("config", "", "kernel config file")
flagKernelSysctl = flag.String("sysctl", "", "kernel sysctl file")
Expand Down Expand Up @@ -53,6 +54,7 @@ func main() {
VMType: *flagVM,
KernelDir: *flagKernelSrc,
OutputDir: wd,
Make: *flagMake,
Compiler: *flagCompiler,
Linker: *flagLinker,
Ccache: "",
Expand Down
3 changes: 2 additions & 1 deletion tools/syz-testbuild/testbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func main() {
}

func test(repo vcs.Repo, bisecter vcs.Bisecter, kernelConfig []byte, env instance.Env, com *vcs.Commit) {
compiler, compilerType, linker, ccache := "gcc", "gcc", "ld", ""
compiler, compilerType, linker, ccache, makeBin := "gcc", "gcc", "ld", "", "make"
bisectEnv, err := bisecter.EnvForCommit(compiler, compilerType, *flagBisectBin, com.Hash, kernelConfig, nil)
if err != nil {
tool.Fail(err)
Expand All @@ -136,6 +136,7 @@ func test(repo vcs.Repo, bisecter vcs.Bisecter, kernelConfig []byte, env instanc
}
_, _, err = env.BuildKernel(&instance.BuildKernelConfig{
CompilerBin: bisectEnv.Compiler,
MakeBin: makeBin,
LinkerBin: linker,
CcacheBin: ccache,
UserspaceDir: *flagUserspace,
Expand Down

0 comments on commit 377a0ea

Please sign in to comment.