done
This commit is contained in:
parent
89a90f55b4
commit
40f813d0b3
22
examples/autoconfig.h
Normal file
22
examples/autoconfig.h
Normal file
@ -0,0 +1,22 @@
|
||||
#define CSP_POSIX 1
|
||||
#define CSP_ZEPHYR 0
|
||||
|
||||
#define CSP_HAVE_STDIO 1
|
||||
#define CSP_ENABLE_CSP_PRINT 1
|
||||
#define CSP_PRINT_STDIO 1
|
||||
#define CSP_REPRODUCIBLE_BUILDS 0
|
||||
|
||||
#define CSP_QFIFO_LEN 16
|
||||
#define CSP_PORT_MAX_BIND 16
|
||||
#define CSP_CONN_RXQUEUE_LEN 16
|
||||
#define CSP_CONN_MAX 8
|
||||
#define CSP_BUFFER_SIZE 256
|
||||
#define CSP_BUFFER_COUNT 15
|
||||
#define CSP_RDP_MAX_WINDOW 5
|
||||
#define CSP_RTABLE_SIZE 10
|
||||
#define CSP_USE_RDP 1
|
||||
#define CSP_USE_HMAC 1
|
||||
#define CSP_USE_PROMISC 1
|
||||
#define CSP_USE_RTABLE 0
|
||||
#define CSP_HAVE_LIBSOCKETCAN 0
|
||||
#define CSP_HAVE_LIBZMQ 0
|
@ -1,7 +1,7 @@
|
||||
const CSP_CONN_RXQUEUE_LEN: usize = 16
|
||||
const CSP_QFIFO_LEN: usize = 16
|
||||
const CSP_PORT_MAX_BIND: usize = 16
|
||||
const CSP_CONN_MAX: usize = 8
|
||||
const CSP_BUFFER_SIZE: usize = 256
|
||||
const CSP_RDP_MAX_WINDOW: usize = 5
|
||||
const CSP_RTABLE_SIZE: usize = 10
|
||||
pub const CSP_CONN_RXQUEUE_LEN: usize = 16;
|
||||
pub const CSP_QFIFO_LEN: usize = 16;
|
||||
pub const CSP_PORT_MAX_BIND: usize = 16;
|
||||
pub const CSP_CONN_MAX: usize = 8;
|
||||
pub const CSP_BUFFER_SIZE: usize = 256;
|
||||
pub const CSP_RDP_MAX_WINDOW: usize = 5;
|
||||
pub const CSP_RTABLE_SIZE: usize = 10;
|
||||
|
@ -1,21 +1,20 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use libcsp_cargo_build::Builder;
|
||||
use libcsp_cargo_build::{generate_autoconf_header_file, Builder};
|
||||
|
||||
fn main() {
|
||||
let out_dir = env::var("OUT_DIR").unwrap_or_default();
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
|
||||
let manifest_path = PathBuf::from(&manifest_dir);
|
||||
let libcsp_path = "../lib/libcsp";
|
||||
let mut csp_builder = Builder::new(PathBuf::from(libcsp_path), PathBuf::from(&out_dir));
|
||||
let update_autoconf = match env::var("UPDATE_CSP_AUTOCONF") {
|
||||
Ok(update_autoconf) => update_autoconf == "1",
|
||||
Err(_e) => false,
|
||||
};
|
||||
if update_autoconf {
|
||||
// We always re-generate the header file.
|
||||
generate_autoconf_header_file(manifest_path.clone(), &csp_builder.cfg)
|
||||
.expect("generating header file failed");
|
||||
csp_builder
|
||||
.generate_autoconf_rust_file(PathBuf::from(&manifest_dir))
|
||||
.generate_autoconf_rust_file(manifest_path)
|
||||
.expect("generating autoconfig.rs failed");
|
||||
println!("cargo:warning=autoconfig.rs updated");
|
||||
}
|
||||
csp_builder.compile().expect("compiling libcsp failed");
|
||||
// If we change the libcsp build configuration, we need to re-run the build.
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
pub mod autoconf {
|
||||
@ -64,23 +64,23 @@ const ARCH_SRCS_UNIX: &[&str] = &[
|
||||
];
|
||||
|
||||
pub struct Config {
|
||||
have_stdio: bool,
|
||||
print_stdio: bool,
|
||||
reproducible_builds: bool,
|
||||
qfifo_len: u32,
|
||||
port_max_bind: u32,
|
||||
conn_rx_queue_len: u32,
|
||||
conn_max: u32,
|
||||
buffer_size: u32,
|
||||
buffer_count: u32,
|
||||
rdp_max_window: u32,
|
||||
rtable_size: u32,
|
||||
hmac: bool,
|
||||
rtable: bool,
|
||||
csp_print: bool,
|
||||
promisc: bool,
|
||||
rdp: bool,
|
||||
yaml: bool,
|
||||
pub have_stdio: bool,
|
||||
pub print_stdio: bool,
|
||||
pub reproducible_builds: bool,
|
||||
pub qfifo_len: u32,
|
||||
pub port_max_bind: u32,
|
||||
pub conn_rx_queue_len: u32,
|
||||
pub conn_max: u32,
|
||||
pub buffer_size: u32,
|
||||
pub buffer_count: u32,
|
||||
pub rdp_max_window: u32,
|
||||
pub rtable_size: u32,
|
||||
pub hmac: bool,
|
||||
pub rtable: bool,
|
||||
pub csp_print: bool,
|
||||
pub promisc: bool,
|
||||
pub rdp: bool,
|
||||
pub yaml: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@ -112,7 +112,7 @@ pub struct Builder {
|
||||
libcsp_path: PathBuf,
|
||||
libcsp_src_path_base: PathBuf,
|
||||
out_dir: PathBuf,
|
||||
cfg: Config,
|
||||
pub cfg: Config,
|
||||
build: cc::Build,
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ impl Builder {
|
||||
|
||||
pub fn compile(&mut self) -> io::Result<()> {
|
||||
if self.generate_autoconf_file {
|
||||
self.generate_autoconf_file()?;
|
||||
self.generate_autoconf_header_file_default_location()?;
|
||||
}
|
||||
for src in SRCS_LIST {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
@ -194,20 +194,25 @@ impl Builder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_file(&mut self) -> io::Result<()> {
|
||||
pub fn generate_autoconf_header_file_default_location(&mut self) -> io::Result<()> {
|
||||
let mut autoconf_dir = self.out_dir.join("cfg");
|
||||
self.build.include(&autoconf_dir);
|
||||
autoconf_dir.push("csp");
|
||||
std::fs::create_dir_all(&autoconf_dir)?;
|
||||
generate_autoconf_header_file(autoconf_dir, &self.cfg)
|
||||
generate_autoconf_header_file(&autoconf_dir, &self.cfg)
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_rust_file(&self, out_dir: PathBuf) -> io::Result<()> {
|
||||
generate_autoconf_rust_file(out_dir, &self.cfg)
|
||||
pub fn generate_autoconf_header_file(&mut self, dir: impl AsRef<Path>) -> io::Result<()> {
|
||||
generate_autoconf_header_file(dir, &self.cfg)
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_rust_file(&self, dir: impl AsRef<Path>) -> io::Result<()> {
|
||||
generate_autoconf_rust_file(dir, &self.cfg)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_header_file(out_dir: PathBuf, cfg: &Config) -> io::Result<()> {
|
||||
pub fn generate_autoconf_header_file(out_dir: impl AsRef<Path>, cfg: &Config) -> io::Result<()> {
|
||||
let out_dir = out_dir.as_ref();
|
||||
let mut autoconf_file_string = String::new();
|
||||
#[cfg(unix)]
|
||||
autoconf_file_string.push_str("#define CSP_POSIX 1\n");
|
||||
@ -310,40 +315,41 @@ pub fn generate_autoconf_header_file(out_dir: PathBuf, cfg: &Config) -> io::Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_rust_file(out_dir: PathBuf, cfg: &Config) -> io::Result<()> {
|
||||
pub fn generate_autoconf_rust_file(out_dir: impl AsRef<Path>, cfg: &Config) -> io::Result<()> {
|
||||
let out_dir = out_dir.as_ref();
|
||||
let mut autoconf_file_string = String::new();
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_CONN_RXQUEUE_LEN,
|
||||
cfg.conn_rx_queue_len
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_QFIFO_LEN,
|
||||
cfg.qfifo_len
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_PORT_MAX_BIND,
|
||||
cfg.port_max_bind
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_CONN_MAX,
|
||||
cfg.conn_max
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_BUFFER_SIZE,
|
||||
cfg.buffer_size
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_RDP_MAX_WINDOW,
|
||||
cfg.rdp_max_window
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"const {}: usize = {}\n",
|
||||
"pub const {}: usize = {};\n",
|
||||
autoconf::CFG_RTABLE_SIZE,
|
||||
cfg.rtable_size
|
||||
));
|
||||
|
@ -13,7 +13,6 @@ fn main() {
|
||||
env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set")
|
||||
}
|
||||
};
|
||||
println!("cargo:warning=CSP_CONFIG_DIR={}", csp_conf_dir);
|
||||
let mut csp_conf_path = PathBuf::new();
|
||||
csp_conf_path.push(csp_conf_dir);
|
||||
csp_conf_path.push("autoconfig.rs");
|
||||
|
@ -5,8 +5,8 @@ extern crate alloc;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
extern crate std;
|
||||
|
||||
pub mod ffi;
|
||||
pub mod config;
|
||||
pub mod ffi;
|
||||
|
||||
use core::time::Duration;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user