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: pass platform and arch to GenerateBindings for cross compilation #3795

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

fcying
Copy link
Contributor

@fcying fcying commented Oct 1, 2024

Description

cross compilation to windows with CGO, GenerateBindings get error.

Fixes #3719

Type of change

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

How Has This Been Tested?

  1. wails init -t vue-ts -n wails
  2. cd wails
  3. add example c code to app.go
package main

/*
void test() {
}
*/
import "C"
  1. wails build
  2. export CC=x86_64-w64-mingw32-gcc
  3. export CGO_ENABLED=1
  4. wails build -platform windows
  • Windows
  • macOS
  • Linux

Test Configuration

wails doctor
Version         | v2.9.2
Revision        | a6288c414e737296475ab2513333b0ba639d144d
Modified        | true
Package Manager | apt

# System
┌───────────────────────────────────────────────────┐                                                                                                                                                                                       | OS           | Debian GNU/Linux                   |
| Version      | 12                                 |
| ID           | debian                             |
| Go Version   | go1.23.1                           |
| Platform     | linux                              |
| Architecture | amd64                              |
| CPU          | AMD Ryzen 7 5700X 8-Core Processor |
| GPU          | Unknown                            |
| Memory       | 20GB                               |
└───────────────────────────────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────┐                                                                                                                                                                    | Dependency | Package Name          | Status    | Version             |
| *docker    | docker.io             | Available | 20.10.24+dfsg1-1+b3 |
| gcc        | build-essential       | Installed | 12.9                |
| libgtk-3   | libgtk-3-dev          | Installed | 3.24.38-2~deb12u2   |
| libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.44.3-1~deb12u1    |
| npm        | npm                   | Installed | 10.8.2              |
| *nsis      | nsis                  | Available | 3.08-3+deb12u1      |
| pkg-config | pkg-config            | Installed | 1.8.1-1             |
└────────────────────── * - Optional Dependency ───────────────────────┘

# Diagnosis
Optional package(s) installation details:
  - docker: sudo apt install docker.io
  - nsis: sudo apt install nsis

 SUCCESS  Your system is ready for Wails development!

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

Summary by CodeRabbit

  • New Features

    • Introduced new options for specifying target platform and architecture during binding generation.
    • Enhanced support for building universal binaries on macOS.
    • Added warning for users regarding the legacy WebView2Loader for Windows builds.
    • Implemented Drag & Drop support for Windows, Linux, and macOS.
  • Bug Fixes

    • Resolved cross-compilation failures related to CGO.
    • Fixed CGO memory issue on Darwin.
    • Addressed JSON compatibility for author names.
    • Ensured proper file drop event handling on Windows.
    • Added nil check for Drag-and-Drop functionality on Windows.
  • Documentation

    • Updated changelog to reflect recent fixes and improvements.

Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes introduce enhancements to the bindings and build packages by adding Platform and Arch fields to the Options struct, allowing for more precise control over binding generation based on target platform and architecture. The GenerateBindings function is updated to utilize these fields, and the execBuildApplication function is modified to support macOS universal builds. Additional warnings and checks are incorporated to improve the build process, particularly for cross-compilation scenarios.

Changes

File Change Summary
v2/pkg/commands/bindings/bindings.go Added Platform and Arch fields to Options struct; modified GenerateBindings function to utilize these fields.
v2/pkg/commands/build/build.go Updated GenerateBindings and execBuildApplication functions to support platform-specific builds, including macOS universal binaries.

Assessment against linked issues

Objective Addressed Explanation
Cross compilation for Windows with CGO (#[3719]) The changes do not resolve the CGO build errors on Windows.
Enhance binding generation based on platform/architecture (#[3719])

🐇 In the meadow, we hop with glee,
New fields added, oh what a spree!
Bindings now dance on platforms wide,
With architecture's charm as our guide.
Build and compile, let the magic unfold,
In the world of code, new tales to be told! 🌼✨


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 your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
v2/pkg/commands/bindings/bindings.go (3)

23-24: LGTM! Consider adding comments for the new fields.

The addition of Platform and Arch fields to the Options struct is a good approach for supporting cross-compilation. The field names are clear and their types are appropriate.

Consider adding comments to describe these new fields, especially mentioning their role in cross-compilation. For example:

// Platform represents the target platform for cross-compilation (e.g., "windows", "darwin", "linux")
Platform string
// Arch represents the target architecture for cross-compilation (e.g., "amd64", "arm64")
Arch string

58-60: LGTM! Consider adding validation for Platform and Arch.

The addition of GOOS and GOARCH environment variables is crucial for cross-compilation and directly addresses the issue. The implementation is consistent with the existing codebase style.

Consider adding validation for the Platform and Arch values before setting the environment variables. This could prevent potential issues with invalid inputs. For example:

if options.Platform == "" || options.Arch == "" {
    return "", fmt.Errorf("Platform and Arch must be specified for cross-compilation")
}

Line range hint 1-98: Summary: Good progress on cross-compilation support, with minor improvements needed.

Overall, the changes successfully address the cross-compilation issues mentioned in the PR objectives. The addition of Platform and Arch fields to the Options struct and their use in setting GOOS and GOARCH environment variables are key improvements.

Main points:

  1. The implementation of cross-compilation support is generally correct and aligns with the PR objectives.
  2. Minor improvements such as adding field comments and input validation have been suggested.
  3. There's a potential issue with overwriting environment variables that needs to be addressed to ensure the cross-compilation setup works as intended.

Please address the comments, particularly the potential issue with environment variables, to ensure the cross-compilation functionality works correctly in all scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a6288c4 and f9e675c.

📒 Files selected for processing (2)
  • v2/pkg/commands/bindings/bindings.go (3 hunks)
  • v2/pkg/commands/build/build.go (1 hunks)
🔇 Additional comments (2)
v2/pkg/commands/bindings/bindings.go (1)

62-62: LGTM! Correct use of RunCommandWithEnv for cross-compilation.

The modification to use shell.RunCommandWithEnv instead of shell.RunCommand is crucial for ensuring that the build process uses the correct environment variables for cross-compilation. This change directly addresses the cross-compilation issues mentioned in the PR objectives.

v2/pkg/commands/build/build.go (1)

234-235: Verify that bindings.Options struct includes Platform and Arch fields

The addition of Platform and Arch to the bindings.Options in the GenerateBindings function is intended to support cross-compilation. Please ensure that the Options struct in the bindings package defines these fields and that they are appropriately utilized during the binding generation process.

Run the following script to confirm that Platform and Arch fields exist in the bindings.Options struct:

✅ Verification successful

bindings.Options includes Platform and Arch fields

Verified that the bindings.Options struct includes the Platform and Arch fields required for cross-compilation support during the binding generation process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'bindings.Options' struct contains 'Platform' and 'Arch' fields.

# Test: Search for the definition of 'Options' struct and check for 'Platform' and 'Arch' fields.
ast-grep --lang go --pattern $'type Options struct {\n    $$$\n    Platform string\n    Arch string\n    $$$\n}'

Length of output: 862

v2/pkg/commands/bindings/bindings.go Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Oct 1, 2024

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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
website/src/pages/changelog.mdx (1)

16-17: Minor typo in the "Unreleased" section

There's a small typo in the "Unreleased" section. The word "Fixed" is repeated.

Consider updating the line to remove the repetition:

-### Fixed - Fixed cross compilation failed with CGO [PR](https://github.com/wailsapp/wails/pull/3795) by [@fcying](https://github.com/fcying)
+### Fixed
+- Cross compilation failed with CGO [PR](https://github.com/wailsapp/wails/pull/3795) by [@fcying](https://github.com/fcying)
🧰 Tools
🪛 LanguageTool

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Fixed - Fixed cross compilation failed with CGO [PR](...

(ENGLISH_WORD_REPEAT_RULE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0331048 and e7ed690.

📒 Files selected for processing (3)
  • 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 as they are similar to previous changes (2)
  • v2/pkg/commands/bindings/bindings.go
  • v2/pkg/commands/build/build.go
🧰 Additional context used
🪛 LanguageTool
website/src/pages/changelog.mdx

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Fixed - Fixed cross compilation failed with CGO [PR](...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (1)
website/src/pages/changelog.mdx (1)

Line range hint 1-1000: Overall changelog quality is good

The changelog is well-structured and provides clear information about the changes in each version. It follows a consistent format throughout, making it easy for users to understand the evolution of the project. The use of links to PRs and attributions to contributors is particularly helpful.

The changelog is informative and well-maintained. Keep up the good work in documenting the project's progress!

🧰 Tools
🪛 LanguageTool

[duplication] ~16-~16: Possible typo: you repeated a word
Context: ...f vulnerabilities. ## [Unreleased] ### Fixed - Fixed cross compilation failed with CGO [PR](...

(ENGLISH_WORD_REPEAT_RULE)

@leaanthony leaanthony enabled auto-merge (squash) October 10, 2024 09:13
@leaanthony leaanthony merged commit 8a5a050 into wailsapp:master Oct 10, 2024
14 checks passed
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.

cross compile(linux->windows) with CGO failed
2 participants