lazylink

build check tokio-pipe

Convert extern fn to libdl call procedural macro.

```rust use lazylink::lazylink;

/// comment!

[lazylink]

[link(name = "z")]

extern "C" { /// zlib version #[linkname = "zlibVersion"] fn zlibversion() -> *const std::os::raw::c_char; }

[lazylink(fullname = "libc.so.6")]

mod libc { /// comment! extern "C" { pub(crate) fn puts(v: *const std::os::raw::c_char); } }

fn main() { let ver = unsafe { zlib_version() }; unsafe { libc::puts(ver); } } ```

into

```rust

![feature(prelude_import)]

[prelude_import]

use std::prelude::v1::*;

[macro_use]

extern crate std; use lazylink::lazylink; struct LazyLinkbfde0578a8e5d844<'a> { /// comment! /// zlib version zlibversion: lazylink::libloading::Symbol<'a, unsafe extern "C" fn() -> *const std::os::raw::cchar>, phantom: std::marker::PhantomData &'a ()>, } impl<'a> _LazyLinkbfde0578a8e5d844<'a> { unsafe fn new( lib: &'a lazylink::libloading::Library, ) -> Result { Ok( Self { # [doc = " comment!"] # [doc = " zlib version"] zlibversion : lib . get (b"zlibVersion\x00") ? , _pha ntom : std :: marker :: PhantomData , }, ) } fn get() -> &'static _LazyLinkbfde0578a8e5d844<'static> { static mut LIB: Option = None; static mut FNS: Option<__LazyLinkbfde0578a8e5d844<'static>> = None; static ONCE: std::sync::Once = std::sync::Once::new(); ONCE.callonce(|| unsafe { LIB = Some( lazylink::libloading::Library::new(lazylink::libloading::libraryfilename("z")) .unwrap(), ); FNS = Some(LazyLinkbfde0578a8e5d844::new(LIB.asref().unwrap()).unwrap()); }); unsafe { FNS.asref().unwrap() } } } /// comment! /// zlib version unsafe fn zlibversion() -> *const std::os::raw::cchar { (LazyLinkbfde0578a8e5d844::get().zlibversion)() } mod libc { struct _LazyLink79e825dc6d38824d<'a> { /// comment! puts: lazylink::libloading::Symbol<'a, unsafe extern "C" fn(*const std::os::raw::cchar)>, _phantom: std::marker::PhantomData &'a ()>, } impl<'a> _LazyLink79e825dc6d38824d<'a> { unsafe fn new( lib: &'a lazylink::libloading::Library, ) -> Result { Ok( Self { # [doc = " comment!"] puts : lib . get (b"puts\x00") ? , phantom : std :: marker :: PhantomData , }, ) } fn get() -> &'static _LazyLink79e825dc6d38824d<'static> { static mut LIB: Option = None; static mut FNS: Option<__LazyLink79e825dc6d38824d<'static>> = None; const ONCE: std::sync::Once = std::sync::Once::new(); ONCE.callonce(|| unsafe { LIB = Some(lazylink::libloading::Library::new("libc.so.6").unwrap()); FNS = Some(LazyLink79e825dc6d38824d::new(LIB.asref().unwrap()).unwrap()); }); unsafe { FNS.asref().unwrap() } } } /// comment! pub(crate) unsafe fn puts(v: *const std::os::raw::cchar) { (_LazyLink79e825dc6d38824d::get().puts)(v) } } fn main() { let ver = unsafe { zlibversion() }; unsafe { libc::puts(ver); } } ```

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.