Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split out a x11rb-protocol crate #664

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exclude = [
]

[dependencies]
x11rb-protocol = { version = "0.9.0", path = "x11rb-protocol" }
libc = { version = "0.2", optional = true }
libloading = { version = "0.7.0", optional = true }
once_cell = { version = "1.8.0", optional = true }
Expand Down Expand Up @@ -83,33 +84,33 @@ all-extensions = [
]

# Features to enable individual X11 extensions
composite = ["xfixes"]
damage = ["xfixes"]
dpms = []
dri2 = []
dri3 = []
glx = []
present = ["randr", "xfixes", "sync"]
randr = ["render"]
record = []
render = []
res = []
screensaver = []
shape = []
shm = []
sync = []
xevie = []
xf86dri = []
xf86vidmode = []
xfixes = ["render", "shape"]
xinerama = []
xinput = ["xfixes"]
xkb = []
xprint = []
xselinux = []
xtest = []
xv = ["shm"]
xvmc = ["xv"]
composite = ["x11rb-protocol/composite", "xfixes"]
eduardosm marked this conversation as resolved.
Show resolved Hide resolved
damage = ["x11rb-protocol/damage", "xfixes"]
dpms = ["x11rb-protocol/dpms"]
dri2 = ["x11rb-protocol/dri2"]
dri3 = ["x11rb-protocol/dri3"]
glx = ["x11rb-protocol/glx"]
present = ["x11rb-protocol/present", "randr", "xfixes", "sync"]
randr = ["x11rb-protocol/randr", "render"]
record = ["x11rb-protocol/record"]
render = ["x11rb-protocol/render"]
res = ["x11rb-protocol/res"]
screensaver = ["x11rb-protocol/screensaver"]
shape = ["x11rb-protocol/shape"]
shm = ["x11rb-protocol/shm"]
sync = ["x11rb-protocol/sync"]
xevie = ["x11rb-protocol/xevie"]
xf86dri = ["x11rb-protocol/xf86dri"]
xf86vidmode = ["x11rb-protocol/xf86vidmode"]
xfixes = ["x11rb-protocol/xfixes", "render", "shape"]
xinerama = ["x11rb-protocol/xinerama"]
xinput = ["x11rb-protocol/xinput", "xfixes"]
xkb = ["x11rb-protocol/xkb"]
xprint = ["x11rb-protocol/xprint"]
xselinux = ["x11rb-protocol/xselinux"]
xtest = ["x11rb-protocol/xtest"]
xv = ["x11rb-protocol/xv", "shm"]
xvmc = ["x11rb-protocol/xvmc", "xv"]

[package.metadata.docs.rs]
features = [
Expand Down Expand Up @@ -146,4 +147,4 @@ name = "record"
required-features = ["record"]

[workspace]
members = ["generator", "xcbgen-rs", "cairo-example", "xtrace-example"]
members = ["generator", "xcbgen-rs", "x11rb-protocol", "cairo-example", "xtrace-example"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PROTO=xcb-proto-1.14-1-g2b3559c
OUT=src/protocol
PROTO_OUT=x11rb-protocol/src/protocol
X11RB_OUT=src/protocol

generate:
mkdir -p "$(OUT)"
cargo run -p x11rb-generator -- "$(PROTO)/src" "$(OUT)"
mkdir -p "$(PROTO_OUT)" "$(X11RB_OUT)"
cargo run -p x11rb-generator -- "$(PROTO)/src" "$(PROTO_OUT)" "$(X11RB_OUT)"

.PHONY: generate
7 changes: 7 additions & 0 deletions doc/making_a_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ git tag -a -m "Version 0.2.0" v0.2.0
cargo publish
git push origin v0.2.0
```
TODO: Update the above for the split with the new x11rb-protocol crate.
Both crate versions should be kept close together. Still, if there are no
semver-incompatible changes in x11rb-protocol, only the micro version needs a
bump.

Also: Beware! The version for the x11rb -> x11rb-protocol dependency needs to be
properly updated on version changes!
111 changes: 72 additions & 39 deletions generator/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,104 @@ mod special_cases;

use output::Output;

pub(crate) fn generate(module: &xcbgen::defs::Module) -> HashMap<PathBuf, String> {
let mut out_map = HashMap::new();
pub(crate) struct Generated {
pub(crate) file_name: PathBuf,
pub(crate) proto: String,
pub(crate) x11rb: String,
}

let mut main_out = Output::new();
write_code_header(&mut main_out);
outln!(main_out, "//! Bindings to the X11 protocol.");
outln!(main_out, "//!");
outln!(
main_out,
"//! Each sub-module of this module corresponds to one X11 extension. It contains all the"
);
pub(crate) fn generate(module: &xcbgen::defs::Module) -> Vec<Generated> {
let mut out_map = Vec::new();

let mut main_proto_out = Output::new();
let mut main_x11rb_out = Output::new();
for out in vec![&mut main_proto_out, &mut main_x11rb_out].into_iter() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should leave a comment about this in #538.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, good idea.

Done.

write_code_header(out);
outln!(out, "//! Bindings to the X11 protocol.");
outln!(out, "//!");
outln!(
out,
"//! Each sub-module of this module corresponds to one X11 extension. It contains all the"
);
outln!(
out,
"//! definitions from that extension. The core X11 protocol is in \
[`xproto`](xproto/index.html).",
);
outln!(out, "");
outln!(out, "// Clippy does not like some names from the XML.");
outln!(out, "#![allow(clippy::upper_case_acronyms)]");
outln!(out, "// This is not easy to fix, so ignore it.");
outln!(
out,
"#![allow(clippy::needless_borrow, clippy::needless_lifetimes)]"
);
}
outln!(main_proto_out, "");
outln!(main_proto_out, "use std::borrow::Cow;");
outln!(main_proto_out, "use std::convert::TryInto;");
outln!(main_proto_out, "use crate::errors::ParseError;");
outln!(main_proto_out, "use crate::utils::RawFdContainer;");
outln!(
main_out,
"//! definitions from that extension. The core X11 protocol is in \
[`xproto`](xproto/index.html).",
main_proto_out,
"use crate::x11_utils::{{TryParse, X11Error}};"
);
outln!(main_out, "");
outln!(main_out, "// Clippy does not like some names from the XML.");
outln!(main_out, "#![allow(clippy::upper_case_acronyms)]");
outln!(main_out, "// This is not easy to fix, so ignore it.");
outln!(main_out, "#![allow(clippy::needless_borrow)]");
outln!(main_out, "");
outln!(main_out, "use std::borrow::Cow;");
outln!(main_out, "use std::convert::TryInto;");
outln!(main_out, "use crate::errors::ParseError;");
outln!(main_out, "use crate::utils::RawFdContainer;");
outln!(main_out, "use crate::x11_utils::{{TryParse, X11Error}};");
outln!(
main_out,
main_proto_out,
"use crate::x11_utils::{{ExtInfoProvider, ReplyParsingFunction, Request as RequestTrait, \
RequestHeader}};"
);
outln!(main_out, "");
outln!(main_proto_out, "");

let caches = RefCell::new(namespace::helpers::Caches::default());
caches.borrow_mut().gather_enum_infos(module);

let mut enum_cases = HashMap::new();
for ns in module.sorted_namespaces() {
let mut ns_out = Output::new();
let mut ns_proto_out = Output::new();
let mut ns_x11rb_out = Output::new();
let wrapper_info = resources::for_extension(&ns.header);
namespace::generate(
module,
&ns,
&caches,
&mut ns_out,
&mut ns_proto_out,
&mut ns_x11rb_out,
&mut enum_cases,
wrapper_info,
);
out_map.insert(
PathBuf::from(format!("{}.rs", ns.header)),
ns_out.into_data(),
);
out_map.push(Generated {
file_name: PathBuf::from(format!("{}.rs", ns.header)),
proto: ns_proto_out.into_data(),
x11rb: ns_x11rb_out.into_data(),
});

if ext_has_feature(&ns.header) {
outln!(main_out, "#[cfg(feature = \"{}\")]", ns.header);
for out in vec![&mut main_proto_out, &mut main_x11rb_out].into_iter() {
if ext_has_feature(&ns.header) {
outln!(out, "#[cfg(feature = \"{}\")]", ns.header);
}
outln!(out, "pub mod {};", ns.header);
}
outln!(main_out, "pub mod {};", ns.header);
}
outln!(main_out, "");
outln!(main_proto_out, "");

requests_replies::generate(&mut main_out, module, enum_cases);
error_events::generate(&mut main_out, module);
requests_replies::generate(&mut main_proto_out, module, enum_cases);
error_events::generate(&mut main_proto_out, module);

outln!(main_x11rb_out, "");
outln!(main_x11rb_out, "pub use x11rb_protocol::protocol::Request;");
outln!(main_x11rb_out, "pub use x11rb_protocol::protocol::Reply;");
outln!(
main_x11rb_out,
"pub use x11rb_protocol::protocol::ErrorKind;"
);
outln!(main_x11rb_out, "pub use x11rb_protocol::protocol::Event;");

out_map.insert(PathBuf::from("mod.rs"), main_out.into_data());
out_map.push(Generated {
file_name: PathBuf::from("mod.rs"),
proto: main_proto_out.into_data(),
x11rb: main_x11rb_out.into_data(),
});
out_map
}

Expand Down
Loading