github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/uroot/builder/builder.go (about)

     1  // Copyright 2015-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package builder
     6  
     7  import (
     8  	gbbgolang "github.com/u-root/gobusybox/src/pkg/golang"
     9  	"github.com/mvdan/u-root-coreutils/pkg/ulog"
    10  	"github.com/mvdan/u-root-coreutils/pkg/uroot/initramfs"
    11  )
    12  
    13  var (
    14  	// BusyBox is a shared GBBBuilder instance.
    15  	BusyBox = GBBBuilder{}
    16  	// Binary is a shared BinaryBuilder instance.
    17  	Binary = BinaryBuilder{}
    18  )
    19  
    20  // Opts are options passed to the Builder.Build function.
    21  type Opts struct {
    22  	// Env is the Go compiler environment.
    23  	Env gbbgolang.Environ
    24  
    25  	// Build options for building go binaries. Ultimate this holds all the
    26  	// args that end up being passed to `go build`.
    27  	BuildOpts *gbbgolang.BuildOpts
    28  
    29  	// Packages are the Go packages to compile.
    30  	//
    31  	// Only an explicit list of absolute directory paths is accepted.
    32  	Packages []string
    33  
    34  	// TempDir is a temporary directory where the compilation mode compiled
    35  	// binaries can be placed.
    36  	//
    37  	// TempDir should contain no files.
    38  	TempDir string
    39  
    40  	// BinaryDir is the initramfs directory for built binaries.
    41  	//
    42  	// BinaryDir must be specified.
    43  	BinaryDir string
    44  }
    45  
    46  // Builder builds Go packages and adds the binaries to an initramfs.
    47  //
    48  // The resulting files need not be binaries per se, but exec'ing the resulting
    49  // file should result in the Go program being executed.
    50  type Builder interface {
    51  	// Build uses the given options to build Go packages and adds its files
    52  	// to be included in the initramfs to the given ArchiveFiles.
    53  	Build(ulog.Logger, *initramfs.Files, Opts) error
    54  
    55  	// DefaultBinaryDir is the initramfs' default directory for binaries
    56  	// built using this builder.
    57  	DefaultBinaryDir() string
    58  }