⚔️

Windows 10 の WSL2 で Tauri を起動するための VcXsrv 設定

2022/08/28に公開

2022-10-11 追記
Windows 11 の WSLg は以下の設定不要ですっと動きました

TLDR

WSL2 から cargo tauri dev してもエラーメッセージが出て起動しない場合の設定項目

  1. 環境変数に下記を設定
export DISPLAY=$(ipconfig.exe | grep IPv4 | head -1 | awk '{print $NF}' | awk 'sub(/\r$/,"")')
  1. VcXsrv の設定画面の最後に下記を設定
    • Disable access control にチェック
    • Addtional parameters for VcXsrv に -nowgl を入力

以上で動きました

以下は同じ問題でハマった人がエラーメッセージでググって辿り着ける用なのでスキップしてもいいよ

DISPLAY の設定

DISPLAY がないと X を表示できません
WSL2 側ではなく Windows 10 側の IP を設定する必要があります

$ cargo tauri dev
        Info Watching /home/oooooooo/work/test/tauri-app/src-tauri for changes...
   Compiling tauri-app v0.0.0 (/home/oooooooo/work/test/tauri-app/src-tauri)
    Finished dev [unoptimized + debuginfo] target(s) in 12.48s

(tauri-app:27979): Gtk-WARNING **: 16:21:13.725: cannot open display:

Disable access control にチェック

Authorization required, but no authorization protocol specified が出るため許可

$ cargo tauri dev
        Info Watching /home/oooooooo/work/test/tauri-app/src-tauri for changes...
   Compiling tauri-app v0.0.0 (/home/oooooooo/work/test/tauri-app/src-tauri)
    Finished dev [unoptimized + debuginfo] target(s) in 13.08s
Authorization required, but no authorization protocol specified

(tauri-app:25167): Gtk-WARNING **: 15:46:15.198: cannot open display: 192.168.1.2:0.0

-nowgl を入力

このオプションを付けないと動かない X アプリがよくある

$ cargo tauri dev
        Info Watching /home/oooooooo/work/test/tauri-app/src-tauri for changes...
   Compiling tauri-app v0.0.0 (/home/oooooooo/work/test/tauri-app/src-tauri)
    Finished dev [unoptimized + debuginfo] target(s) in 12.32s

(WebKitWebProcess:26186): Gdk-ERROR **: 15:57:47.601: The program 'WebKitWebProcess' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 172 error_code 163 request_code 149 (GLX) minor_code 21)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

参考資料

この記事は下記の要約です。助かりました

Discussion