Skip to content

Commit 170b0bb

Browse files
committed
Restructuring dependencies a bit
The user now only has to add `buffi` to the dependencies and we also enforce which version of `bincode` is used for the proc-macro generated code. The error still needs to be manually derived with the buffi provided bincode.
1 parent d864716 commit 170b0bb

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buffi/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@ keywords = ["FFI", "API", "C", "bincode", "serde"]
1010
categories = ["development-tools::ffi"]
1111
readme = "../README.md"
1212

13+
[dependencies.buffi_macro]
14+
version = "=0.3.0"
15+
path = "../buffi_macro"
16+
1317
[dependencies]
1418
serde = { version = "1.0.213", features = ["derive"] }
1519
serde_json = "1.0.132"
1620
serde-generate = { version = "0.26.0", default-features = false, features = ["cpp"] }
1721
serde-reflection = "0.4.0"
18-
rustdoc-types = "0.39.0"
22+
rustdoc-types = "0.39.0"
23+
bincode = { version = "2.0.1", features = ["std", "serde"], default-features = false }
24+
25+
[features]
26+
with_c_api = ["buffi_macro/with_c_api"]
27+
with_tracing = ["buffi_macro/with_tracing"]
28+
default = ["with_c_api"]

buffi/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ use std::path::PathBuf;
3333
use std::path::{Component, Path};
3434
use std::process::{Output, Stdio};
3535

36+
pub use bincode;
37+
pub use buffi_macro::*;
38+
3639
const FUNCTION_PREFIX: &str = "buffi";
3740

3841
#[derive(Debug, serde::Deserialize)]

buffi_macro/src/proc_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn generate_exported_function<'a>(
146146
std::slice::from_raw_parts(#n, #n_size)
147147
}
148148
};
149-
let #n = bincode::serde::decode_from_slice(slice, bincode::config::legacy())?.0;
149+
let #n = buffi::bincode::serde::decode_from_slice(slice, buffi::bincode::config::legacy())?.0;
150150
})
151151
} else {
152152
None
@@ -286,14 +286,14 @@ fn generate_exported_function<'a>(
286286
Err(crate::errors::SerializableError::from(e))
287287
}
288288
};
289-
let bytes = match bincode::serde::encode_to_vec(&res, bincode::config::legacy()) {
289+
let bytes = match buffi::bincode::serde::encode_to_vec(&res, buffi::bincode::config::legacy()) {
290290
Ok(bytes) => {
291291
bytes
292292
}
293293
Err(e) => {
294294
#tracing_serializable_w
295295
res = Err(e.into());
296-
match bincode::serde::encode_to_vec(&res, bincode::config::legacy()) {
296+
match buffi::bincode::serde::encode_to_vec(&res, buffi::bincode::config::legacy()) {
297297
Ok(bytes) => {
298298
bytes
299299
}

example/buffi_example/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ publish = false
88
crate-type = ["staticlib"]
99

1010
[dependencies]
11-
buffi_macro = { path = "../../buffi_macro" }
12-
bincode = { version = "2.0.1", features = ["std", "serde"], default-features = false }
11+
buffi = { path = "../../buffi" }
1312
serde = { version = "1.0.214", features = ["derive"] }
1413
tokio = { version = "1.41.1", features = ["rt-multi-thread"] }
1514
cgmath = { version = "0.18.0", features = ["serde"] }

example/buffi_example/src/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ impl From<Box<dyn Any + Send>> for SerializableError {
2424
}
2525
}
2626

27-
impl From<bincode::error::DecodeError> for SerializableError {
28-
fn from(value: bincode::error::DecodeError) -> Self {
27+
impl From<buffi::bincode::error::DecodeError> for SerializableError {
28+
fn from(value: buffi::bincode::error::DecodeError) -> Self {
2929
Self {
3030
message: format!("Bincode Decode Error: {value}"),
3131
}
3232
}
3333
}
3434

35-
impl From<bincode::error::EncodeError> for SerializableError {
36-
fn from(value: bincode::error::EncodeError) -> Self {
35+
impl From<buffi::bincode::error::EncodeError> for SerializableError {
36+
fn from(value: buffi::bincode::error::EncodeError) -> Self {
3737
Self {
3838
message: format!("Bincode Encode Error: {value}"),
3939
}

example/buffi_example/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct TestClient {
1111
}
1212

1313
/// A function that is not part of an impl block
14-
#[buffi_macro::exported]
14+
#[buffi::exported]
1515
pub fn free_standing_function(input: i64) -> Result<i64, String> {
1616
Ok(input)
1717
}
@@ -34,7 +34,7 @@ pub struct CustomType {
3434
pub itself: Option<Box<CustomType>>,
3535
}
3636

37-
#[buffi_macro::exported]
37+
#[buffi::exported]
3838
impl TestClient {
3939
/// A function that might use context provided by a TestClient to do its thing
4040
pub fn client_function(&self, input: String) -> Result<String, String> {

0 commit comments

Comments
 (0)