Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -compiler flag for build, dev and generate commands #3121

Merged
merged 5 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines 47 to 59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shell.RunCommandWithEnv function call at the end of the GenerateBindings function should also respect the options.Compiler value if it is intended to run a Go-related process.

- stdout, stderr, err = shell.RunCommandWithEnv(env, workingDirectory, filename)
+ stdout, stderr, err = shell.RunCommandWithEnv(env, workingDirectory, options.Compiler, "run", filename)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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)
}
tagString := buildtags.Stringify(genModuleTags)
if options.GoModTidy {
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.RunCommandWithEnv(env, workingDirectory, options.Compiler, "run", 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
Comment on lines 1 to 14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-110]

Please ensure that the changelog and documentation are updated to reflect the new changes introduced by this PR, especially the handling of the -compiler flag.

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