Skip to content

Commit

Permalink
Fix -compiler flag for build, dev and generate commands (#3121)
Browse files Browse the repository at this point in the history
* Fix -compiler flag for build, dev and generate commands

* Update changelog and docs

---------

Co-authored-by: Lea Anthony <[email protected]>
  • Loading branch information
xtrafrancyz and leaanthony authored Dec 17, 2023
1 parent 49a6b1a commit 946b602
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
7 changes: 7 additions & 0 deletions v2/cmd/wails/flags/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
}
Expand All @@ -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",
}
}
1 change: 1 addition & 0 deletions v2/cmd/wails/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion v2/cmd/wails/internal/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions v2/pkg/commands/bindings/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Options struct {
Filename string
Tags []string
ProjectDirectory string
Compiler string
GoModTidy bool
TsPrefix string
TsSuffix string
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 6 additions & 2 deletions v2/pkg/commands/bindings/bindings_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions v2/pkg/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions website/docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 946b602

Please sign in to comment.