improvements for libcsp cargo builder

This commit is contained in:
Robin Müller 2024-06-01 23:21:50 +02:00
parent 28cc72de24
commit 215364a6a5
10 changed files with 45 additions and 29 deletions

15
Cargo.lock generated
View File

@ -44,7 +44,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libcsp"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"bitflags",
"libc",
@ -54,16 +54,7 @@ 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",
]
@ -73,7 +64,7 @@ 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]]

View File

@ -1,3 +1,10 @@
[workspace]
members = [
"libcsp-cargo-build",
"examples"
]
resolver = "2"
[package]
name = "libcsp"
version = "0.1.3"
@ -16,10 +23,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"

View File

@ -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

View File

@ -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" }

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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"

View File

@ -133,12 +133,32 @@ pub struct Builder {
build: cc::Build,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum BuildCreationError {
PathDoesNotExist,
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 +166,7 @@ impl Builder {
cfg: Default::default(),
compiler_warnings: true,
build: Default::default(),
}
})
}
/// Access to the underlying [cc::Build] builder object.