From 81690d32539d01b83124981e43a6e8f087a99d60 Mon Sep 17 00:00:00 2001 From: Roger Standridge <9526806+archie2x@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:45:00 -0700 Subject: [PATCH] add option to specify go -compiler, e.g. tinygo see u-root/gobusybox#121 --- uimage/mkuimage/cmd.go | 3 +++ uimage/mkuimage/uflags.go | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/uimage/mkuimage/cmd.go b/uimage/mkuimage/cmd.go index ecfb99b..e3a77ba 100644 --- a/uimage/mkuimage/cmd.go +++ b/uimage/mkuimage/cmd.go @@ -100,6 +100,9 @@ func CreateUimage(l *llog.Logger, base []uimage.Modifier, tf *TemplateFlags, f * l.Infof("Could not get environment's Go version, using runtime's version: %v", err) v = runtime.Version() } + if len(env.Compiler.VersionOutput) != 0 { + l.Infof("Compiler: %v", env.Compiler.VersionOutput) + } if !isRecommendedVersion(v) { l.Warnf(`You are not using one of the recommended Go versions (have = %s, recommended = %v). Some packages may not compile. diff --git a/uimage/mkuimage/uflags.go b/uimage/mkuimage/uflags.go index 100003d..8687c59 100644 --- a/uimage/mkuimage/uflags.go +++ b/uimage/mkuimage/uflags.go @@ -42,6 +42,7 @@ type CommandFlags struct { Mod golang.ModBehavior BuildTags []string BuildOpts *golang.BuildOpts + Compiler string } // RegisterFlags registers flags related to Go commands being built. @@ -61,6 +62,8 @@ func (c *CommandFlags) RegisterFlags(f *flag.FlagSet) { // Register an alias for -go-build-tags for backwards compatibility. f.Var((*uflag.Strings)(&c.BuildTags), "tags", "Go build tags -- repeat the flag for multiple values") f.Var((*uflag.Strings)(&c.BuildTags), "go-build-tags", "Go build tags -- repeat the flag for multiple values") + f.StringVar((*string)(&c.Compiler), "compiler", "", "override go compiler to use (e.g. \"/path/to/tinygo\")") + } // Modifiers turns the flag values into uimage modifiers. @@ -77,9 +80,13 @@ func (c *CommandFlags) Modifiers(packages ...string) ([]uimage.Modifier, error) switch c.Builder { case "bb", "gbb": return []uimage.Modifier{ - uimage.WithEnv(golang.WithBuildTag(c.BuildTags...), func(e *golang.Environ) { - e.Mod = c.Mod - }), + uimage.WithEnv( + golang.WithBuildTag(c.BuildTags...), + golang.WithCompiler(c.Compiler), + func(e *golang.Environ) { + e.Mod = c.Mod + }, + ), uimage.WithBusyboxCommands(packages...), uimage.WithShellBang(c.ShellBang), uimage.WithBusyboxBuildOpts(c.BuildOpts),