Skip to content

Commit

Permalink
Provide standard flag to set build tags
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Jul 26, 2023
1 parent aa1ef2e commit 5af97a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cmd/makebb/makebb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var (
func main() {
bopts := &golang.BuildOpts{}
bopts.RegisterFlags(flag.CommandLine)
env := golang.Default()
env.RegisterFlags(flag.CommandLine)
flag.Parse()

// Why doesn't the log package export this as a default?
Expand All @@ -36,7 +38,6 @@ func main() {
l.Fatal(err)
}

env := golang.Default()
if env.CgoEnabled {
l.Printf("Disabling CGO for u-root...")
env.CgoEnabled = false
Expand Down
8 changes: 7 additions & 1 deletion src/pkg/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ type Environ struct {
GBBDEBUG bool
}

// RegisterFlags registers flags for Environ.
func (c *Environ) RegisterFlags(f *flag.FlagSet) {
arg := (*uflag.Strings)(&c.BuildTags)
f.Var(arg, "go-build-tags", "Go build tags")
}

// Valid returns an error if GOARCH, GOROOT, or GOOS are unset.
func (c Environ) Valid() error {
if c.GOARCH == "" && c.GOROOT == "" && c.GOOS == "" {
Expand Down Expand Up @@ -167,7 +173,7 @@ func (b *BuildOpts) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&b.EnableInlining, "go-enable-inlining", false, "Enable inlining (will likely produce a larger binary)")
f.BoolVar(&b.NoTrimPath, "go-no-trimpath", false, "Disable -trimpath (will not produce a reproducible binary)")
arg := (*uflag.Strings)(&b.ExtraArgs)
f.Var(arg, "go-extra-args", "Extra args to `go build`")
f.Var(arg, "go-extra-args", "Extra args to 'go build'")
}

// BuildDir compiles the package in the directory `dirPath`, writing the build
Expand Down

0 comments on commit 5af97a4

Please sign in to comment.