wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.2k stars 1.21k forks source link

Cross-compiling for Windows on Linux for command line components. #2995

Closed precisionpete closed 1 year ago

precisionpete commented 1 year ago

Have you read the Documentation Contribution Guidelines?

Description

I'm finding Wails v2 is fantastic for my app versus my previous approach of using systray, WebView2 with CGO. Wails is just so much easier and more reliable.

I primarily develop on Linux and then cross-compile for Windows and Darwin. Doing the Windows part entirely from Linux is a big help.

My app still has a requirement for some console utilities. e.g. a daemon and non-graphical environments. Go does a good a good job of that itself.

Do you have any further documentation of how you managed to get all the Windows resources integrated from the Linux host? Any assistance there would be very helpful.

Thanks

Self-service

precisionpete commented 1 year ago

Problem solved. I consulted ChatGPT and got the following answer. My .rc has more stuff in it. But this was the missing link. I was doing this on Windows. And it never occurred to me that the same tool would be available for Linux...

GPT4 says:

Cross-compiling a Go program for Windows on a Linux host while also embedding Windows resources such as icons and manifests can be achieved through a few steps. Here's a comprehensive guide on how to do it:

  1. Install Necessary Tools:

    • First, ensure you have Go installed on your Linux machine.
    • Install mingw-w64 to provide the necessary cross-compilation toolchain.
    • Install windres, which is a part of the MinGW package, to compile the Windows resources.
  2. Prepare Your Windows Resources:

    • Create a .rc file (Windows Resource file) that includes references to your icon, manifest, etc. For example, create a file named resources.rc with content like:
    1 ICON "icon.ico"
    1 24 "manifest.xml"
  3. Compile the Resource File:

    • Use windres to compile the .rc file into a .syso file, which can be automatically included by Go during the build process.
    x86_64-w64-mingw32-windres -o resources.syso resources.rc
  4. Cross-Compile Your Go Program:

    • Set the necessary environment variables and use the go build command to cross-compile your Go program for Windows.
    env GOOS=windows GOARCH=amd64 go build -o output.exe
  5. Verify Your Executable:

    • Now, output.exe should be a Windows executable that includes your specified icon and manifest. You can transfer it to a Windows machine to verify.
  6. Additional Resources:

    • For more detailed steps, you may want to consult additional resources or tutorials on cross-compiling Go programs and embedding Windows resources.

This process allows you to embed icons, manifests, and other resources into your Go program while cross-compiling it for Windows on a Linux host. By creating a Windows resource file, compiling it into a .syso file, and then including that file during the Go build process, you can ensure that your Windows executable has the desired resources embedded.

stffabi commented 1 year ago

wails build should already include the icon and the manifest when doing a cross compile with wails build --platform windows.

We also compile our Windows app on linux and never had a problem with windows resources not being included.

leaanthony commented 1 year ago

If you still have problems with this, please feel free to reopen 👍

precisionpete commented 1 year ago

Wails is fine. This question was more about how to get the Windows resources included in a non-wails go app when cross-compiled on Linux. And the ChatGPT solution worked perfectly.

Since Wails allows me to build a Windows app without Windows, I was trying to get the rest of my app working with the same build process.

Now, if we could only produce a macos app without macos, that would be a triumph. But I suppose that will never happen...

Thanks again for a great product!

leaanthony commented 1 year ago

So the Wails cli does all that for you, even on Linux. That's why it's a little confusing. Glad you have a solution.