I'm unable to run rust winit application on Alpine (Wayland)

1.2k views Asked by At

I'm following this tutorial to create a winit window with Rust on Alpine Linux.

When I started the demo application described in the tutorial using cargo run it not compile. But after installing build-base cmake musl-dev libpng-dev freetype-dev fontconfig-dev it was compiling. However, it fails to run, and it throws the following error:

thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoWaylandLib X11 status: LibraryOpenError(OpenError { kind: Library, detail: "opening library failed (Dynamic loading not supported); opening library failed (Dynamic loading not supported)" })', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:719:9

It seems to me that it is unable to use a dynamic library because it's MUSL. I don't know how to fix this. (It does compile, but does not run!)

System info:

  • OS: Linux 5.15.80-0-lts, Alpine v3.17 x86_64
  • WM: sway (wayland)
  • Rust: Toolchain stable-x86_64-unknown-linux-musl, rustc 1.65.0
  • Shell: ash

What I've tried:

  • I have tried to install some Xorg and Gui dev libraries like libxtst-dev libxext-dev libxrender-dev freetype-dev fontconfig-dev libxslt glib-dev musl-dev libxcursor-dev libxi-dev libx11-dev glu-dev glew-dev mesa-dev libxcb-dev libxkbcommon-dev libx11-dev xproto lbxft-dev libxext-dev libxcb-dev libxkbcommon-dev just to be sure. That did not work
  • I tried to run the application using RUSTFLAGS="-C target-feature=-crt-static" but that did not work
  • I've tried to run the application using env var RUSTFLAGS="-C target-feature=+crt-static" to compile it static instead of linked (I don't know if this was correct) but that throws an exception
  • I've tried to run the application using env var RUSTFLAGS="-C target-feature=-crt-static". That did compile and run, but no window shows up. And I'm not sure if that is the way to go. Also that bugs cargo to recompile all dependencies every time I've tried to change something in the code.

I've found no documentation or anything on the internet that could help me out, telling how to run this on Alpine or musl.

I was expecting that with the correct dependencies the program compiles and a window shows up. Can anybody help me out?

This is my cargo.toml:

[package]
name = "gpu-programming"
version = "0.1.0"
edition = "2021"

[dependencies]
wgpu = ">=0.14"
winit = ">=0.27"
env_logger = ">=0.10"
log = ">=0.4"

And this is the code I'm talking about (main.rs)

use winit::{
    event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

pub fn main() {
    env_logger::init(); // Make sure WGPU errors are printed to console. Else it will fail silently!

    // Create event loop and window
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new()
        .build(&event_loop)
        .expect("Failed to create window");

    println!("Window created! {:?}", window.id());
    window.set_visible(true);
    println!("Visible {:?}", window.is_visible());
    println!("Monitor: {:?}", window.current_monitor());

    event_loop.run(move |event, _, control_flow| match event {
        Event::WindowEvent {
            ref event,
            window_id,
        } if window_id == window.id() => match event {
            WindowEvent::CloseRequested
            | WindowEvent::KeyboardInput {
                input:
                    KeyboardInput {
                        state: ElementState::Pressed,
                        virtual_keycode: Some(VirtualKeyCode::Escape),
                        ..
                    },
                ..
            } => *control_flow = ControlFlow::Exit,
            _ => {}
        },
        _ => {}
    });
}
0

There are 0 answers