AltF02 / x11-rs

Rust bindings for X11 libraries
https://docs.rs/x11
MIT License
206 stars 66 forks source link

Version 3 #40

Closed ghost closed 7 years ago

ghost commented 8 years ago

Edit (20 October 2016): I'm working on a generator using clang. There will be a major restructure. The x11 crate will have function bindings moved into a separate crate called x11-static while x11 will only contain only types and constants (similar to the winapi crate). Both x11-static and x11-dl will depend on x11 for these items so there will no longer be duplicates. x11-generator will be a build dependency to generate the function bindings and will be available for custom bindings as well.

x11 and x11-generator will be built using x11-parser, which scans the C headers to generate bindings. The code generated by x11-parser will be commited to the repository, so the C headers won't have to be present when building the Rust bindings.

I am considering changing x11-dl to use lazy initialization. This will prevent the loader functions from failing if there are missing functions in order to avoid versioned structs. Instead, calling a missing function will cause a panic.

Note: Version 3 probably won't be stable until untagged unions are a stable feature in Rust.

ghost commented 8 years ago

@tomaka

tomaka commented 8 years ago

For plan A you should keep in mind that some systems don't have X11, so that should be detectable.

ghost commented 8 years ago

There would be functions to check the availability of libraries and functions, so you can avoid calling missing functions and causing a panic. Probably something like:

pub enum Lib {
    Xlib,
    Glx,
    ...
}

pub fn check_lib (lib: Lib) -> bool { ... }
pub fn check_fn (lib: Lib, fname: &str) -> bool { ... }
pub fn check_fns (lib: Lib, fnames: &[&str]) -> bool { ... }

One of the current problems is that Ubuntu LTS 14.04 has an older version of Xrandr which is missing 5 of the functions defined in x11::xrandr::Xrandr, so we added a separate struct (x11::xrandr::Xrandr_2_2_0) which omits these functions. Both plans described above will have better ways to avoid this problem.

bennofs commented 8 years ago

I'm wondering if perhaps x11-dl could also be made just a feature of the main x11 crate? It mostly uses the same code anyway, and this way the code sharing could be better IMO. Of course this would be a breaking change, that's why I'm adding this comment to the version 3 thread.

ghost commented 8 years ago

My current plan is to define all types in x11 and pub use them into x11-dl when version 3.0 comes around. I think this may even be possible before 3.0 without breaking anything.

eazar001 commented 8 years ago

A suggestion for version 3: Include some more bindings for xfixes extension if possible.

ghost commented 8 years ago

Like winapi-rs bindings are currently being added by hand, which is why things are missing. If xfixes bindings are needed, I'll see if I have some time to add them. Unfortunately, version 3 may have to wait for untagged unions, or else a version 4 would follow shortly after.