1 unstable release
Uses new Rust 2024
new 0.1.0 | Apr 14, 2025 |
---|
#2100 in Parser implementations
67 downloads per month
Used in wl-client-builder-cli
98KB
2.5K
SLoC
This crate provides a builder that generates type-safe wrappers for the wl-client
crate.
Generating code in build.rs
The simplest way to generate code looks like this
// build.rs
use wl_client_builder::Builder;
fn main() {
Builder::default().build().unwrap();
}
This will
- load all XML protocols stored in the
wayland-protocols
directory next to theCargo.toml
, - generate code into
$OUT_DIR/wayland-protocols/mod.rs
.
This code can be used with the include!
macro:
mod wayland_protocols {
include!(concat!(env!("OUT_DIR"), "/wayland-protocols/mod.rs"));
}
Generating code with the CLI
Wrappers can be generated ahead of time with the wl-client-builder
application.
This might be preferable if you want to check the generated code into your repository
or if you cannot use build.rs
.
Assuming that you are storing the XML files in a directory called protocols
and
want to generate files into src/protocols/mod.rs
, you can use the CLI as follows:
$ rm -rf src/protocols
$ wl-client-builder --xml-dir protocols src/protocols
$ rustfmt src/protocols/mod.rs
Generating code with a custom application
By default the Builder
assumes that it is being used from build.rs
and will emit
messages for cargo. All of this can be customized.
Builder::default()
// Disable build.rs behavior.
.for_build_rs(false)
// Don't try to load XML files from the `wayland-protocols` directory.
.with_default_dir(false)
// ...
.build().unwrap();
wl-client-builder
The wl-client-builder crate can be used to convert wayland protocol XML files into safe protocol wrappers for wl-client.
MSRV
The MSRV is max(1.85, stable - 3)
.
License
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
Dependencies
~1.8–2.5MB
~45K SLoC