| 1 | //! FFI bindings to the wayland system libraries. |
| 2 | //! |
| 3 | //! The names exported by this crate should *not* be used directly, but through |
| 4 | //! the `ffi_dispatch` macro, like this: |
| 5 | //! |
| 6 | //! ```ignore |
| 7 | //! ffi_dispatch!(HANDLE_NAME, func_name, arg1, arg2, arg3); |
| 8 | //! ``` |
| 9 | //! |
| 10 | //! Where `HANDLE_NAME` is the name of the handle generated if the cargo feature `dlopen` is on. |
| 11 | //! |
| 12 | //! For this to work, you must ensure every needed symbol is in scope (aka the static handle |
| 13 | //! if `dlopen` is on, the extern function if not). The easiest way to do this is to glob import |
| 14 | //! the appropriate module. For example: |
| 15 | //! |
| 16 | //! ```ignore |
| 17 | //! #[macro_use] extern crate wayland_sys; |
| 18 | //! |
| 19 | //! use wayland_sys::client::*; |
| 20 | //! |
| 21 | //! let display_ptr = unsafe { |
| 22 | //! ffi_dispatch!(wayland_client_handle(), wl_display_connect, ::std::ptr::null()) |
| 23 | //! }; |
| 24 | //! ``` |
| 25 | //! |
| 26 | //! Each module except `common` corresponds to a system library. They all define a function named |
| 27 | //! `is_lib_available()` which returns whether the library could be loaded. They always return true |
| 28 | //! if the feature `dlopen` is absent, as we link against the library directly in that case. |
| 29 | #![allow (non_camel_case_types)] |
| 30 | #![forbid (improper_ctypes, unsafe_op_in_unsafe_fn)] |
| 31 | // Doc feature labels can be tested locally by running RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc -p <crate> |
| 32 | #![cfg_attr (docsrs, feature(doc_auto_cfg))] |
| 33 | |
| 34 | // If compiling with neither the `client` or `server` feature (non-sensical but |
| 35 | // it's what happens when running `cargo test --all` from the workspace root), |
| 36 | // dlib isn't actually used. This is not an issue, so don't warn about it. |
| 37 | #[allow (unused_imports)] |
| 38 | #[cfg (any(feature = "client" , feature = "server" ))] |
| 39 | #[macro_use ] |
| 40 | extern crate dlib; |
| 41 | |
| 42 | pub mod common; |
| 43 | |
| 44 | pub mod client; |
| 45 | |
| 46 | pub mod server; |
| 47 | |
| 48 | #[cfg (all(feature = "egl" , feature = "client" ))] |
| 49 | pub mod egl; |
| 50 | |
| 51 | #[cfg (all(feature = "cursor" , feature = "client" ))] |
| 52 | pub mod cursor; |
| 53 | |
| 54 | #[cfg (feature = "server" )] |
| 55 | pub use libc::{gid_t, pid_t, uid_t}; |
| 56 | |
| 57 | // We cannot just reexport dlib::ffi_dispatch, because it'd then |
| 58 | // use the "dlopen" feature *on the crate invoking it* rather than |
| 59 | // the "dlopen" feature of wayland-sys. |
| 60 | |
| 61 | #[cfg (feature = "dlopen" )] |
| 62 | #[macro_export ] |
| 63 | macro_rules! ffi_dispatch( |
| 64 | ($handle: expr, $func: ident $(, $arg: expr)* $(,)?) => ( |
| 65 | ($handle.$func)($($arg),*) |
| 66 | ) |
| 67 | ); |
| 68 | |
| 69 | #[cfg (not(feature = "dlopen" ))] |
| 70 | #[macro_export ] |
| 71 | macro_rules! ffi_dispatch( |
| 72 | ($handle: expr, $func: ident $(, $arg: expr)* $(,)?) => ( |
| 73 | $func($($arg),*) |
| 74 | ) |
| 75 | ); |
| 76 | |