From fa13f3b36778118856a3e50e11607c9c281da424 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 1 Jun 2024 12:05:24 +0200 Subject: [PATCH] split works --- Cargo.lock | 1 + examples/src/main.rs | 10 +++++----- libcsp-sys/build.rs | 28 ++++++++++++++++++++++++++++ libcsp/Cargo.toml | 1 + libcsp/src/lib.rs | 3 --- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89fc465..54e0a14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,6 +48,7 @@ version = "0.1.0" dependencies = [ "bitflags", "libc", + "libcsp-sys", "num_enum", ] diff --git a/examples/src/main.rs b/examples/src/main.rs index 57e73f0..cf783b7 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -8,11 +8,11 @@ use std::{ time::Duration, }; -use libcsp_rust::{ +use libcsp::{ csp_accept_guarded, csp_bind, csp_buffer_get, csp_conn_dport, csp_conn_print_table, - csp_connect_guarded, csp_iflist_print, csp_init, csp_listen, csp_ping, csp_read, - csp_read_guarded, csp_reboot, csp_route_work, csp_send, csp_service_handler, ConnectOpts, - CspSocket, MsgPriority, SocketFlags, CSP_ANY, CSP_LOOPBACK, + csp_connect_guarded, csp_iflist_print, csp_init, csp_listen, csp_ping, csp_read_guarded, + csp_reboot, csp_route_work, csp_send, csp_service_handler, ConnectOpts, CspError, CspSocket, + MsgPriority, SocketFlags, CSP_ANY, CSP_LOOPBACK, }; const MY_SERVER_PORT: i32 = 10; @@ -38,7 +38,7 @@ fn main() -> Result<(), u32> { } if let Err(e) = csp_route_work() { match e { - libcsp_rust::CspError::TimedOut => continue, + CspError::TimedOut => continue, e => { println!("CSP router error: {:?}", e); break; diff --git a/libcsp-sys/build.rs b/libcsp-sys/build.rs index e69de29..f27a0c3 100644 --- a/libcsp-sys/build.rs +++ b/libcsp-sys/build.rs @@ -0,0 +1,28 @@ +use std::{env, path::PathBuf}; + +pub const ENV_KEY_CSP_CONFIG_DIR: &str = "CSP_CONFIG_DIR"; + +fn main() { + println!("cargo:rustc-link-lib=csp"); + + let out_path = env::var("OUT_DIR").unwrap(); + let csp_conf_dir = match env::var("CSP_CONFIG_DIR") { + Ok(conf_path) => conf_path, + Err(_e) => { + println!("cargo:warning=CSP_CONFIG_DIR not set, using CARGO_MANIFEST_DIR to search for autoconfig.rs"); + env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set") + } + }; + let mut csp_conf_path = PathBuf::new(); + csp_conf_path.push(csp_conf_dir); + csp_conf_path.push("autoconfig.rs"); + if !csp_conf_path.exists() { + panic!( + "autoconfig.rs not found at {:?}, is required for library build", + csp_conf_path + ); + } + let out_path_full = PathBuf::from(&out_path).join("autoconfig.rs"); + std::fs::copy(&csp_conf_path, out_path_full).expect("failed to copy autoconfig.rs to OUT_DIR"); + println!("cargo::rerun-if-changed={:?}", &csp_conf_path); +} diff --git a/libcsp/Cargo.toml b/libcsp/Cargo.toml index dddc3ee..6988083 100644 --- a/libcsp/Cargo.toml +++ b/libcsp/Cargo.toml @@ -15,3 +15,4 @@ categories = ["aerospace", "external-ffi-bindings", "no-std", "hardware-support" bitflags = "2" num_enum = "0.7" libc = "0.2" +libcsp-sys = { path = "../libcsp-sys" } diff --git a/libcsp/src/lib.rs b/libcsp/src/lib.rs index 5ae87c7..bcb2b6d 100644 --- a/libcsp/src/lib.rs +++ b/libcsp/src/lib.rs @@ -5,9 +5,6 @@ extern crate alloc; #[cfg(any(feature = "std", test))] extern crate std; -pub mod config; -pub mod ffi; - use core::time::Duration; use num_enum::{IntoPrimitive, TryFromPrimitive};