diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1f67981aa..b274acfda21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Minimize the scope of the `native_lib` features. The code generated by `wayland-scanner` is + now independent of this feature, making `wayland-protocols` also independent of it, and + avoiding it to pollute dependency trees in non-trivial ways. + # 0.22.2 -- 2019-02-16 - [protocols] Update `wlr-protocols` (`data-control` version 2). diff --git a/Cargo.toml b/Cargo.toml index 33187d77d3c..acb8303bb83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ calloop = "0.4.2" members = [ "wayland-sys", "wayland-scanner", "wayland-client", "wayland-server", "wayland-protocols", "wayland-commons" ] [features] -native_lib = ["wayland-client/dlopen", "wayland-server/dlopen", "wayland-protocols/native_lib", "wayland-commons/native_lib", "wayland-sys"] +native_lib = [ "wayland-client/dlopen", "wayland-server/dlopen", "wayland-sys" ] # Manual list of the tests, required because some need `harness = false` diff --git a/tests/< b/tests/< deleted file mode 100644 index e1cfb07bba7..00000000000 --- a/tests/< +++ /dev/null @@ -1,83 +0,0 @@ -mod helpers; - -use helpers::{roundtrip, wayc, ways, TestClient, TestServer}; - -use ways::protocol::wl_seat::WlSeat as ServerSeat; - -use wayc::protocol::wl_seat; - -use std::ffi::OsStr; -use std::sync::{Arc, Mutex}; -use std::thread; - -#[test] -fn display_to_new_thread() { - let socket_name = "wayland-client-display-to-new-thread"; - - let kill_switch = Arc::new(Mutex::new(false)); - let server_kill_switch = kill_switch.clone(); - - let server_thread = thread::spawn(move || { - let mut event_loop = ways::calloop::EventLoop::<()>::new().unwrap(); - let mut display = ways::Display::new(event_loop.handle()); - display.add_socket(Some(socket_name)).unwrap(); - display.create_global::(5, |_, _| {}); - - loop { - event_loop - .dispatch(Some(Duration::from_millis(10)), &mut ()) - .unwrap(); - display.flush_clients(); - if *(server_kill_switch.lock().unwrap()) { - break; - } - } - }); - - let mut client = TestClient::new(OsStr::new(socket_name)); - - let display_clone = client.display.clone(); - - let handle = thread::spawn(move || { - let mut evq = display_clone.create_event_queue(); - let wrapper = (*display_clone).as_ref().make_wrapper(&evq.get_token()).unwrap(); - let manager = wayc::GlobalManager::new(&wrapper); - evq.sync_roundtrip().unwrap(); - // can rpovide a non-send impl - let seat = manager - .instantiate_exact::(5, |newp| newp.implement_closure(|_,_| {}, ())) - .unwrap(); - }).join().unwrap(); - - *kill_switch.lock().unwrap() = true; - - server_thread.join().unwrap(); -} - -#[test] -#[cfg(feature = "native_lib")] -fn display_from_external_on_new_thread() { - let mut server = TestServer::new(); - server.display.create_global::(5, |_, _| {}); - - let mut client = TestClient::new(&server.socket_name); - - let display_ptr = unsafe { client.display.get_display_ptr().as_mut() }.unwrap(); - - let handle = thread::spawn(move || { - let (wrapper, mut evq) = unsafe { wayc::Display::from_external_display(display_ptr) }; - // can be implemented with non-send impl - let manager = wayc::GlobalManager::new(&wrapper); - evq.sync_roundtrip().unwrap(); - // can rpovide a non-send impl - let seat = manager - .instantiate_exact::(5, |newp| newp.implement_closure(|_,_| {}, ())) - .unwrap(); - }); - - ::std::thread::sleep(::std::time::Duration::from_millis(100)); - roundtrip(&mut client, &mut server).unwrap(); - - handle.join().unwrap(); - -} diff --git a/tests/scanner.rs b/tests/scanner.rs index ab92f463dbe..d6dbf95a8a9 100644 --- a/tests/scanner.rs +++ b/tests/scanner.rs @@ -13,11 +13,8 @@ use wayland_scanner::Side; const PROTOCOL: &'static str = include_str!("./scanner_assets/protocol.xml"); -const C_INTERFACES_TARGET: &'static str = include_str!("./scanner_assets/c_interfaces.rs"); -const CLIENT_C_CODE_TARGET: &'static str = include_str!("./scanner_assets/client_c_code.rs"); -const SERVER_C_CODE_TARGET: &'static str = include_str!("./scanner_assets/server_c_code.rs"); -const CLIENT_RUST_CODE_TARGET: &'static str = include_str!("./scanner_assets/client_rust_code.rs"); -const SERVER_RUST_CODE_TARGET: &'static str = include_str!("./scanner_assets/server_rust_code.rs"); +const CLIENT_CODE_TARGET: &'static str = include_str!("./scanner_assets/client_code.rs"); +const SERVER_CODE_TARGET: &'static str = include_str!("./scanner_assets/server_code.rs"); fn print_diff(diffs: &[Difference]) { println!("Partial diffs found:"); @@ -113,44 +110,15 @@ fn run_codegen_test(generated_file_path: &Path, expected_output: &str) { } #[test] -fn c_interfaces_generation() { +fn client_code_generation() { let mut tempfile = tempfile::NamedTempFile::new().unwrap(); - wayland_scanner::generate_c_interfaces_streams(Cursor::new(PROTOCOL.as_bytes()), &mut tempfile); - run_codegen_test(tempfile.path(), C_INTERFACES_TARGET); + wayland_scanner::generate_code_streams(Cursor::new(PROTOCOL.as_bytes()), &mut tempfile, Side::Client); + run_codegen_test(tempfile.path(), CLIENT_CODE_TARGET); } #[test] -fn client_c_code_generation() { +fn server_code_generation() { let mut tempfile = tempfile::NamedTempFile::new().unwrap(); - wayland_scanner::generate_c_code_streams(Cursor::new(PROTOCOL.as_bytes()), &mut tempfile, Side::Client); - run_codegen_test(tempfile.path(), CLIENT_C_CODE_TARGET); -} - -#[test] -fn server_c_code_generation() { - let mut tempfile = tempfile::NamedTempFile::new().unwrap(); - wayland_scanner::generate_c_code_streams(Cursor::new(PROTOCOL.as_bytes()), &mut tempfile, Side::Server); - run_codegen_test(tempfile.path(), SERVER_C_CODE_TARGET); -} - -#[test] -fn client_rust_code_generation() { - let mut tempfile = tempfile::NamedTempFile::new().unwrap(); - wayland_scanner::generate_rust_code_streams( - Cursor::new(PROTOCOL.as_bytes()), - &mut tempfile, - Side::Client, - ); - run_codegen_test(tempfile.path(), CLIENT_RUST_CODE_TARGET); -} - -#[test] -fn server_rust_code_generation() { - let mut tempfile = tempfile::NamedTempFile::new().unwrap(); - wayland_scanner::generate_rust_code_streams( - Cursor::new(PROTOCOL.as_bytes()), - &mut tempfile, - Side::Server, - ); - run_codegen_test(tempfile.path(), SERVER_RUST_CODE_TARGET); + wayland_scanner::generate_code_streams(Cursor::new(PROTOCOL.as_bytes()), &mut tempfile, Side::Server); + run_codegen_test(tempfile.path(), SERVER_CODE_TARGET); } diff --git a/tests/scanner_assets/c_interfaces.rs b/tests/scanner_assets/c_interfaces.rs deleted file mode 100644 index 2dd783e562b..00000000000 --- a/tests/scanner_assets/c_interfaces.rs +++ /dev/null @@ -1,110 +0,0 @@ -use std::os::raw::{c_char, c_void}; -use wayland_sys::common::*; -const NULLPTR: *const c_void = 0 as *const c_void; -static mut types_null: [*const wl_interface; 8] = [ - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, -]; -static mut wl_foo_requests_create_bar_types: [*const wl_interface; 1] = - [unsafe { &wl_bar_interface as *const wl_interface }]; -pub static mut wl_foo_requests: [wl_message; 2] = [ - wl_message { - name: b"foo_it\0" as *const u8 as *const c_char, - signature: b"iusfh\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, - }, - wl_message { - name: b"create_bar\0" as *const u8 as *const c_char, - signature: b"n\0" as *const u8 as *const c_char, - types: unsafe { &wl_foo_requests_create_bar_types as *const _ }, - }, -]; -pub static mut wl_foo_events: [wl_message; 1] = [wl_message { - name: b"cake\0" as *const u8 as *const c_char, - signature: b"2uu\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, -}]; -pub static mut wl_foo_interface: wl_interface = wl_interface { - name: b"wl_foo\0" as *const u8 as *const c_char, - version: 3, - request_count: 2, - requests: unsafe { &wl_foo_requests as *const _ }, - event_count: 1, - events: unsafe { &wl_foo_events as *const _ }, -}; -static mut wl_bar_requests_bar_delivery_types: [*const wl_interface; 4] = [ - NULLPTR as *const wl_interface, - unsafe { &wl_foo_interface as *const wl_interface }, - NULLPTR as *const wl_interface, - NULLPTR as *const wl_interface, -]; -pub static mut wl_bar_requests: [wl_message; 3] = [ - wl_message { - name: b"bar_delivery\0" as *const u8 as *const c_char, - signature: b"2uoa?a\0" as *const u8 as *const c_char, - types: unsafe { &wl_bar_requests_bar_delivery_types as *const _ }, - }, - wl_message { - name: b"release\0" as *const u8 as *const c_char, - signature: b"\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, - }, - wl_message { - name: b"self\0" as *const u8 as *const c_char, - signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, - }, -]; -pub static mut wl_bar_events: [wl_message; 1] = [wl_message { - name: b"self\0" as *const u8 as *const c_char, - signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, -}]; -pub static mut wl_bar_interface: wl_interface = wl_interface { - name: b"wl_bar\0" as *const u8 as *const c_char, - version: 1, - request_count: 3, - requests: unsafe { &wl_bar_requests as *const _ }, - event_count: 1, - events: unsafe { &wl_bar_events as *const _ }, -}; -pub static mut wl_display_interface: wl_interface = wl_interface { - name: b"wl_display\0" as *const u8 as *const c_char, - version: 1, - request_count: 0, - requests: NULLPTR as *const wl_message, - event_count: 0, - events: NULLPTR as *const wl_message, -}; -pub static mut wl_registry_requests: [wl_message; 1] = [wl_message { - name: b"bind\0" as *const u8 as *const c_char, - signature: b"usun\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, -}]; -pub static mut wl_registry_interface: wl_interface = wl_interface { - name: b"wl_registry\0" as *const u8 as *const c_char, - version: 1, - request_count: 1, - requests: unsafe { &wl_registry_requests as *const _ }, - event_count: 0, - events: NULLPTR as *const wl_message, -}; -pub static mut wl_callback_events: [wl_message; 1] = [wl_message { - name: b"done\0" as *const u8 as *const c_char, - signature: b"u\0" as *const u8 as *const c_char, - types: unsafe { &types_null as *const _ }, -}]; -pub static mut wl_callback_interface: wl_interface = wl_interface { - name: b"wl_callback\0" as *const u8 as *const c_char, - version: 1, - request_count: 0, - requests: NULLPTR as *const wl_message, - event_count: 1, - events: unsafe { &wl_callback_events as *const _ }, -}; diff --git a/tests/scanner_assets/client_c_code.rs b/tests/scanner_assets/client_code.rs similarity index 87% rename from tests/scanner_assets/client_c_code.rs rename to tests/scanner_assets/client_code.rs index 531b2484af0..0ed086d5863 100644 --- a/tests/scanner_assets/client_c_code.rs +++ b/tests/scanner_assets/client_code.rs @@ -1,11 +1,24 @@ +use std::os::raw::{c_char, c_void}; +const NULLPTR: *const c_void = 0 as *const c_void; +static mut types_null: [*const sys::common::wl_interface; 8] = [ + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, +]; #[doc = "Interface for fooing\n\nThis is the dedicated interface for doing foos over any\nkind of other foos."] pub mod wl_foo { use super::sys::client::*; - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewProxy, Object, ObjectMetadata, Proxy, NULLPTR, }; + use std::os::raw::c_char; #[doc = "Possible cake kinds\n\nList of the possible kind of cake supported by the protocol."] #[repr(u32)] #[derive(Copy, Clone, Debug, PartialEq)] @@ -283,7 +296,7 @@ pub mod wl_foo { const NAME: &'static str = "wl_foo"; const VERSION: u32 = 3; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_foo_interface } + unsafe { &wl_foo_interface } } } impl WlFoo { @@ -336,15 +349,46 @@ pub mod wl_foo { pub const REQ_CREATE_BAR_SINCE: u32 = 1u32; #[doc = r" The minimal object version supporting this event"] pub const EVT_CAKE_SINCE: u32 = 2u32; + static mut wl_foo_requests_create_bar_types: [*const wl_interface; 1] = + [unsafe { &super::wl_bar::wl_bar_interface as *const wl_interface }]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_foo_requests: [wl_message; 2] = [ + wl_message { + name: b"foo_it\0" as *const u8 as *const c_char, + signature: b"iusfh\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + wl_message { + name: b"create_bar\0" as *const u8 as *const c_char, + signature: b"n\0" as *const u8 as *const c_char, + types: unsafe { &wl_foo_requests_create_bar_types as *const _ }, + }, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_foo_events: [wl_message; 1] = [wl_message { + name: b"cake\0" as *const u8 as *const c_char, + signature: b"2uu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_foo_interface: wl_interface = wl_interface { + name: b"wl_foo\0" as *const u8 as *const c_char, + version: 3, + request_count: 2, + requests: unsafe { &wl_foo_requests as *const _ }, + event_count: 1, + events: unsafe { &wl_foo_events as *const _ }, + }; } #[doc = "Interface for bars\n\nThis interface allows you to bar your foos."] pub mod wl_bar { use super::sys::client::*; - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewProxy, Object, ObjectMetadata, Proxy, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface"] BarDelivery { @@ -726,7 +770,7 @@ pub mod wl_bar { const NAME: &'static str = "wl_bar"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_bar_interface } + unsafe { &wl_bar_interface } } } impl WlBar { @@ -821,15 +865,55 @@ pub mod wl_bar { pub const REQ_SELF_SINCE: u32 = 2u32; #[doc = r" The minimal object version supporting this event"] pub const EVT_SELF_SINCE: u32 = 2u32; + static mut wl_bar_requests_bar_delivery_types: [*const wl_interface; 4] = [ + NULLPTR as *const wl_interface, + unsafe { &super::wl_foo::wl_foo_interface as *const wl_interface }, + NULLPTR as *const wl_interface, + NULLPTR as *const wl_interface, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_bar_requests: [wl_message; 3] = [ + wl_message { + name: b"bar_delivery\0" as *const u8 as *const c_char, + signature: b"2uoa?a\0" as *const u8 as *const c_char, + types: unsafe { &wl_bar_requests_bar_delivery_types as *const _ }, + }, + wl_message { + name: b"release\0" as *const u8 as *const c_char, + signature: b"\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + wl_message { + name: b"self\0" as *const u8 as *const c_char, + signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_bar_events: [wl_message; 1] = [wl_message { + name: b"self\0" as *const u8 as *const c_char, + signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_bar_interface: wl_interface = wl_interface { + name: b"wl_bar\0" as *const u8 as *const c_char, + version: 1, + request_count: 3, + requests: unsafe { &wl_bar_requests as *const _ }, + event_count: 1, + events: unsafe { &wl_bar_events as *const _ }, + }; } #[doc = "core global object\n\nThis global is special and should only generate code client-side, not server-side."] pub mod wl_display { use super::sys::client::*; - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewProxy, Object, ObjectMetadata, Proxy, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc(hidden)] __nonexhaustive, @@ -958,7 +1042,7 @@ pub mod wl_display { const NAME: &'static str = "wl_display"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_display_interface } + unsafe { &wl_display_interface } } } impl WlDisplay {} @@ -972,15 +1056,25 @@ pub mod wl_display { } } } + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_display_interface: wl_interface = wl_interface { + name: b"wl_display\0" as *const u8 as *const c_char, + version: 1, + request_count: 0, + requests: NULLPTR as *const wl_message, + event_count: 0, + events: NULLPTR as *const wl_message, + }; } #[doc = "global registry object\n\nThis global is special and should only generate code client-side, not server-side."] pub mod wl_registry { use super::sys::client::*; - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewProxy, Object, ObjectMetadata, Proxy, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc = "bind an object to the display\n\nThis request is a special code-path, as its new-id argument as no target type."] Bind { @@ -1140,7 +1234,7 @@ pub mod wl_registry { const NAME: &'static str = "wl_registry"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_registry_interface } + unsafe { &wl_registry_interface } } } impl WlRegistry { @@ -1173,15 +1267,31 @@ pub mod wl_registry { } #[doc = r" The minimal object version supporting this request"] pub const REQ_BIND_SINCE: u32 = 1u32; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_registry_requests: [wl_message; 1] = [wl_message { + name: b"bind\0" as *const u8 as *const c_char, + signature: b"usun\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_registry_interface: wl_interface = wl_interface { + name: b"wl_registry\0" as *const u8 as *const c_char, + version: 1, + request_count: 1, + requests: unsafe { &wl_registry_requests as *const _ }, + event_count: 0, + events: NULLPTR as *const wl_message, + }; } #[doc = "callback object\n\nThis object has a special behavior regarding its destructor."] pub mod wl_callback { use super::sys::client::*; - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewProxy, Object, ObjectMetadata, Proxy, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc(hidden)] __nonexhaustive, @@ -1337,7 +1447,7 @@ pub mod wl_callback { const NAME: &'static str = "wl_callback"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_callback_interface } + unsafe { &wl_callback_interface } } } impl WlCallback {} @@ -1357,4 +1467,19 @@ pub mod wl_callback { } #[doc = r" The minimal object version supporting this event"] pub const EVT_DONE_SINCE: u32 = 1u32; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_callback_events: [wl_message; 1] = [wl_message { + name: b"done\0" as *const u8 as *const c_char, + signature: b"u\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_callback_interface: wl_interface = wl_interface { + name: b"wl_callback\0" as *const u8 as *const c_char, + version: 1, + request_count: 0, + requests: NULLPTR as *const wl_message, + event_count: 1, + events: unsafe { &wl_callback_events as *const _ }, + }; } diff --git a/tests/scanner_assets/client_rust_code.rs b/tests/scanner_assets/client_rust_code.rs deleted file mode 100644 index e7f6ec725ad..00000000000 --- a/tests/scanner_assets/client_rust_code.rs +++ /dev/null @@ -1,1078 +0,0 @@ -#[doc = "Interface for fooing\n\nThis is the dedicated interface for doing foos over any\nkind of other foos."] -pub mod wl_foo { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, - }; - #[doc = "Possible cake kinds\n\nList of the possible kind of cake supported by the protocol."] - #[repr(u32)] - #[derive(Copy, Clone, Debug, PartialEq)] - pub enum CakeKind { - #[doc = "mild cake without much flavor"] - Basic = 0, - #[doc = "spicy cake to burn your tongue"] - Spicy = 1, - #[doc = "fruity cake to get vitamins"] - Fruity = 2, - #[doc(hidden)] - __nonexhaustive, - } - impl CakeKind { - pub fn from_raw(n: u32) -> Option { - match n { - 0 => Some(CakeKind::Basic), - 1 => Some(CakeKind::Spicy), - 2 => Some(CakeKind::Fruity), - _ => Option::None, - } - } - pub fn to_raw(&self) -> u32 { - *self as u32 - } - } - bitflags! { # [ doc = "possible delivery modes" ] pub struct DeliveryKind : u32 { # [ doc = "pick your cake up yourself" ] const PickUp = 1 ; # [ doc = "flying drone delivery" ] const Drone = 2 ; # [ doc = "because we fear nothing" ] const Catapult = 4 ; } } - impl DeliveryKind { - pub fn from_raw(n: u32) -> Option { - Some(DeliveryKind::from_bits_truncate(n)) - } - pub fn to_raw(&self) -> u32 { - self.bits() - } - } - pub enum Request { - #[doc = "do some foo\n\nThis will do some foo with its args."] - FooIt { - number: i32, - unumber: u32, - text: String, - float: f64, - file: ::std::os::unix::io::RawFd, - }, - #[doc = "create a bar\n\nCreate a bar which will do its bar job."] - CreateBar { id: super::wl_bar::WlBar }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[ - super::MessageDesc { - name: "foo_it", - since: 1, - signature: &[ - super::ArgumentType::Int, - super::ArgumentType::Uint, - super::ArgumentType::Str, - super::ArgumentType::Fixed, - super::ArgumentType::Fd, - ], - }, - super::MessageDesc { - name: "create_bar", - since: 1, - signature: &[super::ArgumentType::NewId], - }, - ]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::FooIt { .. } => 0, - Request::CreateBar { .. } => 1, - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::FooIt { .. } => 1, - Request::CreateBar { .. } => 1, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - 1 => Some(Object::from_interface::( - version, - meta.child(), - )), - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Request::from_raw can not be used Client-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Request::__nonexhaustive => unreachable!(), - Request::FooIt { - number, - unumber, - text, - float, - file, - } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![ - Argument::Int(number), - Argument::Uint(unumber), - Argument::Str(unsafe { ::std::ffi::CString::from_vec_unchecked(text.into()) }), - Argument::Fixed((float * 256.) as i32), - Argument::Fd(file), - ], - }, - Request::CreateBar { id } => Message { - sender_id: sender_id, - opcode: 1, - args: vec![Argument::NewId(id.as_ref().id())], - }, - } - } - } - pub enum Event { - #[doc = "a cake is possible\n\nThe server advertises that a kind of cake is available\n\nOnly available since version 2 of the interface"] - Cake { kind: CakeKind, amount: u32 }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "cake", - since: 2, - signature: &[super::ArgumentType::Uint, super::ArgumentType::Uint], - }]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Cake { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Cake { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - 0 => { - let mut args = msg.args.into_iter(); - Ok(Event::Cake { - kind: { - if let Some(Argument::Uint(val)) = args.next() { - CakeKind::from_raw(val).ok_or(())? - } else { - return Err(()); - } - }, - amount: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - }) - } - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Event::into_raw can not be used Client-side.") - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlFoo(Proxy); - impl AsRef> for WlFoo { - #[inline] - fn as_ref(&self) -> &Proxy { - &self.0 - } - } - impl From> for WlFoo { - #[inline] - fn from(value: Proxy) -> Self { - WlFoo(value) - } - } - impl From for Proxy { - #[inline] - fn from(value: WlFoo) -> Self { - value.0 - } - } - impl Interface for WlFoo { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_foo"; - const VERSION: u32 = 3; - } - impl WlFoo { - #[doc = "do some foo\n\nThis will do some foo with its args."] - pub fn foo_it( - &self, - number: i32, - unumber: u32, - text: String, - float: f64, - file: ::std::os::unix::io::RawFd, - ) -> () { - let msg = Request::FooIt { - number: number, - unumber: unumber, - text: text, - float: float, - file: file, - }; - self.0.send(msg); - } - #[doc = "create a bar\n\nCreate a bar which will do its bar job."] - pub fn create_bar(&self, implementor: F) -> Result - where - F: FnOnce(NewProxy) -> super::wl_bar::WlBar, - { - let msg = Request::CreateBar { - id: self.0.child_placeholder(), - }; - self.0.send_constructor(msg, implementor, None) - } - } - #[doc = r" An interface for handling events."] - pub trait EventHandler { - #[doc = "a cake is possible\n\nThe server advertises that a kind of cake is available\n\nOnly available since version 2 of the interface."] - fn cake(&mut self, object: WlFoo, kind: CakeKind, amount: u32) {} - } - impl HandledBy for WlFoo { - #[inline] - fn handle(__handler: &mut T, event: Event, __object: Self) { - match event { - Event::Cake { kind, amount } => __handler.cake(__object, kind, amount), - Event::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this request"] - pub const REQ_FOO_IT_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_CREATE_BAR_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this event"] - pub const EVT_CAKE_SINCE: u32 = 2u32; -} -#[doc = "Interface for bars\n\nThis interface allows you to bar your foos."] -pub mod wl_bar { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, - }; - pub enum Request { - #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface"] - BarDelivery { - kind: super::wl_foo::DeliveryKind, - target: super::wl_foo::WlFoo, - metadata: Vec, - metametadata: Option>, - }, - #[doc = "release this bar\n\nNotify the compositor that you have finished using this bar.\n\nThis is a destructor, once sent this object cannot be used any longer."] - Release, - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis request tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface"] - _Self { - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[ - super::MessageDesc { - name: "bar_delivery", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Object, - super::ArgumentType::Array, - super::ArgumentType::Array, - ], - }, - super::MessageDesc { - name: "release", - since: 1, - signature: &[], - }, - super::MessageDesc { - name: "self", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - ], - }, - ]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::Release => true, - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::BarDelivery { .. } => 0, - Request::Release => 1, - Request::_Self { .. } => 2, - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::BarDelivery { .. } => 2, - Request::Release => 1, - Request::_Self { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Request::from_raw can not be used Client-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Request::__nonexhaustive => unreachable!(), - Request::BarDelivery { - kind, - target, - metadata, - metametadata, - } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![ - Argument::Uint(kind.to_raw()), - Argument::Object(target.as_ref().id()), - Argument::Array(metadata), - Argument::Array(metametadata.unwrap_or_else(Vec::new)), - ], - }, - Request::Release => Message { - sender_id: sender_id, - opcode: 1, - args: vec![], - }, - Request::_Self { - _self, - _mut, - object, - ___object, - handler, - ___handler, - request, - event, - } => Message { - sender_id: sender_id, - opcode: 2, - args: vec![ - Argument::Uint(_self), - Argument::Uint(_mut), - Argument::Uint(object), - Argument::Uint(___object), - Argument::Uint(handler), - Argument::Uint(___handler), - Argument::Uint(request), - Argument::Uint(event), - ], - }, - } - } - } - pub enum Event { - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis event tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface"] - _Self { - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "self", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - ], - }]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::_Self { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::_Self { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - 0 => { - let mut args = msg.args.into_iter(); - Ok(Event::_Self { - _self: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - _mut: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - object: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - ___object: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - handler: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - ___handler: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - request: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - event: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - }) - } - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Event::into_raw can not be used Client-side.") - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlBar(Proxy); - impl AsRef> for WlBar { - #[inline] - fn as_ref(&self) -> &Proxy { - &self.0 - } - } - impl From> for WlBar { - #[inline] - fn from(value: Proxy) -> Self { - WlBar(value) - } - } - impl From for Proxy { - #[inline] - fn from(value: WlBar) -> Self { - value.0 - } - } - impl Interface for WlBar { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_bar"; - const VERSION: u32 = 1; - } - impl WlBar { - #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface."] - pub fn bar_delivery( - &self, - kind: super::wl_foo::DeliveryKind, - target: &super::wl_foo::WlFoo, - metadata: Vec, - metametadata: Option>, - ) -> () { - let msg = Request::BarDelivery { - kind: kind, - target: target.clone(), - metadata: metadata, - metametadata: metametadata, - }; - self.0.send(msg); - } - #[doc = "release this bar\n\nNotify the compositor that you have finished using this bar.\n\nThis is a destructor, you cannot send requests to this object any longer once this method is called."] - pub fn release(&self) -> () { - let msg = Request::Release; - self.0.send(msg); - } - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis request tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface."] - pub fn _self( - &self, - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - ) -> () { - let msg = Request::_Self { - _self: _self, - _mut: _mut, - object: object, - ___object: ___object, - handler: handler, - ___handler: ___handler, - request: request, - event: event, - }; - self.0.send(msg); - } - } - #[doc = r" An interface for handling events."] - pub trait EventHandler { - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis event tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface."] - fn _self( - &mut self, - object: WlBar, - _self: u32, - _mut: u32, - _object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - ) { - } - } - impl HandledBy for WlBar { - #[inline] - fn handle(__handler: &mut T, event: Event, __object: Self) { - match event { - Event::_Self { - _self, - _mut, - object, - ___object, - handler, - ___handler, - request, - event, - } => __handler._self( - __object, _self, _mut, object, ___object, handler, ___handler, request, event, - ), - Event::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this request"] - pub const REQ_BAR_DELIVERY_SINCE: u32 = 2u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_RELEASE_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_SELF_SINCE: u32 = 2u32; - #[doc = r" The minimal object version supporting this event"] - pub const EVT_SELF_SINCE: u32 = 2u32; -} -#[doc = "core global object\n\nThis global is special and should only generate code client-side, not server-side."] -pub mod wl_display { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, - }; - pub enum Request { - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Request::from_raw can not be used Client-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Request::__nonexhaustive => unreachable!(), - } - } - } - pub enum Event { - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Event::into_raw can not be used Client-side.") - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlDisplay(Proxy); - impl AsRef> for WlDisplay { - #[inline] - fn as_ref(&self) -> &Proxy { - &self.0 - } - } - impl From> for WlDisplay { - #[inline] - fn from(value: Proxy) -> Self { - WlDisplay(value) - } - } - impl From for Proxy { - #[inline] - fn from(value: WlDisplay) -> Self { - value.0 - } - } - impl Interface for WlDisplay { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_display"; - const VERSION: u32 = 1; - } - impl WlDisplay {} - #[doc = r" An interface for handling events."] - pub trait EventHandler {} - impl HandledBy for WlDisplay { - #[inline] - fn handle(__handler: &mut T, event: Event, __object: Self) { - match event { - Event::__nonexhaustive => unreachable!(), - } - } - } -} -#[doc = "global registry object\n\nThis global is special and should only generate code client-side, not server-side."] -pub mod wl_registry { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, - }; - pub enum Request { - #[doc = "bind an object to the display\n\nThis request is a special code-path, as its new-id argument as no target type."] - Bind { - name: u32, - id: (String, u32, AnonymousObject), - }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "bind", - since: 1, - signature: &[super::ArgumentType::Uint, super::ArgumentType::NewId], - }]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::Bind { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::Bind { .. } => 1, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Request::from_raw can not be used Client-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Request::__nonexhaustive => unreachable!(), - Request::Bind { name, id } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![ - Argument::Uint(name), - Argument::Str(unsafe { ::std::ffi::CString::from_vec_unchecked(id.0.into()) }), - Argument::Uint(id.1), - Argument::NewId(id.2.as_ref().id()), - ], - }, - } - } - } - pub enum Event { - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Event::into_raw can not be used Client-side.") - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlRegistry(Proxy); - impl AsRef> for WlRegistry { - #[inline] - fn as_ref(&self) -> &Proxy { - &self.0 - } - } - impl From> for WlRegistry { - #[inline] - fn from(value: Proxy) -> Self { - WlRegistry(value) - } - } - impl From for Proxy { - #[inline] - fn from(value: WlRegistry) -> Self { - value.0 - } - } - impl Interface for WlRegistry { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_registry"; - const VERSION: u32 = 1; - } - impl WlRegistry { - #[doc = "bind an object to the display\n\nThis request is a special code-path, as its new-id argument as no target type."] - pub fn bind>, F>( - &self, - version: u32, - name: u32, - implementor: F, - ) -> Result - where - F: FnOnce(NewProxy) -> T, - { - let msg = Request::Bind { - name: name, - id: (T::NAME.into(), version, self.0.child_placeholder()), - }; - self.0.send_constructor(msg, implementor, Some(version)) - } - } - #[doc = r" An interface for handling events."] - pub trait EventHandler {} - impl HandledBy for WlRegistry { - #[inline] - fn handle(__handler: &mut T, event: Event, __object: Self) { - match event { - Event::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this request"] - pub const REQ_BIND_SINCE: u32 = 1u32; -} -#[doc = "callback object\n\nThis object has a special behavior regarding its destructor."] -pub mod wl_callback { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewProxy, Object, ObjectMetadata, Proxy, - }; - pub enum Request { - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Request::from_raw can not be used Client-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Request::__nonexhaustive => unreachable!(), - } - } - } - pub enum Event { - #[doc = "done event\n\nThis event is actually a destructor, but the protocol XML has no way of specifying it.\nAs such, the scanner should consider wl_callback.done as a special case.\n\nThis is a destructor, once received this object cannot be used any longer."] - Done { callback_data: u32 }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "done", - since: 1, - signature: &[super::ArgumentType::Uint], - }]; - type Map = super::ProxyMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => true, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => 1, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - 0 => { - let mut args = msg.args.into_iter(); - Ok(Event::Done { - callback_data: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - }) - } - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Event::into_raw can not be used Client-side.") - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlCallback(Proxy); - impl AsRef> for WlCallback { - #[inline] - fn as_ref(&self) -> &Proxy { - &self.0 - } - } - impl From> for WlCallback { - #[inline] - fn from(value: Proxy) -> Self { - WlCallback(value) - } - } - impl From for Proxy { - #[inline] - fn from(value: WlCallback) -> Self { - value.0 - } - } - impl Interface for WlCallback { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_callback"; - const VERSION: u32 = 1; - } - impl WlCallback {} - #[doc = r" An interface for handling events."] - pub trait EventHandler { - #[doc = "done event\n\nThis event is actually a destructor, but the protocol XML has no way of specifying it.\nAs such, the scanner should consider wl_callback.done as a special case.\n\nThis is a destructor, you cannot send requests to this object any longer once this method is called."] - fn done(&mut self, object: WlCallback, callback_data: u32) {} - } - impl HandledBy for WlCallback { - #[inline] - fn handle(__handler: &mut T, event: Event, __object: Self) { - match event { - Event::Done { callback_data } => __handler.done(__object, callback_data), - Event::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this event"] - pub const EVT_DONE_SINCE: u32 = 1u32; -} diff --git a/tests/scanner_assets/server_c_code.rs b/tests/scanner_assets/server_code.rs similarity index 87% rename from tests/scanner_assets/server_c_code.rs rename to tests/scanner_assets/server_code.rs index c6f8cb6cc82..62cff25fa83 100644 --- a/tests/scanner_assets/server_c_code.rs +++ b/tests/scanner_assets/server_code.rs @@ -1,11 +1,24 @@ +use std::os::raw::{c_char, c_void}; +const NULLPTR: *const c_void = 0 as *const c_void; +static mut types_null: [*const sys::common::wl_interface; 8] = [ + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, + NULLPTR as *const sys::common::wl_interface, +]; #[doc = "Interface for fooing\n\nThis is the dedicated interface for doing foos over any\nkind of other foos."] pub mod wl_foo { - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::sys::server::*; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewResource, Object, ObjectMetadata, Resource, NULLPTR, }; + use std::os::raw::c_char; #[doc = "Possible cake kinds\n\nList of the possible kind of cake supported by the protocol."] #[repr(u32)] #[derive(Copy, Clone, Debug, PartialEq)] @@ -188,19 +201,8 @@ pub mod wl_foo { let _args = ::std::slice::from_raw_parts(args, 1); Ok(Request::CreateBar { id: { - let client = - ffi_dispatch!(WAYLAND_SERVER_HANDLE, wl_resource_get_client, obj as *mut _); - let version = - ffi_dispatch!(WAYLAND_SERVER_HANDLE, wl_resource_get_version, obj as *mut _); - let new_ptr = ffi_dispatch!( - WAYLAND_SERVER_HANDLE, - wl_resource_create, - client, - super::wl_bar::WlBar::c_interface(), - version, - _args[0].n - ); - NewResource::::from_c_ptr(new_ptr) + let me = Resource::::from_c_ptr(obj as *mut _); + me.make_child_for::(_args[0].n).unwrap() }, }) } @@ -311,7 +313,7 @@ pub mod wl_foo { const NAME: &'static str = "wl_foo"; const VERSION: u32 = 3; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_foo_interface } + unsafe { &wl_foo_interface } } } impl WlFoo { @@ -362,15 +364,46 @@ pub mod wl_foo { pub const REQ_CREATE_BAR_SINCE: u32 = 1u32; #[doc = r" The minimal object version supporting this event"] pub const EVT_CAKE_SINCE: u32 = 2u32; + static mut wl_foo_requests_create_bar_types: [*const wl_interface; 1] = + [unsafe { &super::wl_bar::wl_bar_interface as *const wl_interface }]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_foo_requests: [wl_message; 2] = [ + wl_message { + name: b"foo_it\0" as *const u8 as *const c_char, + signature: b"iusfh\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + wl_message { + name: b"create_bar\0" as *const u8 as *const c_char, + signature: b"n\0" as *const u8 as *const c_char, + types: unsafe { &wl_foo_requests_create_bar_types as *const _ }, + }, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_foo_events: [wl_message; 1] = [wl_message { + name: b"cake\0" as *const u8 as *const c_char, + signature: b"2uu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_foo_interface: wl_interface = wl_interface { + name: b"wl_foo\0" as *const u8 as *const c_char, + version: 3, + request_count: 2, + requests: unsafe { &wl_foo_requests as *const _ }, + event_count: 1, + events: unsafe { &wl_foo_events as *const _ }, + }; } #[doc = "Interface for bars\n\nThis interface allows you to bar your foos."] pub mod wl_bar { - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::sys::server::*; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewResource, Object, ObjectMetadata, Resource, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface"] BarDelivery { @@ -760,7 +793,7 @@ pub mod wl_bar { const NAME: &'static str = "wl_bar"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_bar_interface } + unsafe { &wl_bar_interface } } } impl WlBar { @@ -853,15 +886,55 @@ pub mod wl_bar { pub const REQ_SELF_SINCE: u32 = 2u32; #[doc = r" The minimal object version supporting this event"] pub const EVT_SELF_SINCE: u32 = 2u32; + static mut wl_bar_requests_bar_delivery_types: [*const wl_interface; 4] = [ + NULLPTR as *const wl_interface, + unsafe { &super::wl_foo::wl_foo_interface as *const wl_interface }, + NULLPTR as *const wl_interface, + NULLPTR as *const wl_interface, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_bar_requests: [wl_message; 3] = [ + wl_message { + name: b"bar_delivery\0" as *const u8 as *const c_char, + signature: b"2uoa?a\0" as *const u8 as *const c_char, + types: unsafe { &wl_bar_requests_bar_delivery_types as *const _ }, + }, + wl_message { + name: b"release\0" as *const u8 as *const c_char, + signature: b"\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + wl_message { + name: b"self\0" as *const u8 as *const c_char, + signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }, + ]; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_bar_events: [wl_message; 1] = [wl_message { + name: b"self\0" as *const u8 as *const c_char, + signature: b"2uuuuuuuu\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_bar_interface: wl_interface = wl_interface { + name: b"wl_bar\0" as *const u8 as *const c_char, + version: 1, + request_count: 3, + requests: unsafe { &wl_bar_requests as *const _ }, + event_count: 1, + events: unsafe { &wl_bar_events as *const _ }, + }; } #[doc = "callback object\n\nThis object has a special behavior regarding its destructor."] pub mod wl_callback { - use super::sys::common::{wl_argument, wl_array, wl_interface}; + use super::sys::common::{wl_argument, wl_array, wl_interface, wl_message}; use super::sys::server::*; use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, + types_null, AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, + MessageGroup, NewResource, Object, ObjectMetadata, Resource, NULLPTR, }; + use std::os::raw::c_char; pub enum Request { #[doc(hidden)] __nonexhaustive, @@ -1009,7 +1082,7 @@ pub mod wl_callback { const NAME: &'static str = "wl_callback"; const VERSION: u32 = 1; fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::wl_callback_interface } + unsafe { &wl_callback_interface } } } impl WlCallback { @@ -1033,4 +1106,19 @@ pub mod wl_callback { } #[doc = r" The minimal object version supporting this event"] pub const EVT_DONE_SINCE: u32 = 1u32; + #[doc = r" C-representation of the messages of this interface, for interop"] + pub static mut wl_callback_events: [wl_message; 1] = [wl_message { + name: b"done\0" as *const u8 as *const c_char, + signature: b"u\0" as *const u8 as *const c_char, + types: unsafe { &types_null as *const _ }, + }]; + #[doc = r" C representation of this interface, for interop"] + pub static mut wl_callback_interface: wl_interface = wl_interface { + name: b"wl_callback\0" as *const u8 as *const c_char, + version: 1, + request_count: 0, + requests: NULLPTR as *const wl_message, + event_count: 1, + events: unsafe { &wl_callback_events as *const _ }, + }; } diff --git a/tests/scanner_assets/server_rust_code.rs b/tests/scanner_assets/server_rust_code.rs deleted file mode 100644 index ee056446089..00000000000 --- a/tests/scanner_assets/server_rust_code.rs +++ /dev/null @@ -1,834 +0,0 @@ -#[doc = "Interface for fooing\n\nThis is the dedicated interface for doing foos over any\nkind of other foos."] -pub mod wl_foo { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, - }; - #[doc = "Possible cake kinds\n\nList of the possible kind of cake supported by the protocol."] - #[repr(u32)] - #[derive(Copy, Clone, Debug, PartialEq)] - pub enum CakeKind { - #[doc = "mild cake without much flavor"] - Basic = 0, - #[doc = "spicy cake to burn your tongue"] - Spicy = 1, - #[doc = "fruity cake to get vitamins"] - Fruity = 2, - #[doc(hidden)] - __nonexhaustive, - } - impl CakeKind { - pub fn from_raw(n: u32) -> Option { - match n { - 0 => Some(CakeKind::Basic), - 1 => Some(CakeKind::Spicy), - 2 => Some(CakeKind::Fruity), - _ => Option::None, - } - } - pub fn to_raw(&self) -> u32 { - *self as u32 - } - } - bitflags! { # [ doc = "possible delivery modes" ] pub struct DeliveryKind : u32 { # [ doc = "pick your cake up yourself" ] const PickUp = 1 ; # [ doc = "flying drone delivery" ] const Drone = 2 ; # [ doc = "because we fear nothing" ] const Catapult = 4 ; } } - impl DeliveryKind { - pub fn from_raw(n: u32) -> Option { - Some(DeliveryKind::from_bits_truncate(n)) - } - pub fn to_raw(&self) -> u32 { - self.bits() - } - } - pub enum Request { - #[doc = "do some foo\n\nThis will do some foo with its args."] - FooIt { - number: i32, - unumber: u32, - text: String, - float: f64, - file: ::std::os::unix::io::RawFd, - }, - #[doc = "create a bar\n\nCreate a bar which will do its bar job."] - CreateBar { id: NewResource }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[ - super::MessageDesc { - name: "foo_it", - since: 1, - signature: &[ - super::ArgumentType::Int, - super::ArgumentType::Uint, - super::ArgumentType::Str, - super::ArgumentType::Fixed, - super::ArgumentType::Fd, - ], - }, - super::MessageDesc { - name: "create_bar", - since: 1, - signature: &[super::ArgumentType::NewId], - }, - ]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::FooIt { .. } => 0, - Request::CreateBar { .. } => 1, - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::FooIt { .. } => 1, - Request::CreateBar { .. } => 1, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - 1 => Some(Object::from_interface::( - version, - meta.child(), - )), - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - 0 => { - let mut args = msg.args.into_iter(); - Ok(Request::FooIt { - number: { - if let Some(Argument::Int(val)) = args.next() { - val - } else { - return Err(()); - } - }, - unumber: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - text: { - if let Some(Argument::Str(val)) = args.next() { - let s = String::from_utf8(val.into_bytes()) - .unwrap_or_else(|e| String::from_utf8_lossy(&e.into_bytes()).into()); - s - } else { - return Err(()); - } - }, - float: { - if let Some(Argument::Fixed(val)) = args.next() { - (val as f64) / 256. - } else { - return Err(()); - } - }, - file: { - if let Some(Argument::Fd(val)) = args.next() { - val - } else { - return Err(()); - } - }, - }) - } - 1 => { - let mut args = msg.args.into_iter(); - Ok(Request::CreateBar { - id: { - if let Some(Argument::NewId(val)) = args.next() { - map.get_new(val).ok_or(())? - } else { - return Err(()); - } - }, - }) - } - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Request::into_raw can not be used Server-side.") - } - } - pub enum Event { - #[doc = "a cake is possible\n\nThe server advertises that a kind of cake is available\n\nOnly available since version 2 of the interface"] - Cake { kind: CakeKind, amount: u32 }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "cake", - since: 2, - signature: &[super::ArgumentType::Uint, super::ArgumentType::Uint], - }]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Cake { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Cake { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Event::from_raw can not be used Server-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Event::__nonexhaustive => unreachable!(), - Event::Cake { kind, amount } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![Argument::Uint(kind.to_raw()), Argument::Uint(amount)], - }, - } - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlFoo(Resource); - impl AsRef> for WlFoo { - #[inline] - fn as_ref(&self) -> &Resource { - &self.0 - } - } - impl From> for WlFoo { - #[inline] - fn from(value: Resource) -> Self { - WlFoo(value) - } - } - impl From for Resource { - #[inline] - fn from(value: WlFoo) -> Self { - value.0 - } - } - impl Interface for WlFoo { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_foo"; - const VERSION: u32 = 3; - } - impl WlFoo { - #[doc = "a cake is possible\n\nThe server advertises that a kind of cake is available\n\nOnly available since version 2 of the interface."] - pub fn cake(&self, kind: CakeKind, amount: u32) -> () { - let msg = Event::Cake { - kind: kind, - amount: amount, - }; - self.0.send(msg); - } - } - #[doc = r" An interface for handling requests."] - pub trait RequestHandler { - #[doc = "do some foo\n\nThis will do some foo with its args."] - fn foo_it( - &mut self, - object: WlFoo, - number: i32, - unumber: u32, - text: String, - float: f64, - file: ::std::os::unix::io::RawFd, - ) { - } - #[doc = "create a bar\n\nCreate a bar which will do its bar job."] - fn create_bar(&mut self, object: WlFoo, id: NewResource) {} - } - impl HandledBy for WlFoo { - #[inline] - fn handle(__handler: &mut T, request: Request, __object: Self) { - match request { - Request::FooIt { - number, - unumber, - text, - float, - file, - } => __handler.foo_it(__object, number, unumber, text, float, file), - Request::CreateBar { id } => __handler.create_bar(__object, id), - Request::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this request"] - pub const REQ_FOO_IT_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_CREATE_BAR_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this event"] - pub const EVT_CAKE_SINCE: u32 = 2u32; -} -#[doc = "Interface for bars\n\nThis interface allows you to bar your foos."] -pub mod wl_bar { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, - }; - pub enum Request { - #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface"] - BarDelivery { - kind: super::wl_foo::DeliveryKind, - target: super::wl_foo::WlFoo, - metadata: Vec, - metametadata: Option>, - }, - #[doc = "release this bar\n\nNotify the compositor that you have finished using this bar.\n\nThis is a destructor, once received this object cannot be used any longer."] - Release, - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis request tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface"] - _Self { - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[ - super::MessageDesc { - name: "bar_delivery", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Object, - super::ArgumentType::Array, - super::ArgumentType::Array, - ], - }, - super::MessageDesc { - name: "release", - since: 1, - signature: &[], - }, - super::MessageDesc { - name: "self", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - ], - }, - ]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::Release => true, - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::BarDelivery { .. } => 0, - Request::Release => 1, - Request::_Self { .. } => 2, - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - Request::BarDelivery { .. } => 2, - Request::Release => 1, - Request::_Self { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - 0 => { - let mut args = msg.args.into_iter(); - Ok(Request::BarDelivery { - kind: { - if let Some(Argument::Uint(val)) = args.next() { - super::wl_foo::DeliveryKind::from_raw(val).ok_or(())? - } else { - return Err(()); - } - }, - target: { - if let Some(Argument::Object(val)) = args.next() { - map.get(val).ok_or(())?.into() - } else { - return Err(()); - } - }, - metadata: { - if let Some(Argument::Array(val)) = args.next() { - val - } else { - return Err(()); - } - }, - metametadata: { - if let Some(Argument::Array(val)) = args.next() { - if val.len() == 0 { - None - } else { - Some(val) - } - } else { - return Err(()); - } - }, - }) - } - 1 => Ok(Request::Release), - 2 => { - let mut args = msg.args.into_iter(); - Ok(Request::_Self { - _self: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - _mut: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - object: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - ___object: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - handler: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - ___handler: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - request: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - event: { - if let Some(Argument::Uint(val)) = args.next() { - val - } else { - return Err(()); - } - }, - }) - } - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Request::into_raw can not be used Server-side.") - } - } - pub enum Event { - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis event tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface"] - _Self { - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "self", - since: 2, - signature: &[ - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - super::ArgumentType::Uint, - ], - }]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - _ => false, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::_Self { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::_Self { .. } => 2, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Event::from_raw can not be used Server-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Event::__nonexhaustive => unreachable!(), - Event::_Self { - _self, - _mut, - object, - ___object, - handler, - ___handler, - request, - event, - } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![ - Argument::Uint(_self), - Argument::Uint(_mut), - Argument::Uint(object), - Argument::Uint(___object), - Argument::Uint(handler), - Argument::Uint(___handler), - Argument::Uint(request), - Argument::Uint(event), - ], - }, - } - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlBar(Resource); - impl AsRef> for WlBar { - #[inline] - fn as_ref(&self) -> &Resource { - &self.0 - } - } - impl From> for WlBar { - #[inline] - fn from(value: Resource) -> Self { - WlBar(value) - } - } - impl From for Resource { - #[inline] - fn from(value: WlBar) -> Self { - value.0 - } - } - impl Interface for WlBar { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_bar"; - const VERSION: u32 = 1; - } - impl WlBar { - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis event tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface."] - pub fn _self( - &self, - _self: u32, - _mut: u32, - object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - ) -> () { - let msg = Event::_Self { - _self: _self, - _mut: _mut, - object: object, - ___object: ___object, - handler: handler, - ___handler: ___handler, - request: request, - event: event, - }; - self.0.send(msg); - } - } - #[doc = r" An interface for handling requests."] - pub trait RequestHandler { - #[doc = "ask for a bar delivery\n\nProceed to a bar delivery of given foo.\n\nOnly available since version 2 of the interface."] - fn bar_delivery( - &mut self, - object: WlBar, - kind: super::wl_foo::DeliveryKind, - target: super::wl_foo::WlFoo, - metadata: Vec, - metametadata: Option>, - ) { - } - #[doc = "release this bar\n\nNotify the compositor that you have finished using this bar.\n\nThis is a destructor, you cannot send requests to this object any longer once this method is called."] - fn release(&mut self, object: WlBar) {} - #[doc = "ask for erronous bindings from wayland-scanner\n\nThis request tests argument names which can break wayland-scanner.\n\nOnly available since version 2 of the interface."] - fn _self( - &mut self, - object: WlBar, - _self: u32, - _mut: u32, - _object: u32, - ___object: u32, - handler: u32, - ___handler: u32, - request: u32, - event: u32, - ) { - } - } - impl HandledBy for WlBar { - #[inline] - fn handle(__handler: &mut T, request: Request, __object: Self) { - match request { - Request::BarDelivery { - kind, - target, - metadata, - metametadata, - } => __handler.bar_delivery(__object, kind, target, metadata, metametadata), - Request::Release {} => __handler.release(__object), - Request::_Self { - _self, - _mut, - object, - ___object, - handler, - ___handler, - request, - event, - } => __handler._self( - __object, _self, _mut, object, ___object, handler, ___handler, request, event, - ), - Request::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this request"] - pub const REQ_BAR_DELIVERY_SINCE: u32 = 2u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_RELEASE_SINCE: u32 = 1u32; - #[doc = r" The minimal object version supporting this request"] - pub const REQ_SELF_SINCE: u32 = 2u32; - #[doc = r" The minimal object version supporting this event"] - pub const EVT_SELF_SINCE: u32 = 2u32; -} -#[doc = "callback object\n\nThis object has a special behavior regarding its destructor."] -pub mod wl_callback { - use super::{ - AnonymousObject, Argument, ArgumentType, HandledBy, Interface, Message, MessageDesc, MessageGroup, - NewResource, Object, ObjectMetadata, Resource, - }; - pub enum Request { - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Request { - const MESSAGES: &'static [super::MessageDesc] = &[]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn opcode(&self) -> u16 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn since(&self) -> u32 { - match *self { - Request::__nonexhaustive => unreachable!(), - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - match msg.opcode { - _ => Err(()), - } - } - fn into_raw(self, sender_id: u32) -> Message { - panic!("Request::into_raw can not be used Server-side.") - } - } - pub enum Event { - #[doc = "done event\n\nThis event is actually a destructor, but the protocol XML has no way of specifying it.\nAs such, the scanner should consider wl_callback.done as a special case.\n\nThis is a destructor, once sent this object cannot be used any longer."] - Done { callback_data: u32 }, - #[doc(hidden)] - __nonexhaustive, - } - impl super::MessageGroup for Event { - const MESSAGES: &'static [super::MessageDesc] = &[super::MessageDesc { - name: "done", - since: 1, - signature: &[super::ArgumentType::Uint], - }]; - type Map = super::ResourceMap; - fn is_destructor(&self) -> bool { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => true, - } - } - fn opcode(&self) -> u16 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => 0, - } - } - fn since(&self) -> u32 { - match *self { - Event::__nonexhaustive => unreachable!(), - Event::Done { .. } => 1, - } - } - fn child(opcode: u16, version: u32, meta: &Meta) -> Option> { - match opcode { - _ => None, - } - } - fn from_raw(msg: Message, map: &mut Self::Map) -> Result { - panic!("Event::from_raw can not be used Server-side.") - } - fn into_raw(self, sender_id: u32) -> Message { - match self { - Event::__nonexhaustive => unreachable!(), - Event::Done { callback_data } => Message { - sender_id: sender_id, - opcode: 0, - args: vec![Argument::Uint(callback_data)], - }, - } - } - } - #[derive(Clone, Eq, PartialEq)] - pub struct WlCallback(Resource); - impl AsRef> for WlCallback { - #[inline] - fn as_ref(&self) -> &Resource { - &self.0 - } - } - impl From> for WlCallback { - #[inline] - fn from(value: Resource) -> Self { - WlCallback(value) - } - } - impl From for Resource { - #[inline] - fn from(value: WlCallback) -> Self { - value.0 - } - } - impl Interface for WlCallback { - type Request = Request; - type Event = Event; - const NAME: &'static str = "wl_callback"; - const VERSION: u32 = 1; - } - impl WlCallback { - #[doc = "done event\n\nThis event is actually a destructor, but the protocol XML has no way of specifying it.\nAs such, the scanner should consider wl_callback.done as a special case.\n\nThis is a destructor, you cannot send requests to this object any longer once this method is called."] - pub fn done(&self, callback_data: u32) -> () { - let msg = Event::Done { - callback_data: callback_data, - }; - self.0.send(msg); - } - } - #[doc = r" An interface for handling requests."] - pub trait RequestHandler {} - impl HandledBy for WlCallback { - #[inline] - fn handle(__handler: &mut T, request: Request, __object: Self) { - match request { - Request::__nonexhaustive => unreachable!(), - } - } - } - #[doc = r" The minimal object version supporting this event"] - pub const EVT_DONE_SINCE: u32 = 1u32; -} diff --git a/wayland-client/Cargo.toml b/wayland-client/Cargo.toml index c2a1aa23216..861dae6b0c2 100644 --- a/wayland-client/Cargo.toml +++ b/wayland-client/Cargo.toml @@ -15,7 +15,7 @@ travis-ci = { repository = "Smithay/wayland-rs" } [dependencies] wayland-commons = { version = "0.22.2", path = "../wayland-commons" } -wayland-sys = { version = "0.22.2", features = ["client"], path = "../wayland-sys", optional = true } +wayland-sys = { version = "0.22.2", path = "../wayland-sys" } nix = "0.12" downcast-rs = "1.0" bitflags = "1.0" @@ -31,7 +31,7 @@ byteorder = "1.0" tempfile = ">=2.0, <4.0" [features] -native_lib = [ "wayland-sys", "wayland-commons/native_lib" ] +native_lib = [ "wayland-sys/client" ] dlopen = ["wayland-sys/dlopen", "native_lib"] egl = ["wayland-sys/egl", "native_lib"] cursor = ["wayland-sys/cursor", "native_lib"] diff --git a/wayland-client/build.rs b/wayland-client/build.rs index 8c7bff55cd6..f540cd62270 100644 --- a/wayland-client/build.rs +++ b/wayland-client/build.rs @@ -10,11 +10,5 @@ fn main() { let out_dir_str = var("OUT_DIR").unwrap(); let out_dir = Path::new(&out_dir_str); - if var("CARGO_FEATURE_NATIVE_LIB").ok().is_some() { - // generate the C code - generate_c_code(protocol_file, out_dir.join("wayland_c_api.rs"), Side::Client); - generate_c_interfaces(protocol_file, out_dir.join("wayland_c_interfaces.rs")); - } else { - generate_rust_code(protocol_file, out_dir.join("wayland_rust_api.rs"), Side::Client); - } + generate_code(protocol_file, out_dir.join("wayland_api.rs"), Side::Client); } diff --git a/wayland-client/src/lib.rs b/wayland-client/src/lib.rs index 4419d9ddad4..40995bed9e8 100644 --- a/wayland-client/src/lib.rs +++ b/wayland-client/src/lib.rs @@ -127,8 +127,7 @@ extern crate calloop; extern crate mio; extern crate wayland_commons; -#[cfg(feature = "native_lib")] -#[macro_use] +#[cfg_attr(feature = "native_lib", macro_use)] extern crate wayland_sys; mod display; @@ -162,51 +161,26 @@ mod imp; #[path = "native_lib/mod.rs"] mod imp; -#[cfg(feature = "native_lib")] /// C-associated types /// /// Required for plugging wayland-scanner generated protocols /// or interfacing with C code using wayland objects. pub mod sys { - pub use super::generated::c_interfaces as protocol_interfaces; pub use wayland_sys::{client, common}; } -/// Generated interfaces for the core wayland protocol pub mod protocol { - #[cfg(feature = "native_lib")] - pub use generated::c_api::*; - #[cfg(not(feature = "native_lib"))] - pub use generated::rust_api::*; -} - -mod generated { #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] #![allow(non_upper_case_globals, non_snake_case, unused_imports)] #![allow(missing_docs)] #![cfg_attr(feature = "cargo-clippy", allow(clippy))] - #[cfg(feature = "native_lib")] - pub mod c_interfaces { - include!(concat!(env!("OUT_DIR"), "/wayland_c_interfaces.rs")); - } - #[cfg(feature = "native_lib")] - pub mod c_api { - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use wayland_sys as sys; - pub(crate) use {AnonymousObject, HandledBy, NewProxy, Proxy, ProxyMap}; - include!(concat!(env!("OUT_DIR"), "/wayland_c_api.rs")); - } - #[cfg(not(feature = "native_lib"))] - pub mod rust_api { - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use {AnonymousObject, HandledBy, NewProxy, Proxy, ProxyMap}; - include!(concat!(env!("OUT_DIR"), "/wayland_rust_api.rs")); - } + pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; + pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; + pub(crate) use wayland_commons::{Interface, MessageGroup}; + pub(crate) use wayland_sys as sys; + pub(crate) use {AnonymousObject, HandledBy, NewProxy, Proxy, ProxyMap}; + include!(concat!(env!("OUT_DIR"), "/wayland_api.rs")); } mod anonymous_object { @@ -224,7 +198,6 @@ mod anonymous_object { type Event = NoMessage; const NAME: &'static str = ""; const VERSION: u32 = 0; - #[cfg(feature = "native_lib")] fn c_interface() -> *const ::sys::common::wl_interface { ::std::ptr::null() } diff --git a/wayland-client/src/proxy.rs b/wayland-client/src/proxy.rs index 95ca67f8133..aa346487c51 100644 --- a/wayland-client/src/proxy.rs +++ b/wayland-client/src/proxy.rs @@ -2,7 +2,6 @@ use super::AnonymousObject; use wayland_commons::utils::UserData; use wayland_commons::Interface; -#[cfg(feature = "native_lib")] use wayland_sys::client::*; use event_queue::QueueToken; @@ -225,13 +224,22 @@ impl Proxy { } } -#[cfg(feature = "native_lib")] impl Proxy { /// Check whether this proxy is managed by the library or not /// /// See `from_c_ptr` for details. + /// + /// NOTE: This method will panic if called while the `native_lib` feature is + /// not activated. pub fn is_external(&self) -> bool { - self.inner.is_external() + #[cfg(feature = "native_lib")] + { + self.inner.is_external() + } + #[cfg(not(feature = "native_lib"))] + { + panic!("[wayland-client] C interfacing methods can only be used with the `native_lib` cargo feature.") + } } /// Get a raw pointer to the underlying wayland object @@ -239,8 +247,18 @@ impl Proxy { /// Retrieve a pointer to the object from the `libwayland-client.so` library. /// You will mostly need it to interface with C libraries needing access /// to wayland objects (to initialize an opengl context for example). + /// + /// NOTE: This method will panic if called while the `native_lib` feature is + /// not activated. pub fn c_ptr(&self) -> *mut wl_proxy { - self.inner.c_ptr() + #[cfg(feature = "native_lib")] + { + self.inner.c_ptr() + } + #[cfg(not(feature = "native_lib"))] + { + panic!("[wayland-client] C interfacing methods can only be used with the `native_lib` cargo feature.") + } } /// Create a `Proxy` instance from a C pointer @@ -262,13 +280,23 @@ impl Proxy { /// /// In order to handle protocol races, invoking it with a NULL pointer will /// create an already-dead object. - pub unsafe fn from_c_ptr(ptr: *mut wl_proxy) -> Proxy + /// + /// NOTE: This method will panic if called while the `native_lib` feature is + /// not activated. + pub unsafe fn from_c_ptr(_ptr: *mut wl_proxy) -> Proxy where I: From>, { - Proxy { - _i: ::std::marker::PhantomData, - inner: ProxyInner::from_c_ptr::(ptr), + #[cfg(feature = "native_lib")] + { + Proxy { + _i: ::std::marker::PhantomData, + inner: ProxyInner::from_c_ptr::(_ptr), + } + } + #[cfg(not(feature = "native_lib"))] + { + panic!("[wayland-client] C interfacing methods can only be used with the `native_lib` cargo feature.") } } } @@ -409,7 +437,6 @@ impl NewProxy { } } -#[cfg(feature = "native_lib")] impl NewProxy { /// Get a raw pointer to the underlying wayland object /// @@ -419,8 +446,18 @@ impl NewProxy { /// /// Use this if you need to pass an unimplemented object to the C library /// you are interfacing with. + /// + /// NOTE: This method will panic if called while the `native_lib` feature is + /// not activated. pub fn c_ptr(&self) -> *mut wl_proxy { - self.inner.c_ptr() + #[cfg(feature = "native_lib")] + { + self.inner.c_ptr() + } + #[cfg(not(feature = "native_lib"))] + { + panic!("[wayland-client] C interfacing methods can only be used with the `native_lib` cargo feature.") + } } /// Create a `NewProxy` instance from a C pointer. @@ -429,10 +466,20 @@ impl NewProxy { /// can be safely implemented. As implementing it will overwrite any previously /// associated data or implementation, this can cause weird errors akin to /// memory corruption if it was not the case. - pub unsafe fn from_c_ptr(ptr: *mut wl_proxy) -> Self { - NewProxy { - _i: ::std::marker::PhantomData, - inner: NewProxyInner::from_c_ptr(ptr), + /// + /// NOTE: This method will panic if called while the `native_lib` feature is + /// not activated. + pub unsafe fn from_c_ptr(_ptr: *mut wl_proxy) -> Self { + #[cfg(feature = "native_lib")] + { + NewProxy { + _i: ::std::marker::PhantomData, + inner: NewProxyInner::from_c_ptr(_ptr), + } + } + #[cfg(not(feature = "native_lib"))] + { + panic!("[wayland-client] C interfacing methods can only be used with the `native_lib` cargo feature.") } } } diff --git a/wayland-commons/Cargo.toml b/wayland-commons/Cargo.toml index daaba355554..59a51f82d81 100644 --- a/wayland-commons/Cargo.toml +++ b/wayland-commons/Cargo.toml @@ -13,8 +13,6 @@ keywords = ["wayland"] travis-ci = { repository = "Smithay/wayland-rs" } [dependencies] -wayland-sys = { version = "0.22.2", path = "../wayland-sys", optional = true } +wayland-sys = { version = "0.22.2", path = "../wayland-sys" } nix = "0.12" -[features] -native_lib = [ "wayland-sys" ] diff --git a/wayland-commons/src/lib.rs b/wayland-commons/src/lib.rs index 9ec461e7945..6292d21a6e3 100644 --- a/wayland-commons/src/lib.rs +++ b/wayland-commons/src/lib.rs @@ -16,11 +16,8 @@ #![warn(missing_docs)] extern crate nix; -#[cfg(feature = "native_lib")] extern crate wayland_sys; -#[cfg(feature = "native_lib")] use std::os::raw::c_void; -#[cfg(feature = "native_lib")] use wayland_sys::common as syscom; pub mod map; @@ -60,11 +57,9 @@ pub trait MessageGroup: Sized { fn from_raw(msg: wire::Message, map: &mut Self::Map) -> Result; /// Turn this message into its raw representation fn into_raw(self, send_id: u32) -> wire::Message; - #[cfg(feature = "native_lib")] /// Construct a message of this group from its C representation unsafe fn from_raw_c(obj: *mut c_void, opcode: u32, args: *const syscom::wl_argument) -> Result; - #[cfg(feature = "native_lib")] /// Build a C representation of this message /// /// It can only be accessed from the provided closure, and this consumes @@ -99,7 +94,6 @@ pub trait Interface: 'static { /// advertise through the registry, and clients can choose any version among the /// ones the server supports. const VERSION: u32; - #[cfg(feature = "native_lib")] /// Pointer to the C representation of this interface fn c_interface() -> *const ::syscom::wl_interface; } @@ -129,7 +123,6 @@ impl MessageGroup for NoMessage { fn into_raw(self, _: u32) -> wire::Message { match self {} } - #[cfg(feature = "native_lib")] unsafe fn from_raw_c( _obj: *mut c_void, _opcode: u32, @@ -137,7 +130,6 @@ impl MessageGroup for NoMessage { ) -> Result { Err(()) } - #[cfg(feature = "native_lib")] fn as_raw_c_in(self, _f: F) -> T where F: FnOnce(u32, &mut [syscom::wl_argument]) -> T, diff --git a/wayland-protocols/Cargo.toml b/wayland-protocols/Cargo.toml index a1a32fc6d87..46913b102e1 100644 --- a/wayland-protocols/Cargo.toml +++ b/wayland-protocols/Cargo.toml @@ -15,7 +15,6 @@ travis-ci = { repository = "Smithay/wayland-rs" } [dependencies] wayland-commons = { version = "0.22.2", path = "../wayland-commons" } -wayland-sys = { version = "0.22.2", path = "../wayland-sys", optional = true } wayland-client = { version = "0.22.2", path = "../wayland-client", optional = true } wayland-server = { version = "0.22.2", path = "../wayland-server", optional = true } bitflags = "1.0" @@ -26,9 +25,6 @@ wayland-scanner = { version = "0.22.2", path = "../wayland-scanner" } [features] client = ["wayland-client"] server = ["wayland-server"] -native_lib = ["wayland-sys"] -native_client = ["client", "native_lib", "wayland-client/native_lib"] -native_server = ["server", "native_lib", "wayland-server/native_lib"] unstable_protocols = [] [package.metadata.docs.rs] diff --git a/wayland-protocols/build.rs b/wayland-protocols/build.rs index 333d6712118..92d171d2488 100644 --- a/wayland-protocols/build.rs +++ b/wayland-protocols/build.rs @@ -40,40 +40,19 @@ static WLR_UNSTABLE_PROTOCOLS: &[(&str, &[&str])] = &[ static MISC_PROTOCOLS: &[&str] = &["gtk-primary-selection"]; fn generate_protocol(name: &str, protocol_file: &Path, out_dir: &Path, client: bool, server: bool) { - if var("CARGO_FEATURE_NATIVE_LIB").ok().is_some() { - generate_c_interfaces(&protocol_file, out_dir.join(&format!("{}_c_interfaces.rs", name))); - - if client { - generate_c_code( - &protocol_file, - out_dir.join(&format!("{}_c_client_api.rs", name)), - Side::Client, - ); - } - - if server { - generate_c_code( - &protocol_file, - out_dir.join(&format!("{}_c_server_api.rs", name)), - Side::Server, - ); - } - } else { - if client { - generate_rust_code( - &protocol_file, - out_dir.join(&format!("{}_rust_client_api.rs", name)), - Side::Client, - ); - } - - if server { - generate_rust_code( - &protocol_file, - out_dir.join(&format!("{}_rust_server_api.rs", name)), - Side::Server, - ); - } + if client { + generate_code( + &protocol_file, + out_dir.join(&format!("{}_client_api.rs", name)), + Side::Client, + ); + } + if server { + generate_code( + &protocol_file, + out_dir.join(&format!("{}_server_api.rs", name)), + Side::Server, + ); } } diff --git a/wayland-protocols/src/lib.rs b/wayland-protocols/src/lib.rs index 87346a17f2a..be6ae2ace45 100644 --- a/wayland-protocols/src/lib.rs +++ b/wayland-protocols/src/lib.rs @@ -24,10 +24,6 @@ extern crate wayland_server; extern crate wayland_commons; -#[cfg(feature = "native_lib")] -#[macro_use] -extern crate wayland_sys; - #[macro_use] extern crate bitflags; diff --git a/wayland-protocols/src/protocol_macro.rs b/wayland-protocols/src/protocol_macro.rs index b22f0d4f5be..e0799e57664 100644 --- a/wayland-protocols/src/protocol_macro.rs +++ b/wayland-protocols/src/protocol_macro.rs @@ -7,10 +7,6 @@ macro_rules! wayland_protocol( #[cfg(feature = "server")] pub use self::generated::server; - #[cfg(all(feature = "native_lib", any(feature = "client", feature = "server")))] - pub use self::generated::c_interfaces; - - #[cfg(all(not(feature = "native_lib"), any(feature = "client", feature = "server")))] mod generated { #![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] #![allow(non_upper_case_globals,non_snake_case,unused_imports)] @@ -25,61 +21,11 @@ macro_rules! wayland_protocol( pub(crate) use wayland_commons::{Interface, MessageGroup}; pub(crate) use wayland_commons::wire::{Argument, MessageDesc, ArgumentType, Message}; pub(crate) use wayland_client::protocol::{$($import),*}; + pub(crate) use wayland_client::sys; $( pub(crate) use ::$prot_name::client::$prot_import; )* - include!(concat!(env!("OUT_DIR"), "/", $name, "_rust_client_api.rs")); - } - - #[cfg(feature = "server")] - pub mod server { - //! Server-side API of this protocol - pub(crate) use wayland_server::{AnonymousObject, NewResource, Resource, ResourceMap, HandledBy}; - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use wayland_commons::wire::{Argument, MessageDesc, ArgumentType, Message}; - pub(crate) use wayland_server::protocol::{$($import),*}; - $( - pub(crate) use ::$prot_name::server::$prot_import; - )* - include!(concat!(env!("OUT_DIR"), "/", $name, "_rust_server_api.rs")); - } - } - - #[cfg(all(feature = "native_lib", any(feature = "client", feature = "server")))] - mod generated { - #![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] - #![allow(non_upper_case_globals,non_snake_case,unused_imports)] - #![allow(missing_docs)] - #![cfg_attr(feature = "cargo-clippy", allow(clippy))] - - pub mod c_interfaces { - //! C interfaces for this protocol - - // import client or server, both are the same anyway - #[cfg(feature = "client")] - pub use wayland_client::sys::protocol_interfaces::{$($interface),*}; - #[cfg(all(not(feature = "client"), feature = "server"))] - pub use wayland_server::sys::protocol_interfaces::{$($interface),*}; - $( - pub(crate) use ::$prot_name::c_interfaces::$prot_iface; - )* - include!(concat!(env!("OUT_DIR"), "/", $name, "_c_interfaces.rs")); - } - - #[cfg(feature = "client")] - pub mod client { - //! Client-side API of this protocol - pub(crate) use wayland_client::{NewProxy, Proxy, ProxyMap, HandledBy, AnonymousObject}; - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use wayland_commons::wire::{Argument, MessageDesc, ArgumentType, Message}; - pub(crate) use wayland_sys as sys; - pub(crate) use wayland_client::protocol::{$($import),*}; - $( - pub(crate) use ::$prot_name::client::$prot_import; - )* - include!(concat!(env!("OUT_DIR"), "/", $name, "_c_client_api.rs")); + include!(concat!(env!("OUT_DIR"), "/", $name, "_client_api.rs")); } #[cfg(feature = "server")] @@ -89,12 +35,12 @@ macro_rules! wayland_protocol( pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; pub(crate) use wayland_commons::{Interface, MessageGroup}; pub(crate) use wayland_commons::wire::{Argument, MessageDesc, ArgumentType, Message}; - pub(crate) use wayland_sys as sys; pub(crate) use wayland_server::protocol::{$($import),*}; + pub(crate) use wayland_server::sys; $( pub(crate) use ::$prot_name::server::$prot_import; )* - include!(concat!(env!("OUT_DIR"), "/", $name, "_c_server_api.rs")); + include!(concat!(env!("OUT_DIR"), "/", $name, "_server_api.rs")); } } } diff --git a/wayland-scanner/src/c_code_gen.rs b/wayland-scanner/src/c_code_gen.rs index 0ddd56996f8..114d94cd1b5 100644 --- a/wayland-scanner/src/c_code_gen.rs +++ b/wayland-scanner/src/c_code_gen.rs @@ -21,7 +21,13 @@ pub(crate) fn generate_protocol_client(protocol: Protocol) -> TokenStream { Side::Client, false, &iface.requests, - Some(messagegroup_c_addon(&ident, Side::Client, false, &iface.requests)), + Some(messagegroup_c_addon( + &ident, + &iface_name, + Side::Client, + false, + &iface.requests, + )), ); let ident = Ident::new("Event", Span::call_site()); @@ -30,7 +36,13 @@ pub(crate) fn generate_protocol_client(protocol: Protocol) -> TokenStream { Side::Client, true, &iface.events, - Some(messagegroup_c_addon(&ident, Side::Client, true, &iface.events)), + Some(messagegroup_c_addon( + &ident, + &iface_name, + Side::Client, + true, + &iface.events, + )), ); let interface = gen_interface( @@ -44,15 +56,17 @@ pub(crate) fn generate_protocol_client(protocol: Protocol) -> TokenStream { let object_methods = gen_object_methods(&iface_name, &iface.requests, Side::Client); let event_handler_trait = gen_event_handler_trait(&iface_name, &iface.events, Side::Client); let sinces = gen_since_constants(&iface.requests, &iface.events); + let c_interface = super::c_interface_gen::generate_interface(&iface); quote! { #doc_attr pub mod #mod_name { + use std::os::raw::c_char; use super::{ Proxy, NewProxy, AnonymousObject, Interface, MessageGroup, MessageDesc, ArgumentType, - Object, Message, Argument, ObjectMetadata, HandledBy + Object, Message, Argument, ObjectMetadata, HandledBy, types_null, NULLPTR }; - use super::sys::common::{wl_argument, wl_interface, wl_array}; + use super::sys::common::{wl_interface, wl_array, wl_argument, wl_message}; use super::sys::client::*; #(#enums)* @@ -62,11 +76,16 @@ pub(crate) fn generate_protocol_client(protocol: Protocol) -> TokenStream { #object_methods #event_handler_trait #sinces + #c_interface } } }); + let c_prefix = super::c_interface_gen::generate_interfaces_prefix(&protocol); + quote! { + #c_prefix + #(#modules)* } } @@ -90,7 +109,7 @@ pub(crate) fn generate_protocol_server(protocol: Protocol) -> TokenStream { Side::Server, true, &iface.requests, - Some(messagegroup_c_addon(&ident, Side::Server, true, &iface.requests)), + Some(messagegroup_c_addon(&ident, &iface_name, Side::Server, true, &iface.requests)), ); let ident = Ident::new("Event", Span::call_site()); @@ -99,7 +118,7 @@ pub(crate) fn generate_protocol_server(protocol: Protocol) -> TokenStream { Side::Server, false, &iface.events, - Some(messagegroup_c_addon(&ident, Side::Server, false, &iface.events)), + Some(messagegroup_c_addon(&ident, &iface_name, Side::Server, false, &iface.events)), ); let interface = gen_interface( @@ -112,15 +131,17 @@ pub(crate) fn generate_protocol_server(protocol: Protocol) -> TokenStream { let object_methods = gen_object_methods(&iface_name, &iface.events, Side::Server); let event_handler_trait = gen_event_handler_trait(&iface_name, &iface.requests, Side::Server); let sinces = gen_since_constants(&iface.requests, &iface.events); + let c_interface = super::c_interface_gen::generate_interface(&iface); quote! { #doc_attr pub mod #mod_name { + use std::os::raw::c_char; use super::{ Resource, NewResource, AnonymousObject, Interface, MessageGroup, MessageDesc, - ArgumentType, Object, Message, Argument, ObjectMetadata, HandledBy + ArgumentType, Object, Message, Argument, ObjectMetadata, HandledBy, types_null, NULLPTR }; - use super::sys::common::{wl_argument, wl_interface, wl_array}; + use super::sys::common::{wl_argument, wl_interface, wl_array, wl_message}; use super::sys::server::*; #(#enums)* @@ -130,16 +151,26 @@ pub(crate) fn generate_protocol_server(protocol: Protocol) -> TokenStream { #object_methods #event_handler_trait #sinces + #c_interface } } }); + let c_prefix = super::c_interface_gen::generate_interfaces_prefix(&protocol); + quote! { + #c_prefix #(#modules)* } } -fn messagegroup_c_addon(name: &Ident, side: Side, receiver: bool, messages: &[Message]) -> TokenStream { +fn messagegroup_c_addon( + name: &Ident, + parent_iface: &Ident, + side: Side, + receiver: bool, + messages: &[Message], +) -> TokenStream { let from_raw_c_body = if receiver { let match_arms = messages .iter() @@ -250,28 +281,8 @@ fn messagegroup_c_addon(name: &Ident, side: Side, receiver: bool, messages: &[Me Side::Server => { quote! { { - let client = ffi_dispatch!( - WAYLAND_SERVER_HANDLE, - wl_resource_get_client, - obj as *mut _ - ); - let version = ffi_dispatch!( - WAYLAND_SERVER_HANDLE, - wl_resource_get_version, - obj as *mut _ - ); - let new_ptr = ffi_dispatch!( - WAYLAND_SERVER_HANDLE, - wl_resource_create, - client, - super::#iface_mod::#iface_type::c_interface(), - version, - _args[#idx].n - ); - - NewResource::::from_c_ptr( - new_ptr - ) + let me = Resource::<#parent_iface>::from_c_ptr(obj as *mut _); + me.make_child_for::(_args[#idx].n).unwrap() } } } @@ -516,10 +527,10 @@ fn messagegroup_c_addon(name: &Ident, side: Side, receiver: bool, messages: &[Me } fn interface_c_addon(low_name: &str) -> TokenStream { - let mod_name = Ident::new(&format!("{}_interface", low_name), Span::call_site()); + let iface_name = Ident::new(&format!("{}_interface", low_name), Span::call_site()); quote! { fn c_interface() -> *const wl_interface { - unsafe { &super::super::c_interfaces::#mod_name } + unsafe { &#iface_name } } } } diff --git a/wayland-scanner/src/c_interface_gen.rs b/wayland-scanner/src/c_interface_gen.rs index 5cff8b57016..86ecfa4dce2 100644 --- a/wayland-scanner/src/c_interface_gen.rs +++ b/wayland-scanner/src/c_interface_gen.rs @@ -6,7 +6,7 @@ use proc_macro2::{Ident, Literal, Span, TokenStream}; use protocol::*; use util::null_terminated_byte_string_literal; -pub(crate) fn generate_interfaces(protocol: Protocol) -> TokenStream { +pub(crate) fn generate_interfaces_prefix(protocol: &Protocol) -> TokenStream { let longest_nulls = protocol.interfaces.iter().fold(0, |max, interface| { let request_longest_null = interface.requests.iter().fold(0, |max, request| { if request.all_null() { @@ -27,58 +27,56 @@ pub(crate) fn generate_interfaces(protocol: Protocol) -> TokenStream { let types_null_len = Literal::usize_unsuffixed(longest_nulls); - let nulls = repeat(quote!(NULLPTR as *const wl_interface)).take(longest_nulls); - - let interfaces = protocol.interfaces.iter().map(|interface| { - let requests = gen_messages(interface, &interface.requests, "requests"); - let events = gen_messages(interface, &interface.events, "events"); - - let interface_ident = Ident::new(&format!("{}_interface", interface.name), Span::call_site()); - let name_value = null_terminated_byte_string_literal(&interface.name); - let version_value = Literal::i32_unsuffixed(interface.version as i32); - let request_count_value = Literal::i32_unsuffixed(interface.requests.len() as i32); - let requests_value = if interface.requests.is_empty() { - quote!(NULLPTR as *const wl_message) - } else { - let requests_ident = Ident::new(&format!("{}_requests", interface.name), Span::call_site()); - quote!(unsafe { &#requests_ident as *const _ }) - }; - let event_count_value = Literal::i32_unsuffixed(interface.events.len() as i32); - let events_value = if interface.events.is_empty() { - quote!(NULLPTR as *const wl_message) - } else { - let events_ident = Ident::new(&format!("{}_events", interface.name), Span::call_site()); - quote!(unsafe { &#events_ident as *const _ }) - }; - - quote!( - #requests - #events - - pub static mut #interface_ident: wl_interface = wl_interface { - name: #name_value as *const u8 as *const c_char, - version: #version_value, - request_count: #request_count_value, - requests: #requests_value, - event_count: #event_count_value, - events: #events_value, - }; - ) - }); + let nulls = repeat(quote!(NULLPTR as *const sys::common::wl_interface)).take(longest_nulls); quote! { use std::os::raw::{c_char, c_void}; - use wayland_sys::common::*; const NULLPTR: *const c_void = 0 as *const c_void; - static mut types_null: [*const wl_interface; #types_null_len] = [ + static mut types_null: [*const sys::common::wl_interface; #types_null_len] = [ #(#nulls,)* ]; - - #(#interfaces)* } } +pub(crate) fn generate_interface(interface: &Interface) -> TokenStream { + let requests = gen_messages(interface, &interface.requests, "requests"); + let events = gen_messages(interface, &interface.events, "events"); + + let interface_ident = Ident::new(&format!("{}_interface", interface.name), Span::call_site()); + let name_value = null_terminated_byte_string_literal(&interface.name); + let version_value = Literal::i32_unsuffixed(interface.version as i32); + let request_count_value = Literal::i32_unsuffixed(interface.requests.len() as i32); + let requests_value = if interface.requests.is_empty() { + quote!(NULLPTR as *const wl_message) + } else { + let requests_ident = Ident::new(&format!("{}_requests", interface.name), Span::call_site()); + quote!(unsafe { &#requests_ident as *const _ }) + }; + let event_count_value = Literal::i32_unsuffixed(interface.events.len() as i32); + let events_value = if interface.events.is_empty() { + quote!(NULLPTR as *const wl_message) + } else { + let events_ident = Ident::new(&format!("{}_events", interface.name), Span::call_site()); + quote!(unsafe { &#events_ident as *const _ }) + }; + + quote!( + #requests + #events + + /// C representation of this interface, for interop + pub static mut #interface_ident: wl_interface = wl_interface { + name: #name_value as *const u8 as *const c_char, + version: #version_value, + request_count: #request_count_value, + requests: #requests_value, + event_count: #event_count_value, + events: #events_value, + }; + ) +} + fn gen_messages(interface: &Interface, messages: &[Message], which: &str) -> TokenStream { if messages.is_empty() { return TokenStream::new(); @@ -95,8 +93,9 @@ fn gen_messages(interface: &Interface, messages: &[Message], which: &str) -> Tok let array_len = Literal::usize_unsuffixed(msg.args.len()); let array_values = msg.args.iter().map(|arg| match (arg.typ, &arg.interface) { (Type::Object, &Some(ref inter)) | (Type::NewId, &Some(ref inter)) => { + let module = Ident::new(inter, Span::call_site()); let interface_ident = Ident::new(&format!("{}_interface", inter), Span::call_site()); - quote!(unsafe { &#interface_ident as *const wl_interface }) + quote!(unsafe { &super::#module::#interface_ident as *const wl_interface }) } _ => quote!(NULLPTR as *const wl_interface), }); @@ -136,6 +135,7 @@ fn gen_messages(interface: &Interface, messages: &[Message], which: &str) -> Tok quote! { #(#types_arrays)* + /// C-representation of the messages of this interface, for interop pub static mut #message_array_ident: [wl_message; #message_array_len] = [ #(#message_array_values,)* ]; diff --git a/wayland-scanner/src/lib.rs b/wayland-scanner/src/lib.rs index 37c735fd642..2bb676e1aef 100644 --- a/wayland-scanner/src/lib.rs +++ b/wayland-scanner/src/lib.rs @@ -10,9 +10,8 @@ //! //! ## How to use this crate //! -//! This crate is to be used in a build script. It provides you two -//! functions, `generate_c_code` and `generate_c_interfaces`. They'll -//! allow you to generate the code to use with the `wayland_client` or +//! This crate is to be used in a build script. It provides the function `generate_code`. +//! It'll allow you to generate the code to use with the `wayland_client` or //! `wayland_server` crates for any XML wayland protocol file (NB: you don't //! need to do it for the core protocol, which is already included in both crates). //! @@ -30,7 +29,7 @@ //! use std::env::var; //! use std::path::Path; //! -//! use wayland_scanner::{Side, generate_c_code, generate_c_interfaces}; +//! use wayland_scanner::{Side, generate_code}; //! //! fn main() { //! // Location of the xml file, relative to the `Cargo.toml` @@ -40,17 +39,11 @@ //! let out_dir_str = var("OUT_DIR").unwrap(); //! let out_dir = Path::new(&out_dir_str); //! -//! generate_c_code( +//! generate_code( //! protocol_file, //! out_dir.join("my_protocol_api.rs"), //! Side::Client, // Replace by `Side::Server` for server-side code //! ); -//! -//! // interfaces are the same for client and server -//! generate_c_interfaces( -//! protocol_file, -//! out_dir.join("my_protocol_interfaces.rs") -//! ); //! } //! ``` //! @@ -76,12 +69,6 @@ //! #![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] //! #![allow(non_upper_case_globals,non_snake_case,unused_imports)] //! -//! pub mod interfaces { -//! // include the interfaces, they just need to be accessible to the generated code -//! // so this module is `pub` so that it can be imported by the other one. -//! include!(concat!(env!("OUT_DIR"), "/my_protocol_interfaces.rs")); -//! } -//! //! pub mod client { //! // If you protocol interacts with objects from other protocols, you'll need to import //! // their modules, like so: @@ -109,7 +96,6 @@ mod c_interface_gen; mod common_gen; mod parse; mod protocol; -mod rust_code_gen; mod side; mod util; @@ -121,62 +107,6 @@ fn load_xml>(prot: P) -> protocol::Protocol { parse::parse_stream(pfile) } -/// Generate the interfaces for a protocol -/// -/// See this crate's toplevel documentation for details. -/// -/// Args: -/// -/// - `protocol`: a path to the XML file describing the protocol, absolute or relative to -/// the build script using this function. -/// - `target`: the path of the file to store this interfaces in. -pub fn generate_c_interfaces, P2: AsRef>(protocol: P1, target: P2) { - let protocol = load_xml(protocol); - - { - let mut out = OpenOptions::new() - .write(true) - .truncate(true) - .create(true) - .open(&target) - .unwrap(); - write!(&mut out, "{}", c_interface_gen::generate_interfaces(protocol)).unwrap(); - } - - let _ = Command::new("rustfmt").arg(target.as_ref()).status(); -} - -/// Generate the code for a protocol using the Rust implementation -/// -/// See this crate toplevel documentation for details. -/// -/// Args: -/// -/// - `protocol`: a path to the XML file describing the protocol, absolute or relative to -/// the build script using this function. -/// - `target`: the path of the file to store the code in. -/// - `side`: the side (client or server) to generate code for. -pub fn generate_rust_code, P2: AsRef>(prot: P1, target: P2, side: Side) { - let protocol = load_xml(prot); - - { - let mut out = OpenOptions::new() - .write(true) - .truncate(true) - .create(true) - .open(&target) - .unwrap(); - let output = match side { - Side::Client => rust_code_gen::generate_protocol_client(protocol), - Side::Server => rust_code_gen::generate_protocol_server(protocol), - }; - - write!(&mut out, "{}", output).unwrap(); - } - - let _ = Command::new("rustfmt").arg(target.as_ref()).status(); -} - /// Generate the code for a protocol using the C system libs /// /// See this crate toplevel documentation for details. @@ -187,7 +117,7 @@ pub fn generate_rust_code, P2: AsRef>(prot: P1, target: P2 /// the build script using this function. /// - `target`: the path of the file to store the code in. /// - `side`: the side (client or server) to generate code for. -pub fn generate_c_code, P2: AsRef>(prot: P1, target: P2, side: Side) { +pub fn generate_code, P2: AsRef>(prot: P1, target: P2, side: Side) { let protocol = load_xml(prot); { @@ -209,38 +139,6 @@ pub fn generate_c_code, P2: AsRef>(prot: P1, target: P2, s let _ = Command::new("rustfmt").arg(target.as_ref()).status(); } -/// Generate the interfaces for a protocol from/to IO streams -/// -/// Like `generate_c_interfaces`, but takes IO Streams directly rather than filenames -/// -/// Args: -/// -/// - `protocol`: an object `Read`-able containing the XML protocol file -/// - `target`: a `Write`-able object to which the generated code will be outputted to -pub fn generate_c_interfaces_streams(protocol: P1, target: &mut P2) { - let protocol = parse::parse_stream(protocol); - write!(target, "{}", c_interface_gen::generate_interfaces(protocol)).unwrap(); -} - -/// Generate the code for a protocol from/to IO streams using the rust implementation -/// -/// Like `generate_code`, but takes IO Streams directly rather than filenames -/// -/// Args: -/// -/// - `protocol`: an object `Read`-able containing the XML protocol file -/// - `target`: a `Write`-able object to which the generated code will be outputted to -/// - `side`: the side (client or server) to generate code for. -pub fn generate_rust_code_streams(protocol: P1, target: &mut P2, side: Side) { - let protocol = parse::parse_stream(protocol); - let output = match side { - Side::Client => rust_code_gen::generate_protocol_client(protocol), - Side::Server => rust_code_gen::generate_protocol_server(protocol), - }; - - write!(target, "{}", output).unwrap(); -} - /// Generate the code for a protocol from/to IO streams using the C system libs /// /// Like `generate_code`, but takes IO Streams directly rather than filenames @@ -250,7 +148,7 @@ pub fn generate_rust_code_streams(protocol: P1, target: &mu /// - `protocol`: an object `Read`-able containing the XML protocol file /// - `target`: a `Write`-able object to which the generated code will be outputted to /// - `side`: the side (client or server) to generate code for. -pub fn generate_c_code_streams(protocol: P1, target: &mut P2, side: Side) { +pub fn generate_code_streams(protocol: P1, target: &mut P2, side: Side) { let protocol = parse::parse_stream(protocol); let output = match side { Side::Client => c_code_gen::generate_protocol_client(protocol), diff --git a/wayland-scanner/src/rust_code_gen.rs b/wayland-scanner/src/rust_code_gen.rs deleted file mode 100644 index 0eb6cb6e1db..00000000000 --- a/wayland-scanner/src/rust_code_gen.rs +++ /dev/null @@ -1,124 +0,0 @@ -use proc_macro2::{Ident, Span, TokenStream}; - -use common_gen::*; -use protocol::*; -use util::*; -use Side; - -pub(crate) fn generate_protocol_client(protocol: Protocol) -> TokenStream { - let modules = protocol.interfaces.iter().map(|iface| { - let doc_attr = iface.description.as_ref().map(description_to_doc_attr); - let mod_name = Ident::new(&iface.name, Span::call_site()); - let iface_name = Ident::new(&snake_to_camel(&iface.name), Span::call_site()); - - let enums = &iface.enums; - let requests = gen_messagegroup( - &Ident::new("Request", Span::call_site()), - Side::Client, - false, - &iface.requests, - None, - ); - let events = gen_messagegroup( - &Ident::new("Event", Span::call_site()), - Side::Client, - true, - &iface.events, - None, - ); - let interface = gen_interface( - &iface_name, - &iface.name, - iface.version, - None, - Side::Client, - ); - let object_methods = gen_object_methods(&iface_name, &iface.requests, Side::Client); - let event_handler_trait = gen_event_handler_trait( - &iface_name, &iface.events, Side::Client); - let sinces = gen_since_constants(&iface.requests, &iface.events); - - quote! { - #doc_attr - pub mod #mod_name { - use super::{ - Proxy, NewProxy, AnonymousObject, Interface, MessageGroup, MessageDesc, ArgumentType, Object, - Message, Argument, ObjectMetadata, HandledBy - }; - - #(#enums)* - #requests - #events - #interface - #object_methods - #event_handler_trait - #sinces - } - } - }); - - quote! { - #(#modules)* - } -} - -pub(crate) fn generate_protocol_server(protocol: Protocol) -> TokenStream { - let modules = protocol - .interfaces - .iter() - // display and registry are handled specially - .filter(|iface| iface.name != "wl_display" && iface.name != "wl_registry") - .map(|iface| { - let doc_attr = iface.description.as_ref().map(description_to_doc_attr); - let mod_name = Ident::new(&iface.name, Span::call_site()); - let iface_name = Ident::new(&snake_to_camel(&iface.name), Span::call_site()); - - let enums = &iface.enums; - let requests = gen_messagegroup( - &Ident::new("Request", Span::call_site()), - Side::Server, - true, - &iface.requests, - None, - ); - let events = gen_messagegroup( - &Ident::new("Event", Span::call_site()), - Side::Server, - false, - &iface.events, - None, - ); - let interface = gen_interface( - &Ident::new(&snake_to_camel(&iface.name), Span::call_site()), - &iface.name, - iface.version, - None, - Side::Server, - ); - let object_methods = gen_object_methods(&iface_name, &iface.events, Side::Server); - let request_handler_trait = gen_event_handler_trait(&iface_name, &iface.requests, Side::Server); - let sinces = gen_since_constants(&iface.requests, &iface.events); - - quote! { - #doc_attr - pub mod #mod_name { - use super::{ - Resource, NewResource, AnonymousObject, Interface, MessageGroup, MessageDesc, - ArgumentType, Object, Message, Argument, ObjectMetadata, HandledBy - }; - - #(#enums)* - #requests - #events - #interface - #object_methods - #request_handler_trait - #sinces - } - } - }); - - quote! { - #(#modules)* - } -} diff --git a/wayland-server/Cargo.toml b/wayland-server/Cargo.toml index c90938cb9bd..32016abfd69 100644 --- a/wayland-server/Cargo.toml +++ b/wayland-server/Cargo.toml @@ -15,7 +15,7 @@ travis-ci = { repository = "Smithay/wayland-rs" } [dependencies] wayland-commons = { version = "0.22.2", path = "../wayland-commons" } -wayland-sys = { version = "0.22.2", features = ["server"], path = "../wayland-sys", optional = true } +wayland-sys = { version = "0.22.2", path = "../wayland-sys" } bitflags = "1.0" downcast-rs = "1.0" libc = "0.2" @@ -27,5 +27,5 @@ calloop = ">=0.3.1, <0.5" wayland-scanner = { version = "0.22.2", path = "../wayland-scanner" } [features] -native_lib = [ "wayland-sys", "wayland-commons/native_lib" ] +native_lib = [ "wayland-sys/server" ] dlopen = [ "wayland-sys/dlopen", "native_lib" ] diff --git a/wayland-server/build.rs b/wayland-server/build.rs index d9446e83e42..1de648768f8 100644 --- a/wayland-server/build.rs +++ b/wayland-server/build.rs @@ -10,11 +10,5 @@ fn main() { let out_dir_str = var("OUT_DIR").unwrap(); let out_dir = Path::new(&out_dir_str); - if var("CARGO_FEATURE_NATIVE_LIB").ok().is_some() { - // Generate the C code - generate_c_code(protocol_file, out_dir.join("wayland_c_api.rs"), Side::Server); - generate_c_interfaces(protocol_file, out_dir.join("wayland_c_interfaces.rs")); - } else { - generate_rust_code(protocol_file, out_dir.join("wayland_rust_api.rs"), Side::Server); - } + generate_code(protocol_file, out_dir.join("wayland_api.rs"), Side::Server); } diff --git a/wayland-server/src/lib.rs b/wayland-server/src/lib.rs index 0027b7cec3e..b66c6bf618f 100644 --- a/wayland-server/src/lib.rs +++ b/wayland-server/src/lib.rs @@ -84,8 +84,7 @@ extern crate mio; extern crate nix; extern crate wayland_commons; -#[cfg(feature = "native_lib")] -#[macro_use] +#[cfg_attr(feature = "native_lib", macro_use)] extern crate wayland_sys; mod client; @@ -102,13 +101,11 @@ pub use anonymous_object::AnonymousObject; pub use wayland_commons::utils::UserDataMap; pub use wayland_commons::{Interface, MessageGroup, NoMessage}; -#[cfg(feature = "native_lib")] /// C-associated types /// /// Required for plugging wayland-scanner generated protocols /// or interfacing with C code using wayland objects. pub mod sys { - pub use super::generated::c_interfaces as protocol_interfaces; pub use wayland_sys::{common, server}; } @@ -125,39 +122,17 @@ pub use imp::ResourceMap; /// Generated interfaces for the core wayland protocol pub mod protocol { - #[cfg(feature = "native_lib")] - pub use generated::c_api::*; - #[cfg(not(feature = "native_lib"))] - pub use generated::rust_api::*; -} - -mod generated { #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] #![allow(non_upper_case_globals, non_snake_case, unused_imports)] #![allow(missing_docs)] #![cfg_attr(feature = "cargo-clippy", allow(clippy))] - #[cfg(feature = "native_lib")] - pub mod c_interfaces { - include!(concat!(env!("OUT_DIR"), "/wayland_c_interfaces.rs")); - } - #[cfg(feature = "native_lib")] - pub mod c_api { - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use wayland_sys as sys; - pub(crate) use {AnonymousObject, HandledBy, NewResource, Resource, ResourceMap}; - include!(concat!(env!("OUT_DIR"), "/wayland_c_api.rs")); - } - #[cfg(not(feature = "native_lib"))] - pub mod rust_api { - pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; - pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; - pub(crate) use wayland_commons::{Interface, MessageGroup}; - pub(crate) use {AnonymousObject, HandledBy, NewResource, Resource, ResourceMap}; - include!(concat!(env!("OUT_DIR"), "/wayland_rust_api.rs")); - } + pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; + pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc}; + pub(crate) use wayland_commons::{Interface, MessageGroup}; + pub(crate) use wayland_sys as sys; + pub(crate) use {AnonymousObject, HandledBy, NewResource, Resource, ResourceMap}; + include!(concat!(env!("OUT_DIR"), "/wayland_api.rs")); } mod anonymous_object { @@ -175,8 +150,7 @@ mod anonymous_object { type Event = NoMessage; const NAME: &'static str = ""; const VERSION: u32 = 0; - #[cfg(feature = "native_lib")] - fn c_interface() -> *const ::sys::common::wl_interface { + fn c_interface() -> *const ::wayland_sys::common::wl_interface { ::std::ptr::null() } } diff --git a/wayland-server/src/native_lib/resource.rs b/wayland-server/src/native_lib/resource.rs index fac2035233b..0cc4be4a00b 100644 --- a/wayland-server/src/native_lib/resource.rs +++ b/wayland-server/src/native_lib/resource.rs @@ -188,6 +188,23 @@ impl ResourceInner { } } + pub unsafe fn make_child_for(&self, id: u32) -> Option { + let version = self.version(); + let client_ptr = match self.client() { + Some(c) => c.ptr(), + None => return None, + }; + let new_ptr = ffi_dispatch!( + WAYLAND_SERVER_HANDLE, + wl_resource_create, + client_ptr, + J::c_interface(), + version as i32, + id + ); + Some(NewResourceInner { ptr: new_ptr }) + } + pub(crate) fn clone(&self) -> ResourceInner { ResourceInner { internal: self.internal.clone(), diff --git a/wayland-server/src/resource.rs b/wayland-server/src/resource.rs index 1adccd20276..e5ff4c5888d 100644 --- a/wayland-server/src/resource.rs +++ b/wayland-server/src/resource.rs @@ -3,7 +3,6 @@ use wayland_commons::{Interface, MessageGroup}; use Client; -#[cfg(feature = "native_lib")] use wayland_sys::server::*; use imp::{NewResourceInner, ResourceInner}; @@ -127,13 +126,24 @@ impl Resource { } } -#[cfg(feature = "native_lib")] impl Resource { /// Check whether this resource is managed by the library or not /// /// See `from_c_ptr` for details. + /// + /// NOTE: This method will panic if called while the `native_lib` feature is not + /// activated pub fn is_external(&self) -> bool { - self.inner.is_external() + #[cfg(feature = "native_lib")] + { + self.inner.is_external() + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); + } } /// Get a raw pointer to the underlying wayland object @@ -141,8 +151,20 @@ impl Resource { /// Retrieve a pointer to the object from the `libwayland-server.so` library. /// You will mostly need it to interface with C libraries needing access /// to wayland objects (to initialize an opengl context for example). + /// + /// NOTE: This method will panic if called while the `native_lib` feature is not + /// activated pub fn c_ptr(&self) -> *mut wl_resource { - self.inner.c_ptr() + #[cfg(feature = "native_lib")] + { + self.inner.c_ptr() + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); + } } /// Create a `Resource` instance from a C pointer @@ -164,13 +186,40 @@ impl Resource { /// /// In order to handle protocol races, invoking it with a NULL pointer will /// create an already-dead object. - pub unsafe fn from_c_ptr(ptr: *mut wl_resource) -> Self + /// + /// NOTE: This method will panic if called while the `native_lib` feature is not + /// activated + pub unsafe fn from_c_ptr(_ptr: *mut wl_resource) -> Self where I: From>, { - Resource { - _i: ::std::marker::PhantomData, - inner: ResourceInner::from_c_ptr::(ptr), + #[cfg(feature = "native_lib")] + { + Resource { + _i: ::std::marker::PhantomData, + inner: ResourceInner::from_c_ptr::(_ptr), + } + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); + } + } + + #[doc(hidden)] + // This method is for scanner-generated use only + pub unsafe fn make_child_for(&self, _id: u32) -> Option> { + #[cfg(feature = "native_lib")] + { + self.inner.make_child_for::(_id).map(NewResource::wrap) + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); } } } @@ -319,7 +368,6 @@ impl NewResource { } } -#[cfg(feature = "native_lib")] impl NewResource { /// Get a raw pointer to the underlying wayland object /// @@ -329,8 +377,20 @@ impl NewResource { /// /// Use this if you need to pass an unimplemented object to the C library /// you are interfacing with. + /// + /// NOTE: This method will panic if called while the `native_lib` feature is not + /// activated pub fn c_ptr(&self) -> *mut wl_resource { - self.inner.c_ptr() + #[cfg(feature = "native_lib")] + { + self.inner.c_ptr() + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); + } } /// Create a `NewResource` instance from a C pointer. @@ -339,10 +399,22 @@ impl NewResource { /// can be safely implemented. As implementing it will overwrite any previously /// associated data or implementation, this can cause weird errors akin to /// memory corruption if it was not the case. - pub unsafe fn from_c_ptr(ptr: *mut wl_resource) -> Self { - NewResource { - _i: ::std::marker::PhantomData, - inner: NewResourceInner::from_c_ptr(ptr), + /// + /// NOTE: This method will panic if called while the `native_lib` feature is not + /// activated + pub unsafe fn from_c_ptr(_ptr: *mut wl_resource) -> Self { + #[cfg(feature = "native_lib")] + { + NewResource { + _i: ::std::marker::PhantomData, + inner: NewResourceInner::from_c_ptr(_ptr), + } + } + #[cfg(not(feature = "native_lib"))] + { + panic!( + "[wayland-server] C interfacing methods are not available without the `native_lib` feature" + ); } } } diff --git a/wayland-sys/Cargo.toml b/wayland-sys/Cargo.toml index d00134568ef..0a16c70986e 100644 --- a/wayland-sys/Cargo.toml +++ b/wayland-sys/Cargo.toml @@ -12,16 +12,16 @@ categories = ["external-ffi-bindings"] travis-ci = { repository = "Smithay/wayland-rs" } [dependencies] -dlib = { version = "0.4" } +dlib = { version = "0.4", optional = true } libc = { version = "0.2", optional = true } lazy_static = { version = "1", optional = true } [features] dlopen = ["dlib/dlopen", "lazy_static"] -client = [] -cursor = [] -egl = [] -server = ["libc"] +client = [ "dlib" ] +cursor = [ "client" ] +egl = [ "client" ] +server = ["libc", "dlib" ] [package.metadata.docs.rs] all-features = true diff --git a/wayland-sys/src/client.rs b/wayland-sys/src/client.rs index dfe22ccf339..5b1ed2a3ec6 100644 --- a/wayland-sys/src/client.rs +++ b/wayland-sys/src/client.rs @@ -4,13 +4,16 @@ #![cfg_attr(rustfmt, rustfmt_skip)] +#[cfg(feature = "client")] use super::common::*; +#[cfg(feature = "client")] use std::os::raw::{c_char, c_int, c_void}; pub enum wl_proxy {} pub enum wl_display {} pub enum wl_event_queue {} +#[cfg(feature = "client")] external_library!(WaylandClient, "wayland-client", functions: // display creation and destruction @@ -80,7 +83,7 @@ external_library!(WaylandClient, "wayland-client", fn wl_proxy_marshal(*mut wl_proxy, u32) -> (), ); -#[cfg(feature = "dlopen")] +#[cfg(all(feature = "client", feature = "dlopen"))] lazy_static!( pub static ref WAYLAND_CLIENT_OPTION: Option = { // This is a workaround for Ubuntu 17.04, which doesn't have a bare symlink @@ -111,11 +114,11 @@ lazy_static!( }; ); -#[cfg(not(feature = "dlopen"))] +#[cfg(all(feature = "client", not(feature = "dlopen")))] pub fn is_lib_available() -> bool { true } -#[cfg(feature = "dlopen")] +#[cfg(all(feature = "client", feature = "dlopen"))] pub fn is_lib_available() -> bool { WAYLAND_CLIENT_OPTION.is_some() } diff --git a/wayland-sys/src/lib.rs b/wayland-sys/src/lib.rs index fbb65bcc5b3..2f23d43ec31 100644 --- a/wayland-sys/src/lib.rs +++ b/wayland-sys/src/lib.rs @@ -36,6 +36,7 @@ // it's what happens when running `cargo test --all` from the workspace root), // dlib isn't actually used. This is not an issue, so don't warn about it. #[allow(unused_imports)] +#[cfg(any(feature = "client", feature = "server"))] #[macro_use] extern crate dlib; @@ -60,10 +61,8 @@ pub static RUST_MANAGED: u8 = 42; pub mod common; -#[cfg(feature = "client")] pub mod client; -#[cfg(feature = "server")] pub mod server; #[cfg(all(feature = "egl", feature = "client"))] diff --git a/wayland-sys/src/server.rs b/wayland-sys/src/server.rs index 8bb76f777f9..ace036ffbdc 100644 --- a/wayland-sys/src/server.rs +++ b/wayland-sys/src/server.rs @@ -5,8 +5,11 @@ #![cfg_attr(rustfmt, rustfmt_skip)] use super::common::*; +#[cfg(feature = "server")] use libc::{gid_t, pid_t, uid_t}; -use std::os::raw::{c_char, c_int, c_void}; +#[cfg(feature = "server")] +use std::os::raw::c_char; +use std::os::raw::{c_int, c_void}; pub enum wl_client {} pub enum wl_display {} @@ -36,6 +39,7 @@ pub struct wl_signal { pub listener_list: wl_list, } +#[cfg(feature = "server")] external_library!(WaylandServer, "wayland-server", functions: // wl_client @@ -138,7 +142,7 @@ external_library!(WaylandServer, "wayland-server", fn wl_resource_post_error(*mut wl_resource, u32, *const c_char) -> (), ); -#[cfg(feature = "dlopen")] +#[cfg(all(feature = "server", feature = "dlopen"))] lazy_static!( pub static ref WAYLAND_SERVER_OPTION: Option = { // This is a workaround for Ubuntu 17.04, which doesn't have a bare symlink @@ -169,17 +173,18 @@ lazy_static!( }; ); -#[cfg(not(feature = "dlopen"))] +#[cfg(all(feature = "server", not(feature = "dlopen")))] pub fn is_lib_available() -> bool { true } -#[cfg(feature = "dlopen")] +#[cfg(all(feature = "server", feature = "dlopen"))] pub fn is_lib_available() -> bool { WAYLAND_SERVER_OPTION.is_some() } +#[cfg(feature = "server")] pub mod signal { - #![allow(cast_ptr_alignment)] + #![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] #[cfg(not(feature = "dlopen"))] use super::{wl_list_init, wl_list_insert}; use super::{wl_listener, wl_notify_func_t, wl_signal};