Skip to content
Draft
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
11 changes: 9 additions & 2 deletions wayland-scanner/src/client_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
Side::Client,
false,
&interface.requests,
&interface.enums,
);
let events = crate::common::gen_message_enum(
&format_ident!("Event"),
Side::Client,
true,
&interface.events,
&interface.enums,
);

let parse_body = crate::common::gen_parse_body(interface, Side::Client);
Expand Down Expand Up @@ -232,8 +234,13 @@

let enum_args = request.args.iter().flat_map(|arg| {
let arg_name = format_ident!("{}{}", if is_keyword(&arg.name) { "_" } else { "" }, arg.name);
if arg.enum_.is_some() {
Some(quote! { #arg_name: WEnum::Value(#arg_name) })
if let Some(ref enu) = arg.enum_ {
let is_bitfield = interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield);

Check failure on line 238 in wayland-scanner/src/client_gen.rs

View workflow job for this annotation

GitHub Actions / clippy

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`

error: current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0` --> wayland-scanner/src/client_gen.rs:238:83 | 238 | let is_bitfield = interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv = note: `-D clippy::incompatible-msrv` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
Some(if is_bitfield {
quote! { #arg_name: #arg_name }
} else {
quote! { #arg_name: WEnum::Value(#arg_name) }
})
} else if arg.typ == Type::NewId {
if arg.interface.is_none() {
Some(quote! { #arg_name: (I::interface(), version) })
Expand Down
176 changes: 96 additions & 80 deletions wayland-scanner/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
side: Side,
receiver: bool,
messages: &[Message],
enums: &[Enum],
) -> TokenStream {
let variants = messages
.iter()
Expand All @@ -182,98 +183,108 @@

let doc_attr = to_doc_attr(&docs);
let msg_name = Ident::new(&snake_to_camel(&msg.name), Span::call_site());
let msg_variant_decl =
if msg.args.is_empty() {
msg_name.into_token_stream()
} else {
let fields = msg.args.iter().flat_map(|arg| {
let field_name =
format_ident!("{}{}", if is_keyword(&arg.name) { "_" } else { "" }, arg.name);
let field_type_inner = if let Some(ref enu) = arg.enum_ {
let enum_type = dotted_to_relname(enu);
quote! { WEnum<#enum_type> }
} else {
match arg.typ {
Type::Uint => quote! { u32 },
Type::Int => quote! { i32 },
Type::Fixed => quote! { f64 },
Type::String => quote! { String },
Type::Array => quote! { Vec<u8> },
Type::Fd => {
if receiver {
quote! { OwnedFd }
} else {
quote! { std::os::unix::io::BorrowedFd<'a> }
}
let msg_variant_decl = if msg.args.is_empty() {
msg_name.into_token_stream()
} else {
let fields = msg.args.iter().flat_map(|arg| {
let field_name = format_ident!(
"{}{}",
if is_keyword(&arg.name) { "_" } else { "" },
arg.name
);
let field_type_inner = if let Some(ref enu) = arg.enum_ {
let is_bitfield =
enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield);

Check failure on line 197 in wayland-scanner/src/common.rs

View workflow job for this annotation

GitHub Actions / clippy

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`

error: current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0` --> wayland-scanner/src/common.rs:197:67 | 197 | ... enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
let enum_type = dotted_to_relname(enu);
if is_bitfield {
enum_type
} else {
quote! { WEnum<#enum_type> }
}
Type::Object => {
if let Some(ref iface) = arg.interface {
let iface_mod = Ident::new(iface, Span::call_site());
let iface_type =
Ident::new(&snake_to_camel(iface), Span::call_site());
quote! { super::#iface_mod::#iface_type }
} else if side == Side::Client {
quote! { super::wayland_client::ObjectId }
} else {
quote! { super::wayland_server::ObjectId }
} else {
match arg.typ {
Type::Uint => quote! { u32 },
Type::Int => quote! { i32 },
Type::Fixed => quote! { f64 },
Type::String => quote! { String },
Type::Array => quote! { Vec<u8> },
Type::Fd => {
if receiver {
quote! { OwnedFd }
} else {
quote! { std::os::unix::io::BorrowedFd<'a> }
}
}
}
Type::NewId if !receiver && side == Side::Client => {
// Client-side sending does not have a pre-existing object
// so skip serializing it
if arg.interface.is_some() {
return None;
} else {
quote! { (&'static Interface, u32) }
Type::Object => {
if let Some(ref iface) = arg.interface {
let iface_mod = Ident::new(iface, Span::call_site());
let iface_type =
Ident::new(&snake_to_camel(iface), Span::call_site());
quote! { super::#iface_mod::#iface_type }
} else if side == Side::Client {
quote! { super::wayland_client::ObjectId }
} else {
quote! { super::wayland_server::ObjectId }
}
}
}
Type::NewId => {
if let Some(ref iface) = arg.interface {
let iface_mod = Ident::new(iface, Span::call_site());
let iface_type =
Ident::new(&snake_to_camel(iface), Span::call_site());
if receiver && side == Side::Server {
quote! { New<super::#iface_mod::#iface_type> }
Type::NewId if !receiver && side == Side::Client => {
// Client-side sending does not have a pre-existing object
// so skip serializing it
if arg.interface.is_some() {
return None;
} else {
quote! { super::#iface_mod::#iface_type }
quote! { (&'static Interface, u32) }
}
} else {
// bind-like function
if side == Side::Client {
quote! { (String, u32, super::wayland_client::ObjectId) }
}
Type::NewId => {
if let Some(ref iface) = arg.interface {
let iface_mod = Ident::new(iface, Span::call_site());
let iface_type =
Ident::new(&snake_to_camel(iface), Span::call_site());
if receiver && side == Side::Server {
quote! { New<super::#iface_mod::#iface_type> }
} else {
quote! { super::#iface_mod::#iface_type }
}
} else {
quote! { (String, u32, super::wayland_server::ObjectId) }
// bind-like function
if side == Side::Client {
quote! { (String, u32, super::wayland_client::ObjectId) }
} else {
quote! { (String, u32, super::wayland_server::ObjectId) }
}
}
}
Type::Destructor => {
panic!("An argument cannot have type \"destructor\".")
}
}
Type::Destructor => panic!("An argument cannot have type \"destructor\"."),
}
};
};

let field_type = if arg.allow_null {
quote! { Option<#field_type_inner> }
} else {
field_type_inner.into_token_stream()
};
let field_type = if arg.allow_null {
quote! { Option<#field_type_inner> }
} else {
field_type_inner.into_token_stream()
};

let doc_attr = arg
.description
.as_ref()
.map(description_to_doc_attr)
.or_else(|| arg.summary.as_ref().map(|s| to_doc_attr(s)));
let doc_attr = arg
.description
.as_ref()
.map(description_to_doc_attr)
.or_else(|| arg.summary.as_ref().map(|s| to_doc_attr(s)));

Some(quote! {
#doc_attr
#field_name: #field_type
})
});
Some(quote! {
#doc_attr
#field_name: #field_type
})
});

quote! {
#msg_name {
#(#fields,)*
}
quote! {
#msg_name {
#(#fields,)*
}
};
}
};

quote! {
#doc_attr
Expand Down Expand Up @@ -374,8 +385,13 @@

let arg_names = msg.args.iter().map(|arg| {
let arg_name = format_ident!("{}{}", if is_keyword(&arg.name) { "_" } else { "" }, arg.name);
if arg.enum_.is_some() {
quote! { #arg_name: From::from(#arg_name as u32) }
if let Some(enu) = &arg.enum_ {
let is_bitfield = interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield);

Check failure on line 389 in wayland-scanner/src/common.rs

View workflow job for this annotation

GitHub Actions / clippy

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`

error: current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0` --> wayland-scanner/src/common.rs:389:83 | 389 | let is_bitfield = interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
if is_bitfield {
quote! { #arg_name: bitflags::Flags::from_bits_retain(#arg_name as u32) }
} else {
quote! { #arg_name: From::from(#arg_name as u32) }
}
} else {
match arg.typ {
Type::Uint | Type::Int | Type::Fd => quote!{ #arg_name },
Expand Down
12 changes: 10 additions & 2 deletions wayland-scanner/src/server_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
Side::Server,
true,
&interface.requests,
&interface.enums,
);
let events = crate::common::gen_message_enum(
&format_ident!("Event"),
Side::Server,
false,
&interface.events,
&interface.enums,
);

let parse_body = crate::common::gen_parse_body(interface, Side::Server);
Expand Down Expand Up @@ -241,8 +243,14 @@
let enum_args = request.args.iter().flat_map(|arg| {
let arg_name =
format_ident!("{}{}", if is_keyword(&arg.name) { "_" } else { "" }, arg.name);
if arg.enum_.is_some() {
Some(quote! { #arg_name: WEnum::Value(#arg_name) })
if let Some(ref enu) = arg.enum_ {
let is_bitfield =
interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield);

Check failure on line 248 in wayland-scanner/src/server_gen.rs

View workflow job for this annotation

GitHub Actions / clippy

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`

error: current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0` --> wayland-scanner/src/server_gen.rs:248:73 | 248 | interface.enums.iter().find(|i| i.name == *enu).is_some_and(|e| e.bitfield); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
Some(if is_bitfield {
quote! { #arg_name: #arg_name }
} else {
quote! { #arg_name: WEnum::Value(#arg_name) }
})
} else if arg.typ == Type::Object || arg.typ == Type::NewId {
if arg.allow_null {
Some(quote! { #arg_name: #arg_name.cloned() })
Expand Down
Loading