From 946b6020c980036d20a9ff7949daa249ace4b2b6 Mon Sep 17 00:00:00 2001 From: Dmytro Manchynskyi Date: Sun, 17 Dec 2023 22:54:44 +0200 Subject: [PATCH] Fix -compiler flag for build, dev and generate commands (#3121) * Fix -compiler flag for build, dev and generate commands * Update changelog and docs --------- Co-authored-by: Lea Anthony --- v2/cmd/wails/flags/generate.go | 7 +++++++ v2/cmd/wails/generate.go | 1 + v2/cmd/wails/internal/dev/dev.go | 2 +- v2/pkg/commands/bindings/bindings.go | 5 +++-- v2/pkg/commands/bindings/bindings_test.go | 8 ++++++-- v2/pkg/commands/build/build.go | 1 + website/docs/reference/cli.mdx | 5 +++++ website/src/pages/changelog.mdx | 1 + 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/v2/cmd/wails/flags/generate.go b/v2/cmd/wails/flags/generate.go index 9adf78aa4..b14d67017 100644 --- a/v2/cmd/wails/flags/generate.go +++ b/v2/cmd/wails/flags/generate.go @@ -2,6 +2,7 @@ package flags type GenerateModule struct { Common + Compiler string `description:"Use a different go compiler to build, eg go1.15beta1"` Tags string `description:"Build tags to pass to Go compiler. Must be quoted. Space or comma (but not both) separated"` Verbosity int `name:"v" description:"Verbosity level (0 = quiet, 1 = normal, 2 = verbose)"` } @@ -12,3 +13,9 @@ type GenerateTemplate struct { Frontend string `description:"Frontend to use for the template"` Quiet bool `description:"Suppress output"` } + +func (c *GenerateModule) Default() *GenerateModule { + return &GenerateModule{ + Compiler: "go", + } +} diff --git a/v2/cmd/wails/generate.go b/v2/cmd/wails/generate.go index 052900519..15a6b33d8 100644 --- a/v2/cmd/wails/generate.go +++ b/v2/cmd/wails/generate.go @@ -48,6 +48,7 @@ func generateModule(f *flags.GenerateModule) error { } _, err = bindings.GenerateBindings(bindings.Options{ + Compiler: f.Compiler, Tags: buildTags, TsPrefix: projectConfig.Bindings.TsGeneration.Prefix, TsSuffix: projectConfig.Bindings.TsGeneration.Suffix, diff --git a/v2/cmd/wails/internal/dev/dev.go b/v2/cmd/wails/internal/dev/dev.go index 02ae79b18..58988bc82 100644 --- a/v2/cmd/wails/internal/dev/dev.go +++ b/v2/cmd/wails/internal/dev/dev.go @@ -61,7 +61,7 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error { } // Run go mod tidy to ensure we're up-to-date - err = runCommand(cwd, false, "go", "mod", "tidy") + err = runCommand(cwd, false, f.Compiler, "mod", "tidy") if err != nil { return err } diff --git a/v2/pkg/commands/bindings/bindings.go b/v2/pkg/commands/bindings/bindings.go index 6ed2a27ba..23d4d635c 100644 --- a/v2/pkg/commands/bindings/bindings.go +++ b/v2/pkg/commands/bindings/bindings.go @@ -18,6 +18,7 @@ type Options struct { Filename string Tags []string ProjectDirectory string + Compiler string GoModTidy bool TsPrefix string TsSuffix string @@ -46,13 +47,13 @@ func GenerateBindings(options Options) (string, error) { tagString := buildtags.Stringify(genModuleTags) if options.GoModTidy { - stdout, stderr, err = shell.RunCommand(workingDirectory, "go", "mod", "tidy") + stdout, stderr, err = shell.RunCommand(workingDirectory, options.Compiler, "mod", "tidy") if err != nil { return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err) } } - stdout, stderr, err = shell.RunCommand(workingDirectory, "go", "build", "-tags", tagString, "-o", filename) + stdout, stderr, err = shell.RunCommand(workingDirectory, options.Compiler, "build", "-tags", tagString, "-o", filename) if err != nil { return stdout, fmt.Errorf("%s\n%s\n%s", stdout, stderr, err) } diff --git a/v2/pkg/commands/bindings/bindings_test.go b/v2/pkg/commands/bindings/bindings_test.go index a2cbed436..53f42f2c7 100644 --- a/v2/pkg/commands/bindings/bindings_test.go +++ b/v2/pkg/commands/bindings/bindings_test.go @@ -1,13 +1,14 @@ package bindings import ( - "github.com/matryer/is" - "github.com/wailsapp/wails/v2/pkg/templates" "os" "path/filepath" "runtime" "strings" "testing" + + "github.com/matryer/is" + "github.com/wailsapp/wails/v2/pkg/templates" ) const standardBindings = `// @ts-check @@ -80,6 +81,7 @@ func TestGenerateBindings(t *testing.T) { name: "should generate standard bindings with no user tags", options: Options{ ProjectDirectory: projectDir, + Compiler: "go", GoModTidy: true, }, expectedBindings: standardBindings, @@ -90,6 +92,7 @@ func TestGenerateBindings(t *testing.T) { name: "should generate bindings when given tags", options: Options{ ProjectDirectory: projectDir, + Compiler: "go", Tags: []string{"test"}, GoModTidy: true, }, @@ -101,6 +104,7 @@ func TestGenerateBindings(t *testing.T) { name: "should generate obfuscated bindings", options: Options{ ProjectDirectory: projectDir, + Compiler: "go", Tags: []string{"obfuscated"}, GoModTidy: true, }, diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index c8522e412..a2b8ffcb2 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -229,6 +229,7 @@ func GenerateBindings(buildOptions *Options) error { // Generate Bindings output, err := bindings.GenerateBindings(bindings.Options{ + Compiler: buildOptions.Compiler, Tags: buildOptions.UserTags, GoModTidy: !buildOptions.SkipModTidy, TsPrefix: buildOptions.ProjectData.Bindings.TsGeneration.Prefix, diff --git a/website/docs/reference/cli.mdx b/website/docs/reference/cli.mdx index bbfe5bea4..dc8b3293f 100644 --- a/website/docs/reference/cli.mdx +++ b/website/docs/reference/cli.mdx @@ -231,6 +231,11 @@ For more details on creating templates, consult the [Templates guide](../guides/ The `wails generate module` command allows you to manually generate the `wailsjs` directory for your application. +| Flag | Description | Default | +|:---------------------|:------------------------------------------------------------|:--------| +| -compiler "compiler" | Use a different go compiler to build, eg go1.15beta1 | go | +| -tags "extra tags" | Build tags to pass to compiler (quoted and space separated) | | + ## update `wails update` will update the version of the Wails CLI. diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index bc923f072..f22628551 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Docs for IsZoomControlEnabled and ZoomFactor. Fixed by @leaanthony in [PR](https://github.com/wailsapp/wails/pull/3137) +- Fixed `-compiler` flag for `wails build`, `wails dev` and `wails generate module`. Fixed in [PR](https://github.com/wailsapp/wails/pull/3121) by [@xtrafrancyz](https://github.com/xtrafrancyz) ## v2.7.1 - 2023-12-10