From 5d444cd6dd19af26e21feb55d255c88c2a4ff9e8 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 4 Apr 2021 13:42:48 +1000 Subject: [PATCH] Support user tags --- v2/cmd/wails/internal/commands/build/build.go | 16 ++++++++++++++++ v2/pkg/commands/build/base.go | 3 ++- v2/pkg/commands/build/build.go | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index 0300b36fd..ea9eddeb6 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -54,6 +54,10 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { ldflags := "" command.StringFlag("ldflags", "optional ldflags", &ldflags) + // tags to pass to `go` + tags := "" + command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &tags) + // Log to file //logFile := "" //command.StringFlag("l", "Log to file", &logFile) @@ -121,6 +125,16 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { println("Warning: compress flag unsupported for universal binaries. Ignoring.") compress = false } + + // Tags + userTags := []string{} + for _, tag := range strings.Split(tags, " ") { + thisTag := strings.TrimSpace(tag) + if thisTag != "" { + userTags = append(userTags, thisTag) + } + } + // Create BuildOptions buildOptions := &build.Options{ Logger: logger, @@ -135,6 +149,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { AppleIdentity: appleIdentity, Verbosity: verbosity, Compress: compress, + UserTags: userTags, } // Calculate platform and arch @@ -166,6 +181,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { fmt.Fprintf(w, "Clean Build Dir: \t%t\n", buildOptions.CleanBuildDirectory) fmt.Fprintf(w, "KeepAssets: \t%t\n", buildOptions.KeepAssets) fmt.Fprintf(w, "LDFlags: \t\"%s\"\n", buildOptions.LDFlags) + fmt.Fprintf(w, "Tags: \t[%s]\n", strings.Join(buildOptions.UserTags, ",")) if len(buildOptions.OutputFile) > 0 { fmt.Fprintf(w, "Output File: \t%s\n", buildOptions.OutputFile) } diff --git a/v2/pkg/commands/build/base.go b/v2/pkg/commands/build/base.go index fb4b3aa94..375079c9e 100644 --- a/v2/pkg/commands/build/base.go +++ b/v2/pkg/commands/build/base.go @@ -190,10 +190,11 @@ func (b *BaseBuilder) CompileProject(options *Options) error { var tags slicer.StringSlicer tags.Add(options.OutputType) - + tags.AddSlice(options.UserTags) if options.Mode == Debug { tags.Add("debug") } + tags.Deduplicate() // Add the output type build tag commands.Add("-tags") diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index 2937e5a87..aaf917a11 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -29,6 +29,7 @@ var modeMap = []string{"Debug", "Production"} // Options contains all the build options as well as the project data type Options struct { LDFlags string // Optional flags to pass to linker + UserTags []string // Tags to pass to the Go compiler Logger *clilogger.CLILogger // All output to the logger OutputType string // EG: desktop, server.... Mode Mode // release or debug