Giter Site home page Giter Site logo

aldaronlau / dl_api Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 0.0 124 KB

The easiest, simplest and safest way to load dynamic (shared object) libraries from Rust!

License: Apache License 2.0

Rust 100.00%
rust dl-api macros ffi abi shared-object shared-library dynamic-linking

dl_api's Introduction

DL API

The easiest, simplest and safest way to load dynamic (shared object) libraries from Rust!

Build Status Docs crates.io

  • Macro to create a structure that dynamically loads a C API
  • Works on Linux (and probably other unix) and Windows

Roadmap to 1.0 (Future Features)

  • Make it easier to load parts of API at any time (modular loading from same .so file).
  • Support some other obscure OS's.
  • Different loading macro for Rust ABI / other ABIS (possible ABI parameter to the macro?)
  • Make sure it's perfect.

Table of Contents

Getting Started

Add the following to your Cargo.toml.

[dependencies]
dl_api = "0.4"

Example

The code inside of the curly braces for link!() matches exactly with code inside of the curly braces for extern "C". This makes it easy for you to turn your extern "C"s into link!()s.

// Shared object: either "libmylibrary.so.1", "mylibrary-1.dll" or "libMyLibrary.dylib"
dl_api::link!(MyApi, "libmylibrary.so.1", {
    fn cFunction(param_name: ParamType) -> ReturnType;
});

fn main() {
    let api = MyApi::new().unwrap(); // unwrap the `Result`.

    let rtn: ReturnType = unsafe {
        (api.cFunction)(0);
    };
}

API

API documentation can be found on docs.rs.

Features

There are no optional features.

Upgrade

You can use the changelog to facilitate upgrading this crate as a dependency.

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.

Contributors are always welcome (thank you for being interested!), whether it be a bug report, bug fix, feature request, feature implementation or whatever. Don't be shy about getting involved. I always make time to fix bugs, so usually a patched version of the library will be out a few days after a report. Features requests will not complete as fast. If you have any questions, design critques, or want me to find you something to work on based on your skill level, you can email me at [email protected]. Otherwise, here's a link to the issues on GitHub. Before contributing, check out the contribution guidelines, and, as always, make sure to follow the code of conduct.

dl_api's People

Contributors

aldaronlau avatar dependabot-preview[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dl_api's Issues

Crate fails to build on Windows

error[E0432]: unresolved import `Error`
  --> C:\Users\appveyor\.cargo\registry\src\github.com-1ecc6299db9ec823\dl_api-0.3.0\src\library\windows.rs:14:5
   |
14 | use Error;
   |     ^^^^^ no `Error` external crate

Seems like you didn't test the edition upgrade on Windows. Do consider setting up CI for Windows on travis or appveyor to help catch these sort of things in the future.

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.