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

Conversation

xtrafrancyz
Copy link
Contributor

@xtrafrancyz xtrafrancyz commented Dec 12, 2023

Description

Fixes #3120

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested wails build, wails dev, wails generate module with and without -compiler flag.

  • Windows

Test Configuration

# Wails
Version  | v2.7.1
Revision | aa8cd7ce67b1427d75cb4f56259d76cc22b4a882
Modified | true

# System
┌───────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Home Single Language                                            |
| Version      | 2009 (Build: 22621)                                                        |
| ID           | 22H2                                                                       |
| Go Version   | go1.21.5                                                                   |
| Platform     | windows                                                                    |
| Architecture | amd64                                                                      |
| CPU          | Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz                                  |
| GPU 1        | NVIDIA GeForce MX350 (NVIDIA) - Driver: 31.0.15.3203                       |
| GPU 2        | Intel(R) Iris(R) Plus Graphics (Intel Corporation) - Driver: 31.0.101.2114 |
| Memory       | 16GB                                                                       |
└───────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 120.0.2210.61 |
| Nodejs     | N/A          | Installed | 20.10.0       |
| npm        | N/A          | Installed | 10.2.3        |
| *upx       | N/A          | Installed | upx 4.2.1     |
| *nsis      | N/A          | Installed | v3.08         |
└─────────────── * - Optional Dependency ───────────────┘

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Users can now specify a different Go compiler for building the application.
  • Refactor

    • Updated internal logic to accommodate the use of a custom Go compiler across various modules.
  • Tests

    • Adjusted tests to include the new compiler option in the Options struct.
  • Documentation

    • Added a description for the new Compiler field in the GenerateModule struct.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2023

Walkthrough

The recent updates to the Wails framework introduce the ability to specify a custom Go compiler for various operations, such as generating bindings and running development commands. This enhancement allows developers to use different versions of the Go compiler, which can be particularly useful when dealing with compatibility issues or specific build requirements.

Changes

File Path Change Summary
v2/cmd/wails/flags/generate.go
v2/cmd/wails/generate.go
v2/pkg/commands/build/build.go
Added Compiler field to various structs and updated binding generation logic to include the Compiler field in bindings.Options.
v2/cmd/wails/internal/dev/dev.go Updated command execution to use dynamic compiler specified by f.Compiler.
v2/pkg/commands/bindings/bindings.go
v2/pkg/commands/bindings/bindings_test.go
Added Compiler field to Options struct and updated tests accordingly.
website/docs/reference/cli.mdx
website/src/pages/changelog.mdx
Added -compiler flag to wails generate module command and fixed issues related to -compiler flag for wails build, wails dev, and wails generate module.

Assessment against linked issues

Objective Addressed Explanation
Bug Identification The addition of the Compiler field and related changes address the bug where the -compiler flag was ignored in binding generation.
Enhancement Request The addition of support for the -compiler flag in wails dev aligns with the enhancement request to avoid manual editing of go.mod for release builds.
Reproduction Steps The provided steps for reproducing the issue have been addressed by the changes, allowing successful compilation with Go 1.20.
Expected Behavior The changes ensure the expected behavior of successful compilation with Go 1.20 when using the -compiler flag.
Workaround The need for manual editing of go.mod before each build has been addressed by the addition of the -compiler flag support.

Poem

In the code where rabbits hop, 🐇💻
A new compiler field did drop.
"Go forth and build," they cheer,
With every version, have no fear! 🎉

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@leaanthony
Copy link
Member

Thanks for this 🙏 Please could you add an entry to the changelog located at website/src/pages/changelog.mdx and update the flags in website/docs/reference/cli.mdx? Many thanks! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5f412d0 and 3f9ddfa.
Files selected for processing (6)
  • v2/cmd/wails/flags/generate.go (2 hunks)
  • v2/cmd/wails/generate.go (1 hunks)
  • v2/cmd/wails/internal/dev/dev.go (1 hunks)
  • v2/pkg/commands/bindings/bindings.go (2 hunks)
  • v2/pkg/commands/bindings/bindings_test.go (4 hunks)
  • v2/pkg/commands/build/build.go (1 hunks)
Additional comments: 15
v2/cmd/wails/flags/generate.go (4)
  • 5-5: The addition of the Compiler field to the GenerateModule struct is consistent with the PR's objective to allow specifying a different Go compiler. This change should be cross-checked with documentation updates and tests to ensure it's properly communicated and verified.

  • 17-21: The Default method correctly initializes the Compiler field with "go", which is the default Go compiler. This method will help ensure that there is a consistent default value for the Compiler field across the codebase.

  • 13-21: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [5-21]

Please ensure that the documentation and changelog are updated to reflect the addition of the Compiler field and the Default method in the GenerateModule struct. This is crucial for users to understand the new feature and for maintaining the project's documentation integrity.

  • 13-21: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [5-21]

Please verify if new tests have been added or existing tests have been updated to cover the new Compiler field and the Default method. This is important to ensure that the new functionality works as expected and to prevent regressions in the future.

v2/cmd/wails/generate.go (1)
  • 48-54: The addition of the Compiler field to the bindings.Options struct is consistent with the PR's objective to fix the -compiler flag functionality. Ensure that f.Compiler is properly initialized before this point, and if a default compiler should be used when f.Compiler is not specified, verify that there is logic elsewhere in the code to handle this case.
v2/cmd/wails/internal/dev/dev.go (2)
  • 63-67: The change dynamically uses the f.Compiler variable to run the mod tidy command, which aligns with the PR's objective to respect the -compiler flag across commands. Ensure that f.Compiler is properly validated and sanitized before this point to prevent command injection vulnerabilities.

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

Please ensure that the changelog and documentation are updated to reflect the changes made in this PR, especially since the -compiler flag behavior is a user-facing feature.

v2/pkg/commands/bindings/bindings.go (2)
  • 18-24: The addition of the Compiler field to the Options struct is consistent with the PR's objective to handle the -compiler flag correctly.

  • 47-59: The GenerateBindings function has been correctly updated to use the options.Compiler value when running the "go mod tidy" and "go build" commands, which ensures that the specified compiler is used.

v2/pkg/commands/bindings/bindings_test.go (2)
  • 81-87: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [81-110]

The addition of the Compiler field to the Options struct in the test cases is consistent with the PR's objective to handle the -compiler flag. Ensure that the Compiler field is being used correctly within the test cases and that it aligns with the changes made in the rest of the codebase.

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

Verify if new tests have been added or existing tests have been updated to cover the changes introduced by this PR, particularly the new Compiler field's functionality.

v2/pkg/commands/build/build.go (4)
  • 226-231: The addition of the Compiler field to the bindings.Options struct within the GenerateBindings function call is consistent with the PR's objective to respect the -compiler flag. This change ensures that the specified compiler is used during the bindings generation process.

  • 226-231: Verify that the Compiler field is properly initialized before this call and that the GenerateBindings function is correctly utilizing this field to invoke the specified compiler.

  • 226-231: Ensure that any tests related to the GenerateBindings function or the build process are updated to account for the new Compiler field.

  • 226-231: Remind the author to update the changelog and documentation to reflect the changes made in this PR, especially the new Compiler field and its impact on the build process.

Comment on lines 1 to 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
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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3f9ddfa and 9b1538a.
Files selected for processing (2)
  • website/docs/reference/cli.mdx (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
Additional comments: 2
website/docs/reference/cli.mdx (1)
  • 231-238: The documentation update correctly reflects the PR's objective to fix the -compiler flag for the wails generate module command by adding the -compiler and -tags flags to the documentation. This ensures that users are aware of the new functionality and how to use it.
website/src/pages/changelog.mdx (1)
  • 17-18: The changelog entry correctly documents the fix for the -compiler flag as described in the PR objectives. It also provides a link to the PR and credits the contributor, which is a good practice for transparency and recognition.

@xtrafrancyz
Copy link
Contributor Author

Sure, thanks for the quick response

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9b1538a and 9c547d2.
Files selected for processing (4)
  • v2/cmd/wails/internal/dev/dev.go (1 hunks)
  • v2/pkg/commands/bindings/bindings.go (2 hunks)
  • v2/pkg/commands/build/build.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
Files skipped from review due to trivial changes (1)
  • website/src/pages/changelog.mdx
Additional comments: 3
v2/cmd/wails/internal/dev/dev.go (1)
  • 63-67: The change to use f.Compiler instead of a hard-coded "go" command aligns with the PR's objective to handle the -compiler flag correctly. Ensure that f.Compiler is properly initialized before this call, and consider adding error handling if f.Compiler is not set or invalid.
v2/pkg/commands/bindings/bindings.go (1)
  • 18-24: The addition of the Compiler field to the Options struct is consistent with the PR's objective to fix the -compiler flag functionality.
v2/pkg/commands/build/build.go (1)
  • 231-235: The addition of the Compiler field in the bindings.Options struct within the GenerateBindings function correctly implements the PR's objective to respect the -compiler flag. Ensure that the Compiler value is properly validated and sanitized before use to prevent command injection vulnerabilities, especially since it will be used in shell commands.

Comment on lines 47 to 59
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)
}
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)
}

@leaanthony leaanthony self-requested a review December 17, 2023 20:44
@leaanthony leaanthony merged commit 946b602 into wailsapp:master Dec 17, 2023
4 checks passed
@leaanthony
Copy link
Member

@xtrafrancyz - thank for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-compiler flag is ignored in binding generation
2 participants