Skip to content

Commit

Permalink
Finalize the structure of wayland-sys.
Browse files Browse the repository at this point in the history
And add some dcumentation.
  • Loading branch information
elinorbgr committed Oct 3, 2015
1 parent 1568ab3 commit ac35197
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wayland-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crossbeam = "0.1.5"
dlib = "0.1"
libc = "0.1"
lazy_static = { version = "0.1", optional = true }
wayland-sys = { path = "../wayland-sys" }
wayland-sys = { path = "../wayland-sys", features = ["client"] }

[build-dependencies.wayland-rust-scanner]
path = "../scanner"
Expand Down
1 change: 1 addition & 0 deletions wayland-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ lazy_static = { version = "0.1", optional = true }

[features]
dlopen = ["dlib/dlopen", "lazy_static"]
client = []
egl = []
4 changes: 4 additions & 0 deletions wayland-sys/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Bindings to the client library `libwayland-client.so`
//!
//! The generated handle is named `WAYLAND_CLIENT_HANDLE`

use libc::{c_char, c_void, c_int, size_t, uint32_t};

use super::common::*;
Expand Down
3 changes: 3 additions & 0 deletions wayland-sys/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Various types and functions that are used by both the client and the server
//! libraries.

use libc::{c_char, c_void, c_int, size_t};

#[repr(C)]
Expand Down
6 changes: 6 additions & 0 deletions wayland-sys/src/egl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Bindings to the EGL library `libwayland-egl.so`
//!
//! This lib allows to create EGL surfaces out of wayland surfaces.
//!
//! The created handle is named `WAYLAND_EGl_HANDLE`.

use libc::c_int;
use client::wl_proxy;

Expand Down
54 changes: 52 additions & 2 deletions wayland-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#![allow(dead_code, non_camel_case_types)]

#[macro_use]
//! FFI bindings to the wayland system libraries.
//!
//! The names exported by this crate should *not* be used directly, but though
//! the `ffi_dispatch` macro like this:
//!
//! ```ignore
//! ffi_dispatch!(HANDLE_NAME, func_name, arg1, arg2, arg3);
//! ```
//!
//! Where `HANDLE_NAME` is the name of the handle generated if the cargo feature
//! `dlopen` is on.
//!
//! For this to work, you must ensure every needed symbol is in scope (aka the static handle
//! if `dlopen` is on, the extern function if not). The easiest way to do this is to glob import
//! the appropriate module. For example:
//!
//! ```
//! #[macro_use] extern crate wayland_sys;
//!
//! use wayland_sys::client::*;
//!
//! fn main() {
//! let display_ptr = unsafe {
//! ffi_dispatch!(WAYLAND_CLIENT_HANDLE, wl_display_connect, ::std::ptr::null())
//! };
//! }
//! ```
//!
//! Each module except `common` corresponds to a system library. They all define a function named
//! `is_lib_available()` which returns a boolean depending on whether the lib could be loaded.
//! They always return true if the feature `dlopen` is absent, as the lib is then directly linked.

#[macro_use(external_library,link_external_library,dlopen_external_library)]
extern crate dlib;

#[cfg(feature = "dlopen")]
Expand All @@ -10,7 +42,25 @@ extern crate lazy_static;
extern crate libc;

pub mod common;

#[cfg(feature = "client")]
pub mod client;

#[cfg(feature = "egl")]
pub mod egl;
pub mod egl;

#[cfg(feature = "dlopen")]
#[macro_export]
macro_rules! ffi_dispatch(
($handle: ident, $func: ident, $($arg: expr),*) => (
($handle.$func)($($arg),*)
)
);

#[cfg(not(feature = "dlopen"))]
#[macro_export]
macro_rules! ffi_dispatch(
($handle: ident, $func: ident, $($arg: expr),*) => (
$func($($arg),*)
)
);

0 comments on commit ac35197

Please sign in to comment.