builder

package
v0.0.0-...-899a47e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package builder has methods for building many Go commands into an initramfs archive.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Busybox is a shared GBBBuilder instance.
	Busybox = &GBBBuilder{}

	// Binary is a shared BinaryBuilder instance.
	Binary = &BinaryBuilder{}
)
View Source
var (
	ErrBusyboxFailed  = errors.New("gobusybox build failed")
	ErrBinaryFailed   = errors.New("binary build failed")
	ErrEnvMissing     = errors.New("must specify Go build environment")
	ErrTempDirMissing = errors.New("must supply temporary directory for build")
)

Possible build errors.

Functions

This section is empty.

Types

type BinaryBuilder

type BinaryBuilder struct{}

BinaryBuilder builds each Go command as a separate binary.

BinaryBuilder is an implementation of Builder.

func (BinaryBuilder) Build

func (b BinaryBuilder) Build(l *llog.Logger, af *initramfs.Files, opts Opts) error

Build implements Builder.Build.

func (BinaryBuilder) DefaultBinaryDir

func (BinaryBuilder) DefaultBinaryDir() string

DefaultBinaryDir implements Builder.DefaultBinaryDir.

"bin" is the default initramfs binary directory for these binaries.

type Builder

type Builder interface {
	// Build uses the given options to build Go packages and adds its files
	// to be included in the initramfs to the given ArchiveFiles.
	Build(*llog.Logger, *initramfs.Files, Opts) error

	// DefaultBinaryDir is the initramfs' default directory for binaries
	// built using this builder.
	DefaultBinaryDir() string
}

Builder builds Go packages and adds the binaries to an initramfs.

The resulting files need not be binaries per se, but exec'ing the resulting file should result in the Go program being executed.

type GBBBuilder

type GBBBuilder struct {
	// ShellBang means generate #! files instead of symlinks.
	// ShellBang are more portable and just as efficient.
	ShellBang bool
}

GBBBuilder is an implementation of Builder that compiles many Go commands into one busybox-style binary.

GBBBuilder will also include symlinks for each command to the busybox binary.

GBBBuilder does all this by rewriting the source files of the packages given to create one busybox-like binary containing all commands.

The compiled binary uses argv[0] to decide which Go command to run.

See bb/README.md for a detailed explanation of the implementation of busybox mode.

func (*GBBBuilder) Build

func (b *GBBBuilder) Build(l *llog.Logger, af *initramfs.Files, opts Opts) error

Build is an implementation of Builder.Build for a busybox-like initramfs.

func (GBBBuilder) DefaultBinaryDir

func (GBBBuilder) DefaultBinaryDir() string

DefaultBinaryDir implements Builder.DefaultBinaryDir.

The default initramfs binary dir is bbin for busybox binaries.

type Opts

type Opts struct {
	// Env is the Go compiler environment.
	Env *golang.Environ

	// Build options for building go binaries. Ultimate this holds all the
	// args that end up being passed to `go build`.
	BuildOpts *golang.BuildOpts

	// Packages are the Go packages to compile.
	//
	// Only an explicit list of absolute directory paths is accepted.
	Packages []string

	// TempDir is a temporary directory where the compilation mode compiled
	// binaries can be placed.
	//
	// TempDir should contain no files.
	TempDir string

	// BinaryDir is the initramfs directory for built binaries.
	//
	// BinaryDir must be specified.
	BinaryDir string
}

Opts are options passed to the Builder.Build function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL