Compare commits
7 Commits
libcsp-sys
...
main
Author | SHA1 | Date | |
---|---|---|---|
de5d29b3e6 | |||
e81321d8bf | |||
0b075e5a97 | |||
d49d0affe2 | |||
e0e66e616d | |||
215364a6a5 | |||
28cc72de24 |
@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.1.3] 2024-06-01
|
||||
|
||||
Fixed documentation build.
|
||||
|
||||
# [v0.1.2] 2024-06-01
|
||||
|
||||
Restructured crate to be the root package of a workspace.
|
||||
|
58
Cargo.lock
generated
58
Cargo.lock
generated
@ -4,15 +4,15 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.5.0"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.98"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
|
||||
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
@ -44,7 +44,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
|
||||
[[package]]
|
||||
name = "libcsp"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
@ -54,18 +54,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libcsp-cargo-build"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libcsp-cargo-build"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "554733e90f35324f10e32b4e848f5c85eb28cd099c5015d9fbe869f3b5a59944"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -73,21 +65,21 @@ name = "libcsp-rust-examples"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libcsp",
|
||||
"libcsp-cargo-build 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libcsp-cargo-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libcsp-sys"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.2"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
@ -121,9 +113,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.84"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6"
|
||||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@ -139,15 +131,35 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.66"
|
||||
version = "2.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
|
||||
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.62"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.62"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.6"
|
||||
|
17
Cargo.toml
17
Cargo.toml
@ -1,6 +1,14 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"libcsp-cargo-build",
|
||||
"examples"
|
||||
]
|
||||
default-members = ["examples"]
|
||||
resolver = "2"
|
||||
|
||||
[package]
|
||||
name = "libcsp"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
description = "Safe and ergonomic Rust API for libcsp on top on libcsp-sys"
|
||||
@ -16,10 +24,3 @@ bitflags = "2"
|
||||
num_enum = "0.7"
|
||||
libc = "0.2"
|
||||
libcsp-sys = { version = "0.1", path = "libcsp-sys" }
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"libcsp-cargo-build",
|
||||
"examples"
|
||||
]
|
||||
resolver = "2"
|
||||
|
@ -48,7 +48,7 @@ in Rust. You can run the example using the following steps:
|
||||
|
||||
1. Clone/Copy `libcsp` into the `lib` folder, for example by using the provided `lib/clone-csp.sh`
|
||||
script or adding `libcsp` as a git submodule.
|
||||
2. You can now use `cargo run -p libcsp-rust-examples` to run the server/client example.
|
||||
2. You can now use `cargo run` to run the server/client example.
|
||||
|
||||
## Compile-time configuration of the `libcsp-sys` library
|
||||
|
||||
@ -59,8 +59,8 @@ The user has to provide the path to a directory containing this `autoconfig.rs`
|
||||
`CSP_CONFIG_DIR` environmental variable.
|
||||
|
||||
You can automatically generate this file when using `libcsp-cargo-build` by using the
|
||||
[`generate_autoconf_rust_file`](here be link soon) method of the Builder object as done in the
|
||||
example build script.
|
||||
[`generate_autoconf_rust_file`](https://docs.rs/libcsp-cargo-build/latest/libcsp_cargo_build/fn.generate_autoconf_rust_file.html)
|
||||
method of the Builder object as done in the example build script.
|
||||
|
||||
In this workspace, the `CSP_CONFIG_DIR` variable is hardcoded using the following `.cargo/config.toml`
|
||||
configuration:
|
||||
|
@ -343,9 +343,9 @@ pub const CSP_DBG_ETH_ERR_RX_OUT: u32 = 3;
|
||||
pub const CSP_DBG_ETH_ERR_SHORT_BEGIN: u32 = 4;
|
||||
pub const CSP_DBG_ETH_ERR_INCOMPLETE: u32 = 5;
|
||||
pub const CSP_DBG_ETH_ERR_UNKNOWN: u32 = 6;
|
||||
pub const __bool_true_false_are_defined: u32 = 1;
|
||||
pub const true_: u32 = 1;
|
||||
pub const false_: u32 = 0;
|
||||
pub const __bool_true_false_are_defined: u32 = 1;
|
||||
pub const CSP_QUEUE_OK: u32 = 0;
|
||||
pub const CSP_QUEUE_ERROR: i32 = -1;
|
||||
pub const CSP_ANY: u32 = 255;
|
||||
@ -2411,7 +2411,11 @@ extern "C" {
|
||||
) -> ::core::ffi::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn bcopy(__src: *const ::core::ffi::c_void, __dest: *mut ::core::ffi::c_void, __n: usize);
|
||||
pub fn bcopy(
|
||||
__src: *const ::core::ffi::c_void,
|
||||
__dest: *mut ::core::ffi::c_void,
|
||||
__n: ::core::ffi::c_ulong,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn bzero(__s: *mut ::core::ffi::c_void, __n: ::core::ffi::c_ulong);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This file was auto-generated by libcsp-cargo-build v0.1.0
|
||||
// This file was auto-generated by libcsp-cargo-build v0.2.0
|
||||
#define CSP_POSIX 1
|
||||
#define CSP_ZEPHYR 0
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
git clone https://github.com/us-irs/libcsp.git
|
||||
cd libcsp
|
||||
git checkout const-correctness
|
||||
|
@ -9,4 +9,4 @@ edition = "2021"
|
||||
libcsp = { version = "0.1", path = ".." }
|
||||
|
||||
[build-dependencies]
|
||||
libcsp-cargo-build = "0.1"
|
||||
libcsp-cargo-build = { version = "0.2", path = "../libcsp-cargo-build" }
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This file was auto-generated by libcsp-cargo-build v0.1.0
|
||||
// This file was auto-generated by libcsp-cargo-build v0.2.0
|
||||
#define CSP_POSIX 1
|
||||
#define CSP_ZEPHYR 0
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This file was auto-generated by libcsp-cargo-build v0.1.0
|
||||
// This file was auto-generated by libcsp-cargo-build v0.2.0
|
||||
pub const CSP_CONN_RXQUEUE_LEN: usize = 16;
|
||||
pub const CSP_QFIFO_LEN: usize = 16;
|
||||
pub const CSP_PORT_MAX_BIND: usize = 16;
|
||||
|
@ -11,7 +11,8 @@ fn main() {
|
||||
|
||||
// This helper structure will take care of the majority of work to compile libcsp using the
|
||||
// cc crate.
|
||||
let mut csp_builder = Builder::new(PathBuf::from(libcsp_path), PathBuf::from(&out_dir));
|
||||
let mut csp_builder = Builder::new(PathBuf::from(libcsp_path), PathBuf::from(&out_dir))
|
||||
.expect("creating libcsp builder failed");
|
||||
// A lot of spam we are not interested in usually.
|
||||
csp_builder.compiler_warnings = false;
|
||||
|
||||
|
@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [unreleased]
|
||||
|
||||
# [v0.2.0] 2024-06-01
|
||||
|
||||
Added basic sanity checks for the user-provided `libcsp` location.
|
||||
|
||||
# [v0.1.0] 2024-06-01
|
||||
|
||||
Initial release
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libcsp-cargo-build"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
description = "Tools to build libcsp using cargo"
|
||||
homepage = "https://egit.irs.uni-stuttgart.de/rust/libcsp-rust"
|
||||
@ -12,3 +12,4 @@ categories = ["aerospace", "external-ffi-bindings", "no-std", "hardware-support"
|
||||
|
||||
[dependencies]
|
||||
cc = "1"
|
||||
thiserror = "1"
|
||||
|
@ -133,12 +133,34 @@ pub struct Builder {
|
||||
build: cc::Build,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum BuildCreationError {
|
||||
#[error("The specified libcsp path does not exist")]
|
||||
PathDoesNotExist,
|
||||
#[error("The specified libcsp path does not have the expected format of the library")]
|
||||
InvalidLibcspFormat,
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
/// Create a new builder instance.
|
||||
pub fn new(libcsp_path: PathBuf, out_dir: PathBuf) -> Self {
|
||||
/// Create a new builder instance. Returns [BuildCreationError] if the specified libcsp path
|
||||
/// does not exist or does not have the expected format.
|
||||
pub fn new(libcsp_path: PathBuf, out_dir: PathBuf) -> Result<Self, BuildCreationError> {
|
||||
// Basic sanity checks for the passed libcsp path.
|
||||
if !libcsp_path.exists() {
|
||||
return Err(BuildCreationError::PathDoesNotExist);
|
||||
}
|
||||
if !libcsp_path
|
||||
.join("include")
|
||||
.join("csp")
|
||||
.join("csp.h")
|
||||
.exists()
|
||||
{
|
||||
return Err(BuildCreationError::InvalidLibcspFormat);
|
||||
}
|
||||
|
||||
let mut libcsp_src_path_base = libcsp_path.clone();
|
||||
libcsp_src_path_base.push("src");
|
||||
Self {
|
||||
Ok(Self {
|
||||
generate_autoconf_file: true,
|
||||
libcsp_path,
|
||||
libcsp_src_path_base,
|
||||
@ -146,7 +168,7 @@ impl Builder {
|
||||
cfg: Default::default(),
|
||||
compiler_warnings: true,
|
||||
build: Default::default(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Access to the underlying [cc::Build] builder object.
|
||||
|
@ -483,7 +483,7 @@ extern "C" {
|
||||
pub fn csp_buffer_get(unused: usize) -> *mut csp_packet_t;
|
||||
|
||||
#[doc = " Free buffer (from task context).\n\n @param[in] buffer buffer to free. NULL is handled gracefully."]
|
||||
pub fn csp_buffer_free(buffer: *mut ::core::ffi::c_void);
|
||||
pub fn csp_buffer_free(buffer: *const ::core::ffi::c_void);
|
||||
|
||||
#[doc = " Print connection table to stdout."]
|
||||
pub fn csp_conn_print_table();
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -398,6 +398,21 @@ pub fn csp_accept(socket: &mut CspSocket, timeout: Duration) -> Option<CspConnRe
|
||||
}))
|
||||
}
|
||||
|
||||
/// Rust wrapper for [ffi::csp_socket_close] which returns the result code directly.
|
||||
pub fn csp_socket_close_raw(sock: &mut CspSocket) -> i32 {
|
||||
unsafe { ffi::csp_socket_close(&mut sock.0) }
|
||||
}
|
||||
|
||||
/// Rust wrapper for [ffi::csp_socket_close].
|
||||
///
|
||||
/// This function will panic if the error code returned from [ffi::csp_socket_close] is not one of
|
||||
/// [CspError]. [csp_socket_close_raw] can be used if this is not acceptable.
|
||||
pub fn csp_socket_close(sock: &mut CspSocket) -> Result<(), CspError> {
|
||||
let result = unsafe { ffi::csp_socket_close(&mut sock.0) };
|
||||
Err(CspError::try_from(result)
|
||||
.unwrap_or_else(|_| panic!("unexpected error value {} from csp_socket_close", result)))
|
||||
}
|
||||
|
||||
/// Rust wrapper for [ffi::csp_read].
|
||||
pub fn csp_read(conn: &mut CspConnRef, timeout: Duration) -> Option<CspPacketRef> {
|
||||
let timeout_millis = timeout.as_millis();
|
||||
@ -589,7 +604,7 @@ pub fn csp_conn_print_table() {
|
||||
pub fn csp_buffer_free(packet: impl Into<CspPacketRef>) {
|
||||
// SAFETY: FFI call and the Rust type system actually ensure the correct type
|
||||
// is free'd here, while also taking the packet by value.
|
||||
unsafe { ffi::csp_buffer_free(packet.into().0 as *mut libc::c_void) }
|
||||
unsafe { ffi::csp_buffer_free(packet.into().0 as *const libc::c_void) }
|
||||
}
|
||||
|
||||
/// Rust wrapper for [ffi::csp_transaction_persistent].
|
||||
|
Reference in New Issue
Block a user