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へのクロスコンパイルも現在のところ失敗することが示されています。

全文翻訳

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向けの実行ファイルとインストーラーがすでに手に入りました!Appleは一般的にクロスコンパイルを許可しないため、macOSをプラットフォームのリストに含めませんでした。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 b