My ultimate goal is to use Pixels in WSL to create a data visualization in Rust.
However, I couldn't get the Pixels examples to run and so I first want to make sure Winit can run properly.
Downloading the Winit repository from GitHub and running the window example works correctly.
However, if I create a new project and copy-paste the example code to it then running the code does not open a window anymore.
From running gdb, the code appears to get stuck in window.request_redraw() but I couldn't find much else out.
I am not super knowledgeable in windowing systems, but from running echo $DISPLAY and echo $WAYLAND_DISPLAY I get :0 and wayland-0, respectively, which I believe indicates that WSL has both X11 and Wayland functionality installed.
I am using Ubuntu 22.04.3 LTS. Running cat /proc/version prints Linux version 5.15.90.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Jan 27 02:56:13 UTC 2023.
I seem to have some misunderstanding of how Cargo manages dependencies, since I don't know why the same code would run inside the Winit source project but not in my own project when I instruct Cargo to download the same version of the Winit source. I have tried Winit v0.29, v0.28, and v0.27 and the same problem persists.
Steps to reproduce:
git clone https://github.com/rust-windowing/winit.git
cd winit
cargo run --example window
window opens fine...
cd ..
cargo new window
cd window
cargo add winit
cargo add simple_logger
cp ../winit/examples/window.rs src/main.rs
mkdir src/util
cp ../winit/examples/util/fill.rs src/util
cargo run
window does not open...

](https://i.stack.imgur.com/slLOh.png)](https://i.stack.imgur.com/77aTr.png)
Solved!
TL;DR the example code had a feature flag that I didn't enable in my own project.
After fruitlessly debugging the main example code in
window.rsI tackled the helper code infill.rs. There is one functionfill_window()with two signatures:The first one should run when the
rwh_05feature is enabled andtarget_osis notandroidorios. Otherwise, the second one should run.I put a
println!()in each and discovered that mywindowproject was compiling to the second (no-op) function while the sourcewinitproject was compiling to the first function.So either
target_os == android,target_os == ios, orrwh_05is not enabled.I ran some tests by adding code to
fill.rsThe output shows that
target_osislinux.Next,
The output shows that
rwh_05is not enabledâ €And this is where I had my revelation.
I had mistakenly put the following in
Cargo.tomlthinking that it would enablerwh_05globally, when in reality it only enabled that feature for thewinitcrate and not my own local project.Adding
to
Cargo.tomland running withcargo run --features rwh_05runs the window example as expected: