AltF02 / x11-rs

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

Consolidate types and constants #84

Open ghost opened 6 years ago

ghost commented 6 years ago

I have a few issues with the way these crates are structured.

(1) x11 and x11-dl both expose their own copies of all native types and constants. This is currently done using symlinks to the source files, but it would be much nicer to just include the types in one crate (x11) and have others (x11-dl) depend on this crate for its types and constants (but of course without the need to statically link any C libraries to use these types). If backwards compatibility is desired, these types and constants can be pub used into x11-dl, but I don't think this is the best thing to do. This and the next problem would likely entail a version bump to 3.0.0...

(2) Everything currently lies within public submodules within the main crate(s). For example, one of the most commonly used types is x11::xlib::Display/x11_dl::xlib::Display. In addition to moving types into one crate, I believe these should be exposed to the root of the crate (i.e. x11::Display). They're currently lumped into modules somewhat arbitrarily, based only on what X library they seem to be most relevant to. If we move everything into the crate root, it will (a) be easier to find and reference these types and (b) be easier to transition to bindings generated from the C headers if desired.

ghost commented 6 years ago

Now that #90 has occurred, I'll be putting more thought into this and #87. The existing types and constants can remain mostly unchanged. The x11_link! macro made sense at the time, but I'm thinking now that gl_generator has a nicer solution to generating bindings. There is no XML spec for the X11 library functions AFAIK, but they can still be loaded either from a serde format like JSON or, even better, an easily parsable, minimal subset of C function declarations. Examples.

// xlib.json
{
    functions: [
        { name: "XOpenDisplay", return_type: "*mut Display", params: ["*const c_char"] }
    ]
}

or

// xlib.cdecls
Display *XOpenDisplay (const char *);