HN 日本語サマリー

← 一覧へ戻る
プログラミング

Wailsでのクロスコンパイル (2025)

Cross-compilation with Wails (2025) (chriswheeler.dev)

3 pointsby auraham0 コメント

要約

この記事は、GoベースのデスクトップアプリフレームワークであるWails v2.11.0におけるクロスコンパイルのテスト結果を報告しています。LinuxやWindows向けの実行ファイルやインストーラーの生成は比較的容易ですが、macOSへのクロスコンパイルはサポートされていません。また、Linux/amd64からLinux/arm64へのクロスコンパイルも現在のところ失敗することが示されています。

全文翻訳

Wailsでのクロスコンパイル

2025年12月9日、私はGoのデスクトップアプリフレームワークであるWails v2.11.0の公式Svelteテンプレートのクロスコンパイルを、Go v1.25.5を搭載したamd64ラップトップ(Ubuntu 24)上でテストしました。もちろん、WailsとGoの改善に伴い、結果は将来変更される可能性があります。Goは他の多くの言語と比較してクロスコンパイルをはるかに容易にすることで知られており、Wailsのようなフレームワークを使用する場合でも、それは概ね当てはまります。複数のプラットフォーム向けの実行ファイルやインストーラーの作成は、コマンドでそれらのプラットフォームをリストアップするだけで済むこともあります。

wails build -clean -nsis \
    -platform 'linux/amd64,windows/amd64,windows/arm64,windows/386'

上記のコマンドは、以下のファイルを作成します。

build
└── bin
 	   ├── my-app-386.exe
 	   ├── my-app-amd64.exe
 	   ├── my-app-amd64-installer.exe
 	   ├── my-app-arm64.exe
 	   ├── my-app-arm64-installer.exe
 	   └── my-app-linux-amd64

これで、LinuxとWindows向けの実行ファイルとインストーラーがすでに手に入りました!macOSはAppleが一般的にクロスコンパイルを許可しないため、プラットフォームのリストには含めませんでした。WailsやGoがそれについてできることはないと思います。(darwinをリストに含めると、プラットフォームはWARNING Crosscompiling to Mac not currently supportedというメッセージとともにスキップされます。)

存在しないプラットフォームを誤って含めた場合、以下のような役立つメッセージが表示されました。

Supported platforms: darwin,darwin/amd64,darwin/arm64,darwin/universal,linux,linux/amd64,linux/arm64,linux/arm,windows,windows/amd64,windows/arm64,windows/386

静的リンクされていますか?

Linuxのlddコマンド(共有オブジェクトの依存関係を表示する)によると、Windowsの実行ファイルとインストーラーは静的リンクされており、Linuxのものは動的リンクされています。

$ ldd build/bin/*
build/bin/my-app-386.exe:
	not a dynamic executable
build/bin/my-app-amd64.exe:
	not a dynamic executable
build/bin/my-app-amd64-installer.exe:
	not a dynamic executable
build/bin/my-app-arm64.exe:
	not a dynamic executable
build/bin/my-app-arm64-installer.exe:
	not a dynamic executable
build/bin/my-app-linux-amd64:
	linux-vdso.so.1 (0x00007ffdbe4c7000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x000079e7a3ff0000)
	libwebkit2gtk-4.0.so.37 => /lib/x86_64-linux-gnu/libwebkit2gtk-4.0.so.37 (0x000079e7a0400000)
	libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x000079e79fc00000)
    ...

fileコマンドもこれを裏付けています。

$ file build/bin/*
build/bin/my-app-386.exe:		 PE32 executable (GUI) Intel 80386, for MS Windows, 7 sections
build/bin/my-app-amd64.exe:		 PE32+ executable (GUI) x86-64, for MS Windows, 9 sections
build/bin/my-app-amd64-installer.exe:	 PE32 executable (GUI) Intel 80386 (stripped to external PDB), for MS Windows, Nullsoft Installer self-extracting archive, 7 sections
build/bin/my-app-arm64.exe:		 PE32+ executable (GUI) Aarch64, for MS Windows, 7 sections
build/bin/my-app-arm64-installer.exe:	 PE32 executable (GUI) Intel 80386 (stripped to external PDB), for MS Windows, Nullsoft Installer self-extracting archive, 7 sections
build/bin/my-app-linux-amd64:		 ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8ce9189206c3fc10a0fdfb874b0a5cd7b5f61ec7, for GNU/Linux 3.2.0, stripped

-ldflags '-extldflags "-static"'を使用してLinux実行ファイルの静的リンクを強制しようとしましたが、以下のような多くのエラーが発生しました。

/usr/bin/ld: /tmp/go-link-3304063632/000004.o: in function `_cgo_77133bf98b3a_C2func_getaddrinfo':
/tmp/go-build/cgo_unix_cgo.cgo2.c:60:(.text+0x37): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Linux実行ファイルの静的リンクを強制する方法はまだあるかもしれませんが、現時点では把握していません。

linux/arm64 については?

残念ながら、linux/amd64からlinux/arm64へのクロスコンパイルは現在機能しません(以下の出力参照)。Wailsのリポジトリを検索したところ、他の人も同じ問題を抱えていることがわかりました。回避策はないようです。以下が出力です。

$ wails build -platform 'linux/arm64'
Wails CLI v2.11.0


# Build Options

Platform(s)        | linux/arm64
Compiler           | /usr/local/go/bin/go
Skip Bindings      | false
Build Mode         | production
Devtools           | false
Frontend Directory | /home/chris/repos/my-app/frontend
Obfuscated         | false
Skip Frontend      | false
Compress           | false
Package            | true
Clean Bin Dir      | false
LDFlags            | 
Tags               | []
Race Detector      | false


# Building target: linux/arm64

  • Generating bindings: Done.
  • Installing frontend dependencies: Done.
  • Compiling frontend: Done.
  • Compiling application: # runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:30: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:34: Error: operand size mismatch for `mov'
gcc_arm64.S:36: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:39: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:42: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:45: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:48: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:52: Error: operand size mismatch for `mov'
gcc_arm64.S:53: Error: operand size mismatch for `mov'
gcc_arm64.S:54: Error: operand size mismatch for `mov'
gcc_arm64.S:56: Error: no such instruction: `blr x20'
gcc_arm64.S:57: Error: no such instruction: `blr x19'
gcc_arm64.S:59: Error: no such instruction: `ldp x27,x28,[sp,'
gcc_arm64.S:62: Error: no such instruction: `ldp x25,x26,[sp,'
gcc_arm64.S:65: Error: no such instruction: `ldp x23,x24,[sp,'
gcc_arm64.S:68: Error: no such instruction: `ldp x21,x22,[sp,'
gcc_arm64.S:71: Error: no such instruction: `ldp x19,x20,[sp,'
gcc_arm64.S:74: Error: no such instruction: `ldp x29,x30,[sp,'
  ERROR   exit status 1

go1.24.11またはgo1.23.12で-compilerオプションを使用しても、同じエラーメッセージが表示されます。(複数のGoバージョンをインストールすることができます。)

dAppServer/wails-build-action GitHub Action

Wailsのウェブサイトには、実行ファイルのビルドのためのサンプルGitHubアクションが含まれており、dAppServer/wails-build-actionアクションを使用しています。最新の安定バージョンに更新されたアクションでサンプルをテストしました。

dAppServer/wails-build-actionの使用をためらう可能性のある、いくつか(あるいはそうでないかもしれない)の点があります。

  • Wailsサイトのサンプルは、ditto: Cannot get the real path for source './build/bin/App.app'というエラーメッセージで失敗します。
  • そのバグの修正はdAppServer/wails-build-actionリポジトリにプルリクエストとして提出されていますが、5ヶ月以上無視されています(例:https://github.com/Snider/build/pull/49/files)。
  • コピーレフトライセンスです。
  • プロジェクトのドキュメントの多くはLLMによって書かれています。

上記のエラーメッセージは、ターゲットとするプラットフォームのリストにdarwin/universalを残しておくと表示されます。(テストした際には、LinuxとWindowsのビルドは成功しました。)

GoReleaser

GoReleaserは、実行ファイルやインストーラーの作成を含むリリースを自動化する素晴らしいツールです。しかし、Wailsをこれと連携させることはできませんでした。

試した.goreleaser.yamlの一部を以下に示します。

builds:
  - id: "wails-build"
    goos:
      - linux
      - windows
    tool: "go1.23.12"
      # how: https://go.dev/doc/manage-install
      # why: https://github.com/wailsapp/wails/issues/4605
    hooks:
      post:
        - wails build -clean -nsis -compiler 'go1.23.12' -platform 'linux/amd64,linux/arm64,windows/amd64,windows/arm64,windows/386'
        - cp ./build/bin/. ./dist

その後、goreleaser release --snapshot --cleanでこれをテストし、以下のエラーが発生しました。

 ⨯ release failed after 6s
   error=
   │ post hook failed: shell: 'wails build -clean -nsis -compiler 'go1.23.12' -platform linux/amd64,linux/arm64,windows/amd64,windows/arm64,windows/386': exit status 1: Wails CLI v2.11.0
   │ # Build Options
   │
   │ Platform(s)        | linux/amd64,linux/arm64,windows/amd64,windows/arm64,windows/386
   │ Compiler           | /home/chris/go/bin/go1.23.12
   │ Skip Bindings      | false
   │ Build Mode         | production
   │ Devtools           | false
   │ Frontend Directory | /home/chris/repos/my-app/frontend
   │ Obfuscated         | false
   │ Skip Frontend      | false
   │ Compress           | false
   │ Package            | true
   │ Clean Bin Dir      | true
   │ LDFlags            | 
   │ Tags               | []
   │ Race Detector      | false
   │ # Building target: linux/amd64
   │
   │   • Generating bindings:   ERROR
   │
   │           fork/exec /tmp/wailsbindings: no such file or directory
   │   ERROR
   │
   │           fork/exec /tmp/wailsbindings: no such file or directory

go1.24.11でも同じエラーが発生し、toolとcompilerを指定せずにGo v1.25.5を使用した場合でも同様でした。Wailsのリポジトリでこの問題に役立つ可能性のあるIssueやPRなどを検索しましたが、有望なものは見つかりませんでした。うまくいく方法があるかもしれませんが、現時点では手動でリリースを作成するかもしれません。

エラーがGitHub Actionsで実行される場合ではなく、goreleaser release --snapshot --cleanを実行した場合にのみ発生する可能性を考慮して、後者も試しました。エラーメッセージは変更されましたが、やはり回避策はないようです。

 ⨯ release failed after 5s                         
   error=
Error:     │ build failed: exit status 1: main.go:11:12: pattern all:frontend/dist: no matching files found
   target=linux_386_sse2
Error: The process '/opt/hostedtoolcache/goreleaser-action/2.13.1/x64/goreleaser' failed with exit code 1