Skip to content

fix: cross compiling on linux for windows#4263

Merged
leaanthony merged 3 commits into
wailsapp:masterfrom
rynsf:bugfix/4262_fix-cross-compile
May 19, 2025
Merged

fix: cross compiling on linux for windows#4263
leaanthony merged 3 commits into
wailsapp:masterfrom
rynsf:bugfix/4262_fix-cross-compile

Conversation

@rynsf

@rynsf rynsf commented May 2, 2025

Copy link
Copy Markdown
Contributor

Description

Fixes #4262
wailsbindings is executed on the build machine to generate bindings. We compile it for the build machine not the target.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  1. wails init -n test-wails
  2. cd test-wails/
  3. wails build -platform windows

This application builds and runs successfully.

For applications that use CGO:

  1. wails init -n test-cgo
  2. cd test-cgo/
  3. add the following code to app.go
package main

/*
void testcgo() {
}
*/
import "C"
  1. export CC=x86_64-w64-mingw32-gcc
  2. export CGO_ENABLED=1
  3. wails build -platform windows

This application also builds and runs successfully.

  • Windows
  • macOS
  • Linux

Test Configuration


          Wails Doctor



# Wails
Version         | v2.10.1
Revision        | e645d0b47dae6cb330130c0cc4425521e5580bcd
Modified        | false
Package Manager | pacman


# System
┌──────────────────────────────────────────────────────────────────────────────────┐
| OS           | Manjaro Linux                                                     |
| Version      | Unknown                                                           |
| ID           | manjaro                                                           |
| Branding     |                                                                   |
| Go Version   | go1.24.2                                                          |
| Platform     | linux                                                             |
| Architecture | amd64                                                             |
| CPU          | Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz                         |
| GPU          | CometLake-U GT2 [UHD Graphics] (Intel Corporation) - Driver: i915 |
| Memory       | 8GB                                                               |
└──────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌─────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version                     |
| *docker    | docker       | Installed | 1:28.0.4-2                  |
| gcc        | gcc          | Installed | 14.2.1+r753+g1cd744a6828f-1 |
| libgtk-3   | gtk3         | Installed | 1:3.24.49-1                 |
| libwebkit  | webkit2gtk   | Installed | 2.48.1-1                    |
| npm        | npm          | Installed | 11.2.0-1                    |
| pkg-config | pkgconf      | Installed | 2.4.3-1                     |
|                                                                     |
└────────────────────── * - Optional Dependency ──────────────────────┘

# Diagnosis
 SUCCESS  Your system is ready for Wails development!

 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

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

  • Bug Fixes

    • Resolved build failures when cross-compiling on Linux targeting Windows.
  • Documentation

    • Updated the changelog to include details about the build fix for cross-compilation issues.

compile wailsbindings for the build machine
@coderabbitai

coderabbitai Bot commented May 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove the Platform and Arch fields from the Options struct used in the bindings generation process. The build environment now always uses the native OS and architecture values from the runtime, rather than accepting overrides for cross-compilation. Additionally, the CC environment variable is explicitly removed before invoking the build command. The changelog is updated to document this fix for build failures during cross-compilation from Linux to Windows.

Changes

File(s) Change Summary
v2/pkg/commands/bindings/bindings.go Removed Platform and Arch fields from Options struct; set GOOS/GOARCH from runtime; unset CC.
v2/pkg/commands/build/build.go Stopped passing Platform and Arch fields to GenerateBindings.
website/src/pages/changelog.mdx Added changelog entry describing the fix for cross-compilation build failures.

Assessment against linked issues

Objective Addressed Explanation
Fix build failure when cross compiling on Linux for Windows (#4262)

Possibly related PRs

Poem

A hop, a skip, a build anew,
No more cross-compile hullabaloo!
Platform, Arch—now out of sight,
Native bindings set just right.
With CC unset and errors gone,
The rabbit hums and hops along!
🐇✨

Tip

⚡️ Free AI Code Reviews for VS Code, Cursor, Windsurf
  • CodeRabbit now supports VS Code, Cursor and Windsurf. This brings free AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Learn more

[!ANNOUNCEMENT]

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e645d0b and 59adf6f.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/pages/changelog.mdx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@leaanthony

Copy link
Copy Markdown
Member

Thanks for opening this. This code was originally introduced here to fix CGO cross compilation. It looks like this might break that?

@sonarqubecloud

Copy link
Copy Markdown

@rynsf

rynsf commented May 15, 2025

Copy link
Copy Markdown
Contributor Author

Yes, I did look at that PR. And this is what I was able to understand. The CGO build fails in that issue because there was a mismatch between GOOS and GOARCH, and the CC passed for cross compiling.
wailsbindings is executed on the build machine during the build process. As can seen here, bindings.go:90.
So, the way to deal with that mismatch must be to compile wailsbindings for the build machine.
That said, I have tested building CGO applications as shown in the above comment.
Just to be very sure, I have tested it again with:

  1. wails init -n test-cgo
  2. cd test-cgo/
  3. add the following code to app.go
/*
int multiple(int n) {
    return n * MY_NUM;
}
*/
import "C"

and modify Greet to call multiple

func (a *App) Greet(name string) string {
	return fmt.Sprintf("Hello %s, It's show time! Num: %d", name, C.multiple(2))
}
  1. CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CGO_CFLAGS="-DMY_NUM=10" wails build -platform windows

The application builds successfully.

Final result:
test-cgo wails application running on windows

Please let me know if I've misunderstood something. Thanks for your time.

@leaanthony

Copy link
Copy Markdown
Member

Please let me know if I've misunderstood something. Thanks for your time.

Thanks so much for testing

@leaanthony leaanthony merged commit ac1479a into wailsapp:master May 19, 2025
8 of 10 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.

build fails when cross compiling on Linux for Windows

2 participants