Smithay / wayland-rs

Rust implementation of the wayland protocol (client and server).
MIT License
1.09k stars 123 forks source link

wayland-sys 0.31.5 panic in `build.rs`: `wayland-client` required by `wayland-sys` not found #767

Open emilk opened 3 weeks ago

emilk commented 3 weeks ago

I updated a crate that pulled in a new wayland-sys, and now I get the following error on CI:

error: failed to run custom build command for `wayland-sys v0.31.5`

Caused by:
  process didn't exit successfully: `/home/runner/work/rerun/rerun/target/debug/build/wayland-sys-973359b900b2004b/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=WAYLAND_CLIENT_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=WAYLAND_CLIENT_STATIC
  cargo:rerun-if-env-changed=WAYLAND_CLIENT_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wayland-sys-0.31.5/build.rs:10:47:
  called `Result::unwrap()` on an `Err` value: 
  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags wayland-client

  The system library `wayland-client` required by crate `wayland-sys` was not found.
  The file `wayland-client.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  The PKG_CONFIG_PATH environment variable is not set.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `wayland-client.pc`.

The offending line is this, which unfortunately doesn't have a comment:

https://github.com/Smithay/wayland-rs/blob/a078c5b36a8f68c095ffb2ad32dba7c2eef22310/wayland-sys/build.rs#L9-L11

(it would be nice if the unwrap was replaced with a helpful expect).

CARGO_FEATURE_CLIENT lead me to look at the documentation for the client feature flag, but again I came up short:

https://github.com/Smithay/wayland-rs/blob/a078c5b36a8f68c095ffb2ad32dba7c2eef22310/wayland-sys/Cargo.toml#L24-L26

(I can recommend https://crates.io/crates/document-features for documenting features btw)

I would appreciate any guidance I can get (I don't speak Linux) 🙏

Is the fix as simple as adding apt-get install wayland-client to my CI?

kchibisov commented 3 weeks ago

You need the libwayland-dev. You can also look into CI for winit/etc.

emilk commented 3 weeks ago

You need the libwayland-dev

Does all users of our binary need it too? That will be quite annoying for them, especially X11 users.

You can also look into CI for winit/etc.

I don't see anything special in https://github.com/rust-windowing/winit/blob/master/.github/workflows/ci.yml


This happened when updating from wayland-sys 0.31.4 to 0.31.5 btw - what changed there? Can it be undone?

elinorbgr commented 3 weeks ago

The crate wayland-sys has not changed at all since its 0.31.1 release, so I don't think this update is the reason you got this error. Rather, maybe one of your dependencies pulling wayland-sys activated the cargo feature in one of its updates?

Does all users of our binary need it too?

That depends on what does your dependency using wayland-client, but assuming it uses the dlopen feature (like winit does), then that is only needed for building the project.

kchibisov commented 3 weeks ago

@emilk maybe something that was using wayland-sys disabled its dlopen feature? Since dlopen is the only way to avoid the direct linking to system library. winit for example always enables it by default, but one can disable it when including winit.

emilk commented 2 weeks ago

I could indeed fix the problem by adding wayland-sys = { features = ["dlopen"] } to my code (https://github.com/rerun-io/rerun/pull/7977). Thanks! 🙏

It might be nice to add that as a suggestion for others that hit the same unwrap in https://github.com/Smithay/wayland-rs/blob/a078c5b36a8f68c095ffb2ad32dba7c2eef22310/wayland-sys/build.rs#L9-L11