wailsapp / wails

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

[v2] Cross Compilation Investigation #1041

Open leaanthony opened 2 years ago

leaanthony commented 2 years ago

Although there is the options for using xgo, this article suggests it might be possible to cross-compile in a more lightweight way using zig: https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

tmclane commented 2 years ago

Hey thanks for posting this!

springyboiii commented 2 years ago

Hey, Great job creating this. Ran into a small issue. Wails CLI v2.0.0-beta.33

App Type: desktop Platforms: darwin/universal Compiler: C:\Program Files\Go\bin\go.exe Build Mode: Production Skip Frontend: false Compress: false Package: true Clean Build Dir: false LDFlags: "" Tags: []

Building target: darwin/universal

Crosscompiling to Mac not currently supported.

Crosscompiling is not working for linux as well. got any solutions?

tmclane commented 2 years ago

You'll notice that this is still a WIP.

springyboiii commented 2 years ago

Oh my bad. I was following a video from youtube where the author himself is explaining the crosscompiling process and it was working fine for him. Sorry.

tmclane commented 2 years ago

This ticket is for the V2 version which I do not believe has working cross-compile at this time.

tmclane commented 2 years ago

V1 used to work with what was available.. if it isn't working now I would open an issue on that.

tmclane commented 2 years ago

Didn't mean to be harsh.

leaanthony commented 2 years ago

Cross compilation for v2 works for all scenarios apart from when the target is Mac and the compilation host isn't. If you really want to cross compile right now you can do so using GitHub actions. Both the October app and https://riftshare.app take this approach. I'll update the docs with this information over the weekend 👍

https://github.com/marcus-crane/october/blob/main/.github/workflows/release.yaml

leaanthony commented 2 years ago

V1 used to work with what was available.. if it isn't working now I would open an issue on that.

V1 is at bug+feature freeze.

springyboiii commented 2 years ago

Oh okay. But I could not get cross-compiling to Linux working as well. Anyway, Thank you for this awesome project. I'll start looking for alternatives to this compiling issue. wails build -platform linux Wails CLI v2.0.0-beta.33

App Type: desktop Platforms: linux Compiler: C:\Program Files\Go\bin\go.exe Build Mode: Production Skip Frontend: false Compress: false Package: true Clean Build Dir: false LDFlags: "" Tags: []

Building target: linux

Crosscompiling to Linux not currently supported.

leaanthony commented 2 years ago

Latest versions should work for you but you need docker

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

leaanthony commented 2 years ago

We may leave "Cross-compilation" for Mac as a github actions task for v2. I will timebox trying to get xgo working to 1 evening and then leave this as a post-v2 task. The majority of people developing for Mac will have a Mac so I'm not sure how many people this really affects.

leaanthony commented 2 years ago

Cross compilation will be handled by GitHub actions for v2. Bumping this down the road.

leaanthony commented 2 years ago

Another option: https://github.com/goreleaser/goreleaser-cross

aadog commented 2 years ago

How to cross compile linux/arm

leaanthony commented 2 years ago

Using GitHub actions is the best way

zllovesuki commented 1 year ago

Cross compiling to darwin target works on linux host with osxcross.

Requirements:

  1. Package the Xcode SDK from an macOS host. Please ensure you have read and understood the Xcode license terms before continuing.
  2. Build the toolchain with ./build.sh
  3. Build the runtime library with ./build_compiler_rt.sh

Examples:

CGO_CFLAGS="-mmacosx-version-min=10.15" CGO_LDFLAGS="-fuse-ld=lld -mmacosx-version-min=10.15 -framework UniformTypeIdentifiers" CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="o64-clang" CXX="o64-clang++" go build -tags desktop,production -buildmode=pie -buildvcs=false -ldflags "-s -w" -a -o build/bin/Phantom-darwin-amd64

CGO_CFLAGS="-mmacosx-version-min=11.1" CGO_LDFLAGS="-fuse-ld=lld -mmacosx-version-min=11.1 -framework UniformTypeIdentifiers" CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC="o64-clang" CXX="o64-clang++" go build -tags desktop,production -buildmode=pie -buildvcs=false -ldflags "-s -w" -a -o build/bin/Phantom-darwin-arm64

Then you can make an universal binary with:

lipo -create -output build/bin/Phantom-darwin build/bin/Phantom-darwin-amd64 build/bin/Phantom-darwin-arm64

The resulting binary can be packaged into .app. Running codesign and notary on an macOS host will work with the cross compiled binary:

rachel@rachels-iMac-Pro phantom % ./codesign.sh     
Conducting pre-submission checks for Phantom.app.zip and initiating connection to the Apple notary service...
Submission ID received
  id: (redacted)
Upload progress: 100.00% (11.9 MB of 11.9 MB)   
Successfully uploaded file
  id: (redacted)
  path: /Users/rachel/code/phantom/build/bin/Phantom.app.zip
Waiting for processing to complete.
Current status: Accepted..........
Processing complete
  id: (redacted)
  status: Accepted
Processing: /Users/rachel/code/phantom/build/bin/Phantom.app
Processing: /Users/rachel/code/phantom/build/bin/Phantom.app
The staple and validate action worked!

You can try using https://github.com/indygreg/apple-platform-rs for codesigning on Linux, however I haven't tested it yet.

dxdns commented 1 year ago

wails build -platform linux/amd64

DEB | Using go webview2loader Wails CLI v2.4.1

Build Options

Platform(s) | linux/amd64 Compiler | C:\Program Files\Go\bin\go.exe Skip Bindings | false Build Mode | production Frontend Directory | D:\projects\myproject\frontend Obfuscated | false Skip Frontend | false Compress | false Package | true Clean Bin Dir | false LDFlags | Tags | [] Race Detector | false

Building target: linux/amd64

WARNING Crosscompiling to Linux not currently supported.

abjrcode commented 1 year ago

Hi, until this investigation is concluded; I wanted to solve all of the cross compilation and targeting issues for my own project so I cooked up a Docker solution inspired by go-releaser-cross. It is available as open source here so feel free to use it.

leaanthony commented 1 year ago

Thank you!

federico-ntr commented 2 months ago

Using GitHub actions is the best way

Unfortunately I can't use GitHub actions at work as we don't use GH at all, so not a way for us. Our pipelines run on on-premise machines which are either linux or windows. I'll try to play around with qemu and, in case of success, i'll report here.

EDIT: actually I don't think it's legal to setup virtual macos machines, so I guess I'll stick with manual builds for darwin.

leaanthony commented 2 months ago

EDIT: actually I don't think it's legal to setup virtual macos machines, so I guess I'll stick with manual builds for darwin.

Indeed, and it's not legal for us to re-distribute macos sdks so you can use docker to do it (though we may be able to find a way that doesn't involve us redistributing anything)...