Skip to content

Commit

Permalink
add option to specify go -compiler, e.g. tinygo see u-root/gobusybox#121
Browse files Browse the repository at this point in the history
  • Loading branch information
archie2x committed Aug 6, 2024
1 parent 899a47e commit 81690d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions uimage/mkuimage/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 10 additions & 3 deletions uimage/mkuimage/uflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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),
Expand Down

0 comments on commit 81690d3

Please sign in to comment.