github.com/andrewsun2898/u-root@v6.0.1-0.20200616011413-4b2895c1b815+incompatible/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 "github.com/u-root/u-root/pkg/golang" 9 "github.com/u-root/u-root/pkg/uroot/initramfs" 10 ) 11 12 var ( 13 BusyBox = BBBuilder{} 14 Source = SourceBuilder{} 15 Binary = BinaryBuilder{} 16 ) 17 18 // Opts are options passed to the Builder.Build function. 19 type Opts struct { 20 // Env is the Go compiler environment. 21 Env golang.Environ 22 23 // Packages are the Go packages to compile. 24 // 25 // Only an explicit list of Go import paths is accepted. 26 // 27 // E.g. cmd/go or github.com/u-root/u-root/cmds/ls. 28 Packages []string 29 30 // TempDir is a temporary directory where the compilation mode compiled 31 // binaries can be placed. 32 // 33 // TempDir should contain no files. 34 TempDir string 35 36 // BinaryDir is the initramfs directory for built binaries. 37 // 38 // BinaryDir must be specified. 39 BinaryDir string 40 } 41 42 // Builder builds Go packages and adds the binaries to an initramfs. 43 // 44 // The resulting files need not be binaries per se, but exec'ing the resulting 45 // file should result in the Go program being executed. 46 type Builder interface { 47 // Build uses the given options to build Go packages and adds its files 48 // to be included in the initramfs to the given ArchiveFiles. 49 Build(*initramfs.Files, Opts) error 50 51 // DefaultBinaryDir is the initramfs' default directory for binaries 52 // built using this builder. 53 DefaultBinaryDir() string 54 }