Run rust in wsl to create a screen

I'm new in Rust, and I'm trying to build a simple screen to see how to do this in Rust. However, I keep getting the same error when I run the cargo run command. I know it's because I'm using WSL, but I just want to use it this way. I've tried using the WINIT_UNIX_BACKEND=x11 cargo run command, but neither option works..
This is my simple code:

use eframe::egui;

fn main() -> Result<(), eframe::Error> {
    let options = eframe::NativeOptions::default();
    eframe::run_native(
        "Minha Janela",
        options,
        Box::new(|_cc| Ok(Box::new(MyApp::default()) as Box<dyn eframe::App>))
    )
}

#[derive(Default)]
struct MyApp;

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.label("Olá, mundo!");
        });
    }
}

This is the error:

Error: WinitEventLoop(Os(OsError { line: 81, file: "/home/myuser_teste/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/winit-0.30.9/src/platform_impl/linux/wayland/event_loop/mod.rs", error: WaylandError(Connection(NoCompositor)) }))

It works for me without setting any environment variables. But that's because I did a lot of work to enable WSLg ages ago. Including installing some drivers:

sudo apt update
sudo apt install libegl1 mesa-vulkan-drivers ubuntu-wsl
Optionally, you might also want to upgrade the drivers...

... using the kisak-mesa PPA. But I found that it changes the wgpu GL backend to llvm-pipe (a software rasterizer) on the current Ubuntu version (24.10). The Ubuntu Mesa uses Direct3D 12.

Ubuntu Mesa:

cargo run --bin wgpu-info

Adapter 0:
                 Backend: Vulkan
                    Name: llvmpipe (LLVM 19.1.1, 256 bits)
                VendorID: 0x10005
                DeviceID: 0x0
                    Type: Cpu
                  Driver: llvmpipe
              DriverInfo: Mesa 24.2.8-1ubuntu1~24.10.1 (LLVM 19.1.1)
        WebGPU Compliant: true
Adapter 1:
                 Backend: Gl
                    Name: D3D12 (NVIDIA GeForce RTX 3090)
                VendorID: 0x0
                DeviceID: 0x0
                    Type: Other
                  Driver: <empty>
              DriverInfo: 4.6 (Core Profile) Mesa 24.2.8-1ubuntu1~24.10.1
        WebGPU Compliant: false

kisak-mesa PPA:

cargo run --bin wgpu-info

Adapter 0:
                 Backend: Vulkan
                    Name: llvmpipe (LLVM 19.1.7, 256 bits)
                VendorID: 0x10005
                DeviceID: 0x0
                    Type: Cpu
                  Driver: llvmpipe
              DriverInfo: Mesa 25.0.3 - kisak-mesa PPA (LLVM 19.1.7)
        WebGPU Compliant: true
Adapter 1:
                 Backend: Gl
                    Name: llvmpipe (LLVM 19.1.7, 256 bits)
                VendorID: 0x10005
                DeviceID: 0x0
                    Type: Cpu
                  Driver: <empty>
              DriverInfo: 4.5 (Core Profile) Mesa 25.0.3 - kisak-mesa PPA
        WebGPU Compliant: false

Both Mesa versions are kind of weird. The drop shadow will go totally opaque sometimes, which is quite jarring. I didn't see any behavioral differences with the PPA. Upgrading may not be worthwhile on current version of Ubuntu. But it was crucial on older versions (22.04 and earlier, IIRC).

1 Like