Git Product home page Git Product logo

Comments (17)

 avatar commented on August 29, 2024

I like the idea of compiling a single binary that works with multiple system configurations! I'm not sure how I feel about this being the default behavior, but it would be easy to implement in the form of a feature. Maybe after I play around with it a bit, I'll change my mind and just make it the default anyway. Would it be sufficient to just search /usr/lib and /usr/local/lib for the needed libraries?

from x11-rs.

 avatar commented on August 29, 2024

We can use dylib until std::dynamic_lib is stable.

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

I was thinking of using the shared_library library I wrote.
It provides a macro named shared_library! which is similar to export {} blocks and makes the transition easier (it would also make it easier to revert the changes if wanted).
Example here: https://github.com/tomaka/glutin/blob/master/src/api/caca/ffi.rs

from x11-rs.

 avatar commented on August 29, 2024

I can get started on this as soon as I get home.

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

I thought about working on it myself, but if you do it that would be awesome!

Note that you probably need to add an attribute like #![recursion_limit="200"], or you will reach the recursion limit.

from x11-rs.

 avatar commented on August 29, 2024

I've run into a problem. The shared_library macro doesn't seem to like variadic C functions like XCreateIC. I would comment them out until finding a workaround, but IIRC, glutin uses this function in particular.

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

Arg. I'm aware of this limitation, but I thought that X11 didn't have any variadic function.

from x11-rs.

 avatar commented on August 29, 2024

I may have found a solution, but it's not quite as pretty as I had hoped. I wrote a macro with two patterns: one that takes the usual list of functions, and one that takes a list of functions followed by variadic: and a list of variadic functions, omitting the ellipses in the pattern to make the compiler happy.

  pub fn XWriteBitmapFile (_7: *mut Display, _6: *const c_char, _5: c_ulong, _4: c_uint, _3: c_uint, _2: c_int, _1: c_int) -> c_int,
  pub fn XXorRegion (_3: Region, _2: Region, _1: Region) -> c_int,
variadic:
  pub fn XCreateIC (_1: XIM) -> XIC,
  pub fn XCreateOC (_1: XOM) -> XFontSet,

I'm still working out a bug that's preventing it from compiling, but I should have a test working soon. Should I apply this to shared_library and submit a pull request?

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

Should I apply this to shared_library and submit a pull request?

That would be nice!

from x11-rs.

 avatar commented on August 29, 2024

x11-rs now supports dynamic linking with a temporary macro when the dynamic feature is enabled. This temporary macro will be updated once I can wrap my head around the recursiveness of shared_library!.

from x11-rs.

 avatar commented on August 29, 2024

Example usage:

use x11::xlib::Xlib;

fn do_something_but_not_anything_useful_just_as_an_example () {
  let xlib = Xlib::open().unwrap();
  let display = (xlib.XOpenDisplay)(null());
  (xlib.XCloseDisplay)(display);
}

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

Note that this is a bad usage of Cargo features.
Cargo features are not flags. If a code depends on x11 without dynamic, then adds a dependency on glutin, then x11 will get compiled with the dynamic feature and break the code.

from x11-rs.

 avatar commented on August 29, 2024

Fixed so extern blocks are not removed. The compiler only tries to link the functions if they are actually called, so this shouldn't cause problems. If this turns out to be wrong, another possible solution is to split the dynamic interface into another crate (but still in to same repo and from mostly the same sources).

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

The compiler only tries to link the functions if they are actually called, so this shouldn't cause problems.

Are you sure that it doesn't pass -lx11 to the linker?

from x11-rs.

 avatar commented on August 29, 2024

The build script uses pkg-config, so it might still pass -lX11 if x11-rs was compiled on a system where pkg-config detected Xlib. Because of this, it might not work to have the old API and the dynamic API coexist in one crate unless I'm forgetting another option. I can't remove the old API because it appears that it will soon be used by servo. If you're okay with it, I'll add another crate for the dynamic API. They'll exist in the same repo and use the same sources for bindings, but different sources for internals (such as the x11_link macro).

from x11-rs.

 avatar commented on August 29, 2024

I have the split working in a separate branch (dl_split). If you're okay with the changes, I'll submit a pull request to glutin. The only usage change would be using crate x11_dl instead of x11.

from x11-rs.

tomaka avatar tomaka commented on August 29, 2024

Sure, as long as you publish it on crates.io

from x11-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.