maurict
maurict

Reputation: 21

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

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:

What I've tried:

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,
            _ => {}
        },
        _ => {}
    });
}

Upvotes: 2

Views: 2141

Answers (1)

Radek Polak
Radek Polak

Reputation: 1

Same problem except that i am compiling for ARM. Solved this by compiling for gnueabi target. Something like:

cross build --release --target armv7-unknown-linux-gnueabihf

The resulting binary runs just fine under alpine. As a bonus it works also on Debian.

Upvotes: 0

Related Questions