From 701b508bde41e12f2a570ce6cde8b947515f9ab7 Mon Sep 17 00:00:00 2001 From: anthonyray Date: Mon, 16 Mar 2020 19:10:39 +0100 Subject: [PATCH 1/4] Renaming ffi-utils to ffi-convert --- Cargo.toml | 6 +++--- ffi-convert-derive/Cargo.toml | 18 ++++++++++++++++++ .../src/asrust.rs | 4 ++-- .../src/cdrop.rs | 6 +++--- .../src/creprof.rs | 4 ++-- .../src/lib.rs | 0 .../src/utils.rs | 0 .../Cargo.toml | 4 ++-- .../src/lib.rs | 2 +- ffi-convert/Cargo.toml | 18 ++++++++++++++++++ {ffi-utils => ffi-convert}/src/conversions.rs | 0 {ffi-utils => ffi-convert}/src/lib.rs | 14 +++++++------- {ffi-utils => ffi-convert}/src/types.rs | 4 ++-- ffi-utils-derive/Cargo.toml | 13 ------------- ffi-utils/Cargo.toml | 13 ------------- 15 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 ffi-convert-derive/Cargo.toml rename {ffi-utils-derive => ffi-convert-derive}/src/asrust.rs (93%) rename {ffi-utils-derive => ffi-convert-derive}/src/cdrop.rs (89%) rename {ffi-utils-derive => ffi-convert-derive}/src/creprof.rs (95%) rename {ffi-utils-derive => ffi-convert-derive}/src/lib.rs (100%) rename {ffi-utils-derive => ffi-convert-derive}/src/utils.rs (100%) rename {ffi-utils-tests => ffi-convert-tests}/Cargo.toml (67%) rename {ffi-utils-tests => ffi-convert-tests}/src/lib.rs (99%) create mode 100644 ffi-convert/Cargo.toml rename {ffi-utils => ffi-convert}/src/conversions.rs (100%) rename {ffi-utils => ffi-convert}/src/lib.rs (95%) rename {ffi-utils => ffi-convert}/src/types.rs (97%) delete mode 100644 ffi-utils-derive/Cargo.toml delete mode 100644 ffi-utils/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 667b243..9aba44e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "ffi-utils", - "ffi-utils-derive", - "ffi-utils-tests", + "ffi-convert", + "ffi-convert-derive", + "ffi-convert-tests", ] diff --git a/ffi-convert-derive/Cargo.toml b/ffi-convert-derive/Cargo.toml new file mode 100644 index 0000000..fae9076 --- /dev/null +++ b/ffi-convert-derive/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "ffi-convert-derive" +version = "0.1.0" +authors = ["Snips "] +edition = "2018" +license = "MIT OR Apache-2.0" +description = "Macros implementations of CReprOf, AsRust, CDrop traits from ffi-convert" +repository = "https://github.com/snipsco/snips-utils-rs" +readme = "../README.md" +keywords = ["ffi"] + +[lib] +proc-macro = true + +[dependencies] +syn = "1.0.5" +quote = "1.0.2" +proc-macro2 = "1.0.6" diff --git a/ffi-utils-derive/src/asrust.rs b/ffi-convert-derive/src/asrust.rs similarity index 93% rename from ffi-utils-derive/src/asrust.rs rename to ffi-convert-derive/src/asrust.rs index bdf7293..1409385 100644 --- a/ffi-utils-derive/src/asrust.rs +++ b/ffi-convert-derive/src/asrust.rs @@ -21,7 +21,7 @@ pub fn impl_asrust_macro(input: &syn::DeriveInput) -> TokenStream { } let mut conversion = if field.is_string { - quote!( ffi_utils::create_rust_string_from!(self.#field_name) ) + quote!( ffi_convert::create_rust_string_from!(self.#field_name) ) } else { if field.is_pointer { quote!( { @@ -54,7 +54,7 @@ pub fn impl_asrust_macro(input: &syn::DeriveInput) -> TokenStream { quote!( impl AsRust<#target_type> for #struct_name { - fn as_rust(&self) -> Result<#target_type, ffi_utils::Error> { + fn as_rust(&self) -> Result<#target_type, ffi_convert::Error> { use failure::ResultExt; Ok(#target_type { #(#fields, )* diff --git a/ffi-utils-derive/src/cdrop.rs b/ffi-convert-derive/src/cdrop.rs similarity index 89% rename from ffi-utils-derive/src/cdrop.rs rename to ffi-convert-derive/src/cdrop.rs index 72efd7d..df1a853 100644 --- a/ffi-utils-derive/src/cdrop.rs +++ b/ffi-convert-derive/src/cdrop.rs @@ -18,7 +18,7 @@ pub fn impl_cdrop_macro(input: &syn::DeriveInput) -> TokenStream { } = field; let drop_field = if field.is_string { - quote!(ffi_utils::take_back_c_string!(self.#field_name)) + quote!(ffi_convert::take_back_c_string!(self.#field_name)) } else { if field.is_pointer { quote!( unsafe { #field_type::drop_raw_pointer(self.#field_name) }? ) @@ -42,8 +42,8 @@ pub fn impl_cdrop_macro(input: &syn::DeriveInput) -> TokenStream { let c_drop_impl = quote!( impl CDrop for # struct_name { - fn do_drop(&mut self) -> Result<(), ffi_utils::Error> { - use ffi_utils::RawPointerConverter; + fn do_drop(&mut self) -> Result<(), ffi_convert::Error> { + use ffi_convert::RawPointerConverter; # ( #do_drop_fields; )* Ok(()) } diff --git a/ffi-utils-derive/src/creprof.rs b/ffi-convert-derive/src/creprof.rs similarity index 95% rename from ffi-utils-derive/src/creprof.rs rename to ffi-convert-derive/src/creprof.rs index b4d7194..1aafa77 100644 --- a/ffi-utils-derive/src/creprof.rs +++ b/ffi-convert-derive/src/creprof.rs @@ -45,9 +45,9 @@ pub fn impl_creprof_macro(input: &syn::DeriveInput) -> TokenStream { let c_repr_of_impl = quote!( impl CReprOf<# target_type> for # struct_name { - fn c_repr_of(input: # target_type) -> Result { + fn c_repr_of(input: # target_type) -> Result { use failure::ResultExt; - use ffi_utils::RawPointerConverter; + use ffi_convert::RawPointerConverter; Ok(Self { # ( # c_repr_of_fields, )* }) diff --git a/ffi-utils-derive/src/lib.rs b/ffi-convert-derive/src/lib.rs similarity index 100% rename from ffi-utils-derive/src/lib.rs rename to ffi-convert-derive/src/lib.rs diff --git a/ffi-utils-derive/src/utils.rs b/ffi-convert-derive/src/utils.rs similarity index 100% rename from ffi-utils-derive/src/utils.rs rename to ffi-convert-derive/src/utils.rs diff --git a/ffi-utils-tests/Cargo.toml b/ffi-convert-tests/Cargo.toml similarity index 67% rename from ffi-utils-tests/Cargo.toml rename to ffi-convert-tests/Cargo.toml index 6c56bca..8e6673c 100644 --- a/ffi-utils-tests/Cargo.toml +++ b/ffi-convert-tests/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "ffi-utils-tests" +name = "ffi-convert-tests" version = "0.1.0" authors = ["Deluvi "] edition = "2018" [dependencies] failure = "0.1" -ffi-utils = { path = "../ffi-utils" } +ffi-convert = { path = "../ffi-convert" } libc = "0.2.66" diff --git a/ffi-utils-tests/src/lib.rs b/ffi-convert-tests/src/lib.rs similarity index 99% rename from ffi-utils-tests/src/lib.rs rename to ffi-convert-tests/src/lib.rs index 0dfc67f..221ea55 100644 --- a/ffi-utils-tests/src/lib.rs +++ b/ffi-convert-tests/src/lib.rs @@ -1,5 +1,5 @@ use failure::{bail, Fallible}; -use ffi_utils::*; +use ffi_convert::*; #[macro_export] macro_rules! generate_round_trip_rust_c_rust { diff --git a/ffi-convert/Cargo.toml b/ffi-convert/Cargo.toml new file mode 100644 index 0000000..e338de5 --- /dev/null +++ b/ffi-convert/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "ffi-convert" +version = "0.1.0" +authors = [ + "Thibaut Lorrain ", + "Kevin Lefevre ", +] +edition = "2018" +license = "MIT OR Apache-2.0" +description = "A collection of utilities to ease conversion between Rust and C-compatible data structures." +repository = "https://github.com/snipsco/snips-utils-rs" +readme = "../README.md" +keywords = ["ffi"] + +[dependencies] +ffi-convert-derive = { path = "../ffi-convert-derive" } +failure = "0.1" +libc = "0.2" diff --git a/ffi-utils/src/conversions.rs b/ffi-convert/src/conversions.rs similarity index 100% rename from ffi-utils/src/conversions.rs rename to ffi-convert/src/conversions.rs diff --git a/ffi-utils/src/lib.rs b/ffi-convert/src/lib.rs similarity index 95% rename from ffi-utils/src/lib.rs rename to ffi-convert/src/lib.rs index 3f305c4..044465c 100644 --- a/ffi-utils/src/lib.rs +++ b/ffi-convert/src/lib.rs @@ -28,7 +28,7 @@ //! //! We then create the C-compatible struct by [mapping](#types-representations-mapping) idiomatic Rust types to C-compatible types : //! ``` -//! # use ffi_utils::CArray; +//! # use ffi_convert::CArray; //! # struct CTopping {}; //! # struct CSauce {}; //! #[repr(C)] @@ -55,9 +55,9 @@ //! Instead of manually writing the body of the conversion traits, we can derive them : //! //! ``` -//! # use ffi_utils::{CReprOf, AsRust, CDrop}; -//! # use ffi_utils::CArray; -//! # use ffi_utils::RawBorrow; +//! # use ffi_convert::{CReprOf, AsRust, CDrop}; +//! # use ffi_convert::CArray; +//! # use ffi_convert::RawBorrow; //! # struct Sauce {}; //! # #[derive(CReprOf, AsRust, CDrop)] //! # #[target_type(Sauce)] @@ -134,7 +134,7 @@ //! The `CReprOf` trait allows to create a C-compatible representation of the reciprocal idiomatic Rust struct by consuming the latter. //! ``` -//! # use ffi_utils::{Error, CDrop}; +//! # use ffi_convert::{Error, CDrop}; //! pub trait CReprOf: Sized + CDrop { //! fn c_repr_of(input: T) -> Result; //! } @@ -151,7 +151,7 @@ //! The `AsRust` trait allows to create an idiomatic Rust struct from a C-compatible struct : //! ``` -//! # use ffi_utils::{Error, CDrop}; +//! # use ffi_convert::{Error, CDrop}; //! pub trait AsRust { //! fn as_rust(&self) -> Result; //! } @@ -167,7 +167,7 @@ //! ## Caveats with derivation of CReprOf and AsRust traits //! -pub use ffi_utils_derive::*; +pub use ffi_convert_derive::*; mod conversions; mod types; diff --git a/ffi-utils/src/types.rs b/ffi-convert/src/types.rs similarity index 97% rename from ffi-utils/src/types.rs rename to ffi-convert/src/types.rs index b01e3d5..1dad06e 100644 --- a/ffi-utils/src/types.rs +++ b/ffi-convert/src/types.rs @@ -25,7 +25,7 @@ pub enum SNIPS_RESULT { /// # Example /// /// ``` -/// use ffi_utils::{CReprOf, CStringArray}; +/// use ffi_convert::{CReprOf, CStringArray}; /// let pizza_names = vec!["Diavola".to_string(), "Margarita".to_string(), "Regina".to_string()]; /// let c_pizza_names = CStringArray::c_repr_of(pizza_names).expect("could not convert !"); /// @@ -95,7 +95,7 @@ impl CDrop for CStringArray { /// # Example /// /// ``` -/// use ffi_utils::{CReprOf, AsRust, CDrop, CArray}; +/// use ffi_convert::{CReprOf, AsRust, CDrop, CArray}; /// use libc::c_char; /// /// pub struct PizzaTopping { diff --git a/ffi-utils-derive/Cargo.toml b/ffi-utils-derive/Cargo.toml deleted file mode 100644 index 7e14477..0000000 --- a/ffi-utils-derive/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "ffi-utils-derive" -version = "0.1.0" -authors = ["Snips "] -edition = "2018" - -[lib] -proc-macro = true - -[dependencies] -syn = "1.0.5" -quote = "1.0.2" -proc-macro2 = "1.0.6" diff --git a/ffi-utils/Cargo.toml b/ffi-utils/Cargo.toml deleted file mode 100644 index 0f30f76..0000000 --- a/ffi-utils/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "ffi-utils" -version = "0.1.0" -authors = [ - "Thibaut Lorrain ", - "Kevin Lefevre ", -] -edition = "2018" - -[dependencies] -ffi-utils-derive = { path = "../ffi-utils-derive" } -failure = "0.1" -libc = "0.2" From e1c77de1c109105150c97a1f918a22e89e6012f9 Mon Sep 17 00:00:00 2001 From: anthonyray Date: Mon, 16 Mar 2020 19:13:30 +0100 Subject: [PATCH 2/4] Specifying dependencies on crates.io --- ffi-convert-tests/Cargo.toml | 2 +- ffi-convert/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ffi-convert-tests/Cargo.toml b/ffi-convert-tests/Cargo.toml index 8e6673c..ded3465 100644 --- a/ffi-convert-tests/Cargo.toml +++ b/ffi-convert-tests/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" [dependencies] failure = "0.1" -ffi-convert = { path = "../ffi-convert" } +ffi-convert = "0.1" libc = "0.2.66" diff --git a/ffi-convert/Cargo.toml b/ffi-convert/Cargo.toml index e338de5..a961d5e 100644 --- a/ffi-convert/Cargo.toml +++ b/ffi-convert/Cargo.toml @@ -13,6 +13,6 @@ readme = "../README.md" keywords = ["ffi"] [dependencies] -ffi-convert-derive = { path = "../ffi-convert-derive" } +ffi-convert-derive = "0.1" failure = "0.1" libc = "0.2" From 51f1167608582656f8606e5ffdcd961ad934b02a Mon Sep 17 00:00:00 2001 From: anthonyray Date: Tue, 17 Mar 2020 14:43:26 +0100 Subject: [PATCH 3/4] changing author names to Sonos --- ffi-convert-derive/Cargo.toml | 2 +- ffi-convert-tests/Cargo.toml | 2 +- ffi-convert/Cargo.toml | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ffi-convert-derive/Cargo.toml b/ffi-convert-derive/Cargo.toml index fae9076..2a61c6f 100644 --- a/ffi-convert-derive/Cargo.toml +++ b/ffi-convert-derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ffi-convert-derive" version = "0.1.0" -authors = ["Snips "] +authors = ["Sonos"] edition = "2018" license = "MIT OR Apache-2.0" description = "Macros implementations of CReprOf, AsRust, CDrop traits from ffi-convert" diff --git a/ffi-convert-tests/Cargo.toml b/ffi-convert-tests/Cargo.toml index ded3465..983f9ab 100644 --- a/ffi-convert-tests/Cargo.toml +++ b/ffi-convert-tests/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ffi-convert-tests" version = "0.1.0" -authors = ["Deluvi "] +authors = ["Sonos"] edition = "2018" [dependencies] diff --git a/ffi-convert/Cargo.toml b/ffi-convert/Cargo.toml index a961d5e..eb80e8a 100644 --- a/ffi-convert/Cargo.toml +++ b/ffi-convert/Cargo.toml @@ -1,10 +1,7 @@ [package] name = "ffi-convert" version = "0.1.0" -authors = [ - "Thibaut Lorrain ", - "Kevin Lefevre ", -] +authors = ["Sonos"] edition = "2018" license = "MIT OR Apache-2.0" description = "A collection of utilities to ease conversion between Rust and C-compatible data structures." From 64fa01a0286d36d32f4278e0438caf4efdb313f0 Mon Sep 17 00:00:00 2001 From: anthonyray Date: Tue, 17 Mar 2020 15:23:01 +0100 Subject: [PATCH 4/4] Removing SNIPS_RESULT enum --- ffi-convert/src/types.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ffi-convert/src/types.rs b/ffi-convert/src/types.rs index 1dad06e..95d40c7 100644 --- a/ffi-convert/src/types.rs +++ b/ffi-convert/src/types.rs @@ -10,17 +10,6 @@ use crate::conversions::*; use crate::convert_to_c_string_result; use crate::create_rust_string_from; -/// Used as a return type for functions that can encounter errors -#[repr(C)] -#[derive(Debug)] -#[allow(non_camel_case_types)] -pub enum SNIPS_RESULT { - /// The function returned successfully - SNIPS_RESULT_OK = 0, - /// The function encountered an error, you can retrieve it using the dedicated function - SNIPS_RESULT_KO = 1, -} - /// A utility type to represent arrays of string /// # Example ///