#wayland #codegen

macro build wayland-scanner

Wayland Scanner for generating rust APIs from XML wayland protocol files

139 releases

0.31.0 Sep 2, 2023
0.30.1 Jun 17, 2023
0.30.0 Dec 27, 2022
0.30.0-beta.13 Nov 4, 2022
0.2.0 Nov 19, 2015

#784 in GUI

Download history 59019/week @ 2023-08-10 56555/week @ 2023-08-17 56431/week @ 2023-08-24 53623/week @ 2023-08-31 61504/week @ 2023-09-07 59231/week @ 2023-09-14 55773/week @ 2023-09-21 67874/week @ 2023-09-28 70964/week @ 2023-10-05 93338/week @ 2023-10-12 82848/week @ 2023-10-19 102820/week @ 2023-10-26 95948/week @ 2023-11-02 89637/week @ 2023-11-09 104216/week @ 2023-11-16 86162/week @ 2023-11-23

399,100 downloads per month
Used in 1,371 crates (16 directly)

MIT license

96KB
2K SLoC

crates.io docs.rs Continuous Integration codecov

wayland-scanner

This crate provides procedural macros for generating the rust code associated with a Wayland XML protocol specification, for use with the wayland-client, wayland-server and wayland-backend crates.

Before trying to use this crate, you may check if the protocol extension you want to use is not already exposed in the wayland-protocols crate.


lib.rs:

Wayland protocol code-generation machinnery

This crate provides procedural macros for generating the rust code associated with a Wayland XML protocol specification, for use with the wayland-client, wayland-server and wayland-backend crates.

Before trying to use this crate, you may check if the protocol extension you want to use is not already exposed in the wayland-protocols crate.

Example usage

Below is a template for generating the code for a custom protocol client-side. Server-side is identical, just replacing client by server. The path to the XML file is relative to the crate root.

// Generate the bindings in their own module
pub mod my_protocol {
    use wayland_client;
    // import objects from the core protocol if needed
    use wayland_client::protocol::*;

    // This module hosts a low-level representation of the protocol objects
    // you will not need to interact with it yourself, but the code generated
    // by the generate_client_code! macro will use it
    pub mod __interfaces {
        // import the interfaces from the core protocol if needed
        use wayland_client::protocol::__interfaces::*;
        wayland_scanner::generate_interfaces!("./path/to/the/protocol.xml");
    }
    use self::__interfaces::*;

    // This macro generates the actual types that represent the wayland objects of
    // your custom protocol
    wayland_scanner::generate_client_code!("./path/to/the/protocol.xml");
}

Dependencies

~1.5MB
~23K SLoC