Skip to content

Commit

Permalink
Use cargo workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenByteDev committed Jul 29, 2023
1 parent b408a1c commit 33a82db
Show file tree
Hide file tree
Showing 42 changed files with 342 additions and 334 deletions.
76 changes: 7 additions & 69 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,69 +1,7 @@
[package]
name = "dlopen2"
version = "0.5.0"
authors = [
"Szymon Wieloch <szymon.wieloch@gmail.com>",
"Ahmed Masud <ahmed.masud@saf.ai>",
"OpenByte <development.openbyte@gmail.com>"]
description = "Library for opening and operating on dynamic link libraries (also known as shared objects or shared libraries)."
keywords = [
#common functions
"dlopen", "dll", "so", "dylib", "shared"]
license = "MIT"
repository = "https://github.com/OpenByteDev/dlopen2"
edition = "2021"

[dependencies]
dlopen2_derive = { path = "dlopen2-derive", version = "0.3", optional = true }
once_cell = "1.18"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winnt", "minwindef", "winerror", "libloaderapi", "errhandlingapi", "dbghelp", "processthreadsapi", "basetsd"] }

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[dev-dependencies]
const-cstr = "0.3"
regex = "1.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
example_dylib = { path = "example-dylib" }
current_platform = "0.2"


[features]
default = ["wrapper", "symbor", "derive"]
wrapper = []
symbor = []
derive = ["dlopen2_derive"]
doc_cfg = []


[[example]]
name = "raw"
crate-type = ["bin"]

[[example]]
name = "symbor"
crate-type = ["bin"]

[[example]]
name = "symbor_api"
crate-type = ["bin"]

[[example]]
name = "wrapper_api"
crate-type = ["bin"]

[[example]]
name = "raw_addr_info"
crate-type = ["bin"]

[[example]]
name = "wrapper_multi_api"
crate-type = ["bin"]


[package.metadata.docs.rs]
all-features = true
[workspace]
members = [
"dlopen2",
"dlopen2-derive",
"example-dylib",
]
resolver = "2"
3 changes: 2 additions & 1 deletion dlopen2-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ authors = ["Szymon Wieloch <szymon.wieloch@gmail.com>",
"OpenByte <development.openbyte@gmail.com>"]
description = "Derive macros for the dlopen2 crate."
license = "MIT"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
syn = "2.0"
syn = { version = "2.0", features = ["extra-traits"] }
quote = "1.0"
proc-macro2 = "1.0"
68 changes: 68 additions & 0 deletions dlopen2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "dlopen2"
version = "0.5.0"
authors = [
"Szymon Wieloch <szymon.wieloch@gmail.com>",
"Ahmed Masud <ahmed.masud@saf.ai>",
"OpenByte <development.openbyte@gmail.com>"]
description = "Library for opening and operating on dynamic link libraries (also known as shared objects or shared libraries)."
keywords = [
"dlopen", "dll", "so", "dylib", "shared"]
license = "MIT"
repository = "https://github.com/OpenByteDev/dlopen2"
edition = "2021"

[dependencies]
dlopen2_derive = { path = "../dlopen2-derive", version = "0.3", optional = true }
once_cell = "1.18"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winnt", "minwindef", "winerror", "libloaderapi", "errhandlingapi", "dbghelp", "processthreadsapi", "basetsd"] }

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[dev-dependencies]
const-cstr = "0.3"
regex = "1.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
example_dylib = { path = "../example-dylib" }
current_platform = "0.2"


[features]
default = ["wrapper", "symbor", "derive"]
wrapper = []
symbor = []
derive = ["dlopen2_derive"]
doc_cfg = []


[[example]]
name = "raw"
crate-type = ["bin"]

[[example]]
name = "symbor"
crate-type = ["bin"]

[[example]]
name = "symbor_api"
crate-type = ["bin"]

[[example]]
name = "wrapper_api"
crate-type = ["bin"]

[[example]]
name = "raw_addr_info"
crate-type = ["bin"]

[[example]]
name = "wrapper_multi_api"
crate-type = ["bin"]


[package.metadata.docs.rs]
all-features = true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
mod commons;
use commons::example_lib_path;

use dlopen2::wrapper::{Container, WrapperApi, WrapperMultiApi};
use std::os::raw::c_int;

//Define 3 APIs:

#[derive(WrapperApi)]
struct Working1<'a> {
rust_fun_print_something: fn(),
c_fun_add_two: unsafe extern "C" fn(arg: c_int) -> c_int,
rust_i32_mut: &'a mut i32,
}

#[derive(WrapperApi)]
struct Working2<'a> {
rust_fun_add_one: fn(arg: i32) -> i32,
c_fun_print_something_else: extern "C" fn(),
rust_i32: &'a i32,
}

//this one wont' work in the example
#[derive(WrapperApi)]
struct NotWorking<'a> {
some_rust_fun: fn(arg: i32) -> i32,
some_c_fun: extern "C" fn(),
some_rust_num: &'a u32,
}

//Now define a multi wrapper that wraps sub APIs into one bigger API.
//This example assumes that the first API is obligatory and the other two are optional.

#[derive(WrapperMultiApi)]
struct Api<'a> {
pub obligatory: Working1<'a>,
pub optional1: Option<Working2<'a>>,
pub optional2: Option<NotWorking<'a>>,
}

fn main() {
let lib_path = example_lib_path();
let api: Container<Api> = unsafe { Container::load(lib_path) }.expect("Could not open library");
//use obligatory API:
api.obligatory.rust_fun_print_something();
println!("4+2={}", unsafe { api.obligatory.c_fun_add_two(4) });
println!("static i32={}", api.obligatory.rust_i32_mut());

match api.optional1 {
Some(ref opt) => {
println!("First optional API loaded!");
println!("3+1={}", opt.rust_fun_add_one(3));
opt.c_fun_print_something_else();
println!("static value is {}", opt.rust_i32())
}
None => println!("Could not load the first optional API"),
}

match api.optional2 {
Some(ref opt) => {
opt.some_c_fun();
println!("Second optional API loaded");
println!("result of some function: {}", opt.some_rust_fun(3));
println!("static value is {}", opt.some_rust_num());
}
None => println!("Could not load the second optional API"),
}
}
mod commons;
use commons::example_lib_path;

use dlopen2::wrapper::{Container, WrapperApi, WrapperMultiApi};
use std::os::raw::c_int;

//Define 3 APIs:

#[derive(WrapperApi)]
struct Working1<'a> {
rust_fun_print_something: fn(),
c_fun_add_two: unsafe extern "C" fn(arg: c_int) -> c_int,
rust_i32_mut: &'a mut i32,
}

#[derive(WrapperApi)]
struct Working2<'a> {
rust_fun_add_one: fn(arg: i32) -> i32,
c_fun_print_something_else: extern "C" fn(),
rust_i32: &'a i32,
}

//this one wont' work in the example
#[derive(WrapperApi)]
struct NotWorking<'a> {
some_rust_fun: fn(arg: i32) -> i32,
some_c_fun: extern "C" fn(),
some_rust_num: &'a u32,
}

//Now define a multi wrapper that wraps sub APIs into one bigger API.
//This example assumes that the first API is obligatory and the other two are optional.

#[derive(WrapperMultiApi)]
struct Api<'a> {
pub obligatory: Working1<'a>,
pub optional1: Option<Working2<'a>>,
pub optional2: Option<NotWorking<'a>>,
}

fn main() {
let lib_path = example_lib_path();
let api: Container<Api> = unsafe { Container::load(lib_path) }.expect("Could not open library");
//use obligatory API:
api.obligatory.rust_fun_print_something();
println!("4+2={}", unsafe { api.obligatory.c_fun_add_two(4) });
println!("static i32={}", api.obligatory.rust_i32_mut());

match api.optional1 {
Some(ref opt) => {
println!("First optional API loaded!");
println!("3+1={}", opt.rust_fun_add_one(3));
opt.c_fun_print_something_else();
println!("static value is {}", opt.rust_i32())
}
None => println!("Could not load the first optional API"),
}

match api.optional2 {
Some(ref opt) => {
opt.some_c_fun();
println!("Second optional API loaded");
println!("result of some function: {}", opt.some_rust_fun(3));
println!("static value is {}", opt.some_rust_num());
}
None => println!("Could not load the second optional API"),
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 33a82db

Please sign in to comment.