Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalize tracing-ffi-schema #101

Merged
merged 5 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dep_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"same-file",
"semver",
"semver-parser",
"tracing-ffi-schema",
"ucd-trie",
"unicode-segmentation",
"version_check",
Expand Down
1 change: 1 addition & 0 deletions ffi/rodbus-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ num_cpus = "1"
[build-dependencies]
rodbus-schema = { path = "../rodbus-schema" }
rust-oo-bindgen = { git = "https://github.com/stepfunc/oo_bindgen.git", tag = "0.3.0" }
tracing-ffi-schema = { git = "https://github.com/stepfunc/tracing-ffi.git", tag = "0.1.0" }

[features]
default = ["serial", "tls"]
Expand Down
10 changes: 10 additions & 0 deletions ffi/rodbus-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use std::env;
use std::io::Write;
use std::path::Path;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

let mut file =
std::fs::File::create(Path::new(&env::var_os("OUT_DIR").unwrap()).join("tracing.rs"))
.unwrap();
file.write_all(tracing_ffi_schema::get_impl_file().as_bytes())
.unwrap();

match rodbus_schema::build_lib() {
Ok(lib) => {
rust_oo_bindgen::RustCodegen::new(&lib).generate().unwrap();
Expand Down
23 changes: 23 additions & 0 deletions ffi/rodbus-ffi/src/helpers/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ use rodbus::Shutdown;

use crate::ffi;

impl From<ffi::DecodeLevel> for rodbus::DecodeLevel {
fn from(level: ffi::DecodeLevel) -> Self {
rodbus::DecodeLevel {
app: match level.app() {
ffi::AppDecodeLevel::Nothing => rodbus::AppDecodeLevel::Nothing,
ffi::AppDecodeLevel::FunctionCode => rodbus::AppDecodeLevel::FunctionCode,
ffi::AppDecodeLevel::DataHeaders => rodbus::AppDecodeLevel::DataHeaders,
ffi::AppDecodeLevel::DataValues => rodbus::AppDecodeLevel::DataValues,
},
frame: match level.frame() {
ffi::FrameDecodeLevel::Nothing => rodbus::FrameDecodeLevel::Nothing,
ffi::FrameDecodeLevel::Header => rodbus::FrameDecodeLevel::Header,
ffi::FrameDecodeLevel::Payload => rodbus::FrameDecodeLevel::Payload,
},
physical: match level.physical() {
ffi::PhysDecodeLevel::Nothing => rodbus::PhysDecodeLevel::Nothing,
ffi::PhysDecodeLevel::Length => rodbus::PhysDecodeLevel::Length,
ffi::PhysDecodeLevel::Data => rodbus::PhysDecodeLevel::Data,
},
}
}
}

impl From<rodbus::RequestError> for ffi::RequestError {
fn from(err: rodbus::RequestError) -> Self {
match err {
Expand Down
10 changes: 8 additions & 2 deletions ffi/rodbus-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ mod database;
mod error;
mod iterator;
mod list;
mod logging;
mod runtime;
mod server;
mod tracing;

pub(crate) mod helpers {
// From<T> implementations for FFI types
Expand All @@ -17,16 +17,22 @@ pub(crate) mod helpers {
mod ext;
}

pub(crate) use crate::tracing::*;
pub use client::*;
pub use database::*;
pub use iterator::*;
pub use list::*;
pub(crate) use logging::*;
pub use runtime::*;
pub use server::*;

pub mod ffi;

impl From<crate::TracingInitError> for std::os::raw::c_int {
fn from(_: crate::TracingInitError) -> Self {
crate::ffi::ParamError::LoggingAlreadyConfigured.into()
}
}

lazy_static::lazy_static! {
static ref VERSION: std::ffi::CString = std::ffi::CString::new(rodbus::VERSION).unwrap();
}
Expand Down
191 changes: 0 additions & 191 deletions ffi/rodbus-ffi/src/logging.rs

This file was deleted.

1 change: 1 addition & 0 deletions ffi/rodbus-ffi/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/tracing.rs"));
1 change: 1 addition & 0 deletions ffi/rodbus-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ readme = "../README.md"

[dependencies]
oo-bindgen = { git = "https://github.com/stepfunc/oo_bindgen.git", tag = "0.3.0" }
tracing-ffi-schema = { git = "https://github.com/stepfunc/tracing-ffi.git", tag = "0.1.0" }
2 changes: 1 addition & 1 deletion ffi/rodbus-schema/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl CommonDefinitions {
pub(crate) fn build(lib: &mut LibraryBuilder) -> BackTraced<CommonDefinitions> {
let error_type = build_error_type(lib)?;
let nothing = build_nothing_type(lib)?;
let decode_level = crate::logging::define(lib, error_type.clone())?;
let decode_level = crate::decoding::define(lib)?;
let bit_value = build_bit_value(lib)?;
let register_value = build_register_value(lib)?;

Expand Down
Loading