Getting Tauri working in WSL

martypenner

4 reactions 2022-10-05

Update: Tauri has good guidelines for working with homebrew and a clear set of prerequisites for linux. Not sure if I missed these before or they were added later, but those docs basically describe how to avoid the installation problems I ran into.

TL;DR:

  • Don’t use homebrew; use your distro’s package manager instead (I used apt on ubuntu 20.04).
  • Install wslg according to instructions.
  • Install latest GPU drivers.
  • DON’T install a 3rd-party X server like VcXsrv.
  • DON’T install xfce4.
  • Add export DISPLAY=:0 to your shell file, e.g. ~/.zshrc.

I’ve been chipping away at a personal task manager clone (who isn’t these days?), and wanted to begin packaging the app for desktop. I recently heard about tauri.app, which sounds like a very promising electron alternative. I love their philosophy of security and local-first apps; this has been something on my mind for quite a while. I appreciate cloud connectivity as an option, but for something like a simple task manager, why do you need to talk to your servers?! Let me choose that please.

Tauri is built in Rust, and because it’s a desktop app, it obviously has some visual components that run outside of the cli. I do a lot of my personal development on my windows machine in WSL. It’s fantastic overall, but how do I run desktop apps from it? There’s no way I wanted to set up Tauri in windows and pollute my environment again.

It turns out that wslg has been around for a bit and provides a way to run linux desktop apps as companion apps to the rest of your windows app. That’s so cool. Through a process of trial and error, I discovered that getting wslg going was pretty easy, but getting tauri from within wsl was not. Essentially, I found that using homebrew to install wslg packages in my wsl distro (Ubuntu 20.04) caused a lot of issues. Resorting to the native package manager to install the same dependencies worked much better.

A number of *-dev packages were required to be present to boot tauri properly. I noticed a number of issues with pkg-config and missing packages. I used the ubuntu 20.04 package repository search whenever I saw an error message about a missing package to determine which packages to install.

The full install line was this:

sudo apt install pkg-config \
  libdbus-1-dev \
  libgtk-3-dev \
  libsoup2.4-dev \
  libjavascriptcoregtk-4.0-dev \
  libwebkit2gtk-4.0-dev

Finally, I need to add export DISPLAY=:0 to my ~/.zshrc file.

After running through the various required steps and navigating around some speedbumps, I got it working! Tauri has a very easy-to-use init script. Watching that desktop GUI come up the first time after running npm run tauri dev is very satisfying. I’m looking forward to exploring its APIs.

For more info on potential issues with tauri and wslg, have a look at this: https://github.com/tauri-apps/tauri/issues/380

tauri