wails icon indicating copy to clipboard operation
wails copied to clipboard

[v2] Cross Compilation Investigation

Open leaanthony opened this issue 2 years ago • 21 comments

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

leaanthony avatar Dec 25 '21 21:12 leaanthony

Hey thanks for posting this!

tmclane avatar Jan 12 '22 20:01 tmclane

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?

springyboiii avatar Mar 17 '22 16:03 springyboiii

You'll notice that this is still a WIP.

tmclane avatar Mar 17 '22 16:03 tmclane

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.

springyboiii avatar Mar 17 '22 16:03 springyboiii

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

tmclane avatar Mar 17 '22 16:03 tmclane

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

tmclane avatar Mar 17 '22 16:03 tmclane

Didn't mean to be harsh.

tmclane avatar Mar 17 '22 16:03 tmclane

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 avatar Mar 17 '22 18:03 leaanthony

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.

leaanthony avatar Mar 17 '22 18:03 leaanthony

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.

springyboiii avatar Mar 18 '22 04:03 springyboiii

Latest versions should work for you but you need docker

leaanthony avatar Mar 18 '22 11:03 leaanthony

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.

stale[bot] avatar Apr 17 '22 13:04 stale[bot]

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 avatar Apr 17 '22 23:04 leaanthony

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

leaanthony avatar Apr 25 '22 08:04 leaanthony

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

leaanthony avatar Jul 03 '22 20:07 leaanthony

How to cross compile linux/arm

aadog avatar Nov 07 '22 17:11 aadog

Using GitHub actions is the best way

leaanthony avatar Nov 07 '22 19:11 leaanthony

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.

zllovesuki avatar Feb 27 '23 21:02 zllovesuki

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.

dxdns avatar Apr 15 '23 12:04 dxdns

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.

abjrcode avatar Oct 28 '23 17:10 abjrcode

Thank you!

leaanthony avatar Oct 28 '23 20:10 leaanthony