restructuring complete
This commit is contained in:
parent
564a8f498d
commit
1f091aa865
352
Cargo.lock
generated
352
Cargo.lock
generated
@ -2,38 +2,6 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.69.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"log",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.5.0"
|
||||
@ -46,90 +14,6 @@ version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a483f3cbf7cec2e153d424d0e92329d816becc6421389bd494375c6065921b9b"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "lazycell"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.155"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
|
||||
[[package]]
|
||||
name = "libcsp-cargo-build"
|
||||
version = "0.1.0"
|
||||
@ -141,9 +25,7 @@ dependencies = [
|
||||
name = "libcsp-rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"bitflags",
|
||||
"libcsp-cargo-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -153,237 +35,3 @@ dependencies = [
|
||||
"libcsp-cargo-build",
|
||||
"libcsp-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.84"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
@ -3,30 +3,9 @@ use std::{env, path::PathBuf};
|
||||
use libcsp_cargo_build::Builder;
|
||||
|
||||
fn main() {
|
||||
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
// Pass some important build script environment variables to the binary/library.
|
||||
// Remove this at a later stage, this belongs in a concrete example app.
|
||||
/*
|
||||
println!(
|
||||
"cargo:rustc-env=TARGET={}",
|
||||
std::env::var("TARGET").unwrap()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OUT_DIR={}",
|
||||
std::env::var("OUT_DIR").unwrap()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OPT_LEVEL={}",
|
||||
std::env::var("OPT_LEVEL").unwrap()
|
||||
);
|
||||
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
|
||||
*/
|
||||
let out_dir = env::var("OUT_DIR").unwrap_or_default();
|
||||
|
||||
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
||||
// automatically know it must look for a `libcsp.a` file.
|
||||
// println!("cargo:rustc-link-lib=csp");
|
||||
// println!("cargo:rustc-link-search={}/csp", project_dir);
|
||||
|
||||
let mut csp_builder = Builder::new();
|
||||
csp_builder.compile();
|
||||
let libcsp_path = "../lib/libcsp";
|
||||
let mut csp_builder = Builder::new(PathBuf::from(libcsp_path), PathBuf::from(out_dir));
|
||||
csp_builder.compile().expect("compiling libcsp failed");
|
||||
}
|
||||
|
@ -1,4 +1,78 @@
|
||||
pub struct CspBuildOpts {
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
pub mod autoconf {
|
||||
pub const CFG_POSIX: &str = "CSP_POSIX";
|
||||
pub const CFG_ZEPHYR: &str = "CSP_ZEPHYR";
|
||||
|
||||
pub const CFG_HAVE_STDIO: &str = "CSP_HAVE_STDIO";
|
||||
pub const CFG_ENABLE_CSP_PRINT: &str = "CSP_ENABLE_CSP_PRINT";
|
||||
pub const CFG_PRINT_STDIO: &str = "CSP_PRINT_STDIO";
|
||||
|
||||
pub const CFG_REPRODUCIBLE_BUILDS: &str = "CSP_REPRODUCIBLE_BUILDS";
|
||||
|
||||
pub const CFG_QFIFO_LEN: &str = "CSP_QFIFO_LEN";
|
||||
pub const CFG_PORT_MAX_BIND: &str = "CSP_PORT_MAX_BIND";
|
||||
pub const CFG_CONN_RXQUEUE_LEN: &str = "CSP_CONN_RXQUEUE_LEN";
|
||||
pub const CFG_CONN_MAX: &str = "CSP_CONN_MAX";
|
||||
pub const CFG_BUFFER_SIZE: &str = "CSP_BUFFER_SIZE";
|
||||
pub const CFG_BUFFER_COUNT: &str = "CSP_BUFFER_COUNT";
|
||||
pub const CFG_RDP_MAX_WINDOW: &str = "CSP_RDP_MAX_WINDOW";
|
||||
pub const CFG_RTABLE_SIZE: &str = "CSP_RTABLE_SIZE";
|
||||
|
||||
pub const CFG_USE_RDP: &str = "CSP_USE_RDP";
|
||||
pub const CFG_USE_HMAC: &str = "CSP_USE_HMAC";
|
||||
pub const CFG_USE_PROMISC: &str = "CSP_USE_PROMISC";
|
||||
pub const CFG_USE_RTABLE: &str = "CSP_USE_RTABLE";
|
||||
pub const CFG_HAVE_LIBSOCKETCAN: &str = "CSP_HAVE_LIBSOCKETCAN";
|
||||
pub const CFG_HAVE_LIBZMQ: &str = "CSP_HAVE_LIBZMQ";
|
||||
}
|
||||
|
||||
const SRCS_LIST: &[&str] = &[
|
||||
"csp_bridge.c",
|
||||
"csp_buffer.c",
|
||||
"csp_crc32.c",
|
||||
"csp_debug.c",
|
||||
"csp_id.c",
|
||||
"csp_iflist.c",
|
||||
"csp_conn.c",
|
||||
"csp_init.c",
|
||||
"csp_io.c",
|
||||
"csp_port.c",
|
||||
"csp_promisc.c",
|
||||
"csp_qfifo.c",
|
||||
"csp_port.c",
|
||||
"csp_route.c",
|
||||
"interfaces/csp_if_lo.c",
|
||||
"interfaces/csp_if_kiss.c",
|
||||
"interfaces/csp_if_tun.c",
|
||||
"interfaces/csp_if_udp.c",
|
||||
];
|
||||
|
||||
const ARCH_SRCS_UNIX: &[&str] = &[
|
||||
"arch/posix/csp_clock.c",
|
||||
"arch/posix/csp_semaphore.c",
|
||||
"arch/posix/csp_system.c",
|
||||
"arch/posix/csp_time.c",
|
||||
"arch/posix/csp_queue.c",
|
||||
"arch/posix/pthread_queue.c",
|
||||
];
|
||||
|
||||
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,
|
||||
@ -6,10 +80,22 @@ pub struct CspBuildOpts {
|
||||
yaml: bool,
|
||||
}
|
||||
|
||||
impl Default for CspBuildOpts {
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
rtable: true,
|
||||
have_stdio: true,
|
||||
print_stdio: true,
|
||||
reproducible_builds: false,
|
||||
qfifo_len: 16,
|
||||
port_max_bind: 16,
|
||||
conn_rx_queue_len: 16,
|
||||
conn_max: 8,
|
||||
buffer_size: 256,
|
||||
buffer_count: 15,
|
||||
rdp_max_window: 5,
|
||||
rtable_size: 10,
|
||||
hmac: true,
|
||||
rtable: false,
|
||||
csp_print: true,
|
||||
promisc: true,
|
||||
rdp: true,
|
||||
@ -19,84 +105,206 @@ impl Default for CspBuildOpts {
|
||||
}
|
||||
|
||||
pub struct Builder {
|
||||
opts: CspBuildOpts,
|
||||
generate_autoconf_file: bool,
|
||||
libcsp_path: PathBuf,
|
||||
libcsp_src_path_base: PathBuf,
|
||||
out_dir: PathBuf,
|
||||
cfg: Config,
|
||||
build: cc::Build,
|
||||
}
|
||||
|
||||
impl Default for Builder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
opts: CspBuildOpts::default(),
|
||||
build: cc::Build::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
pub fn new(libcsp_path: PathBuf, out_dir: PathBuf) -> Self {
|
||||
let mut libcsp_src_path_base = libcsp_path.clone();
|
||||
libcsp_src_path_base.push("src");
|
||||
Self {
|
||||
generate_autoconf_file: true,
|
||||
libcsp_path,
|
||||
libcsp_src_path_base,
|
||||
out_dir,
|
||||
cfg: Default::default(),
|
||||
build: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cc(&mut self) -> &mut cc::Build {
|
||||
&mut self.build
|
||||
}
|
||||
|
||||
pub fn compile(&mut self) {
|
||||
self.build
|
||||
.file("libcsp/src/csp_bridge.c")
|
||||
.file("libcsp/src/csp_buffer.c")
|
||||
.file("libcsp/src/csp_crc32.c")
|
||||
.file("libcsp/src/csp_debug.c")
|
||||
.file("libcsp/src/csp_id.c")
|
||||
.file("libcsp/src/csp_iflist.c")
|
||||
.file("libcsp/src/csp_conn.c")
|
||||
.file("libcsp/src/csp_init.c")
|
||||
.file("libcsp/src/csp_io.c")
|
||||
.file("libcsp/src/csp_port.c")
|
||||
.file("libcsp/src/csp_promisc.c")
|
||||
.file("libcsp/src/csp_qfifo.c")
|
||||
.file("libcsp/src/csp_port.c")
|
||||
.file("libcsp/src/csp_route.c")
|
||||
.file("libcsp/src/interfaces/csp_if_lo.c")
|
||||
.file("libcsp/src/interfaces/csp_if_kiss.c")
|
||||
.file("libcsp/src/interfaces/csp_if_tun.c")
|
||||
.file("libcsp/src/interfaces/csp_if_udp.c");
|
||||
if self.opts.rdp {
|
||||
self.build.file("libcsp/src/csp_rdp.c");
|
||||
self.build.file("libcsp/src/csp_rdp_queue.c");
|
||||
pub fn compile(&mut self) -> io::Result<()> {
|
||||
if self.generate_autoconf_file {
|
||||
self.generate_autoconf_file()?;
|
||||
}
|
||||
if self.opts.promisc {
|
||||
self.build.file("libcsp/src/csp_promisc.c");
|
||||
for src in SRCS_LIST {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push(src);
|
||||
self.build.file(next_file);
|
||||
}
|
||||
if self.opts.csp_print {
|
||||
self.build.file("libcsp/src/csp_hex_dump.c");
|
||||
if self.cfg.rdp {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_rdp.c");
|
||||
self.build.file(next_file);
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_rdp_queue.c");
|
||||
self.build.file(next_file);
|
||||
}
|
||||
if self.opts.yaml {
|
||||
self.build.file("libcsp/src/csp_yaml.c");
|
||||
if self.cfg.promisc {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_promisc.c");
|
||||
self.build.file(next_file);
|
||||
}
|
||||
if self.opts.rtable {
|
||||
self.build.file("libcsp/src/csp_rtable_cidr.c");
|
||||
if self.cfg.csp_print {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_hex_dump.c");
|
||||
self.build.file(next_file);
|
||||
}
|
||||
if self.cfg.yaml {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_yaml.c");
|
||||
self.build.file(next_file);
|
||||
}
|
||||
if self.cfg.rtable {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push("csp_rtable_cidr.c");
|
||||
self.build.file(next_file);
|
||||
}
|
||||
|
||||
// TODO: UNIX does not necesarilly mean POSIX? Details to deal with later..
|
||||
#[cfg(unix)]
|
||||
self.posix_arch_files();
|
||||
|
||||
self.build.include("cfg");
|
||||
self.build.include("libcsp/include");
|
||||
self.build.include("libcsp/src");
|
||||
let mut inc_path = self.libcsp_path.clone();
|
||||
inc_path.push("include");
|
||||
self.build.include(inc_path);
|
||||
self.build.include(&self.libcsp_src_path_base);
|
||||
|
||||
self.build.compile("csp");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn posix_arch_files(&mut self) {
|
||||
self.build
|
||||
.file("libcsp/src/arch/posix/csp_clock.c")
|
||||
.file("libcsp/src/arch/posix/csp_semaphore.c")
|
||||
.file("libcsp/src/arch/posix/csp_system.c")
|
||||
.file("libcsp/src/arch/posix/csp_time.c")
|
||||
.file("libcsp/src/arch/posix/csp_queue.c")
|
||||
.file("libcsp/src/arch/posix/pthread_queue.c");
|
||||
for src in ARCH_SRCS_UNIX {
|
||||
let mut next_file = self.libcsp_src_path_base.clone();
|
||||
next_file.push(src);
|
||||
self.build.file(next_file);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_file(&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_file(autoconf_dir, &self.cfg)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_autoconf_file(out_dir: PathBuf, cfg: &Config) -> io::Result<()> {
|
||||
// panic!("cargo:warning=outdir for autoconf file: {:?}", out_dir);
|
||||
let mut autoconf_file_string = String::new();
|
||||
#[cfg(unix)]
|
||||
autoconf_file_string.push_str("#define CSP_POSIX 1\n");
|
||||
autoconf_file_string.push_str("#define CSP_ZEPHYR 0\n");
|
||||
autoconf_file_string.push('\n');
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_HAVE_STDIO,
|
||||
cfg.have_stdio as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_ENABLE_CSP_PRINT,
|
||||
cfg.csp_print as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_PRINT_STDIO,
|
||||
cfg.print_stdio as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_REPRODUCIBLE_BUILDS,
|
||||
cfg.reproducible_builds as u32
|
||||
));
|
||||
autoconf_file_string.push('\n');
|
||||
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_QFIFO_LEN,
|
||||
cfg.qfifo_len
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_PORT_MAX_BIND,
|
||||
cfg.port_max_bind
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_CONN_RXQUEUE_LEN,
|
||||
cfg.conn_rx_queue_len
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_CONN_MAX,
|
||||
cfg.conn_max
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_BUFFER_SIZE,
|
||||
cfg.buffer_size
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_BUFFER_COUNT,
|
||||
cfg.buffer_count
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_RDP_MAX_WINDOW,
|
||||
cfg.rdp_max_window
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_RTABLE_SIZE,
|
||||
cfg.rtable_size
|
||||
));
|
||||
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_USE_RDP,
|
||||
cfg.rdp as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_USE_HMAC,
|
||||
cfg.hmac as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_USE_PROMISC,
|
||||
cfg.promisc as u32
|
||||
));
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_USE_RTABLE,
|
||||
cfg.rtable as u32
|
||||
));
|
||||
|
||||
// TODO: Maybe those will be added at some point..
|
||||
autoconf_file_string.push_str(&format!(
|
||||
"#define {} {}\n",
|
||||
autoconf::CFG_HAVE_LIBSOCKETCAN,
|
||||
0
|
||||
));
|
||||
autoconf_file_string.push_str(&format!("#define {} {}\n", autoconf::CFG_HAVE_LIBZMQ, 0));
|
||||
let out_file = out_dir.join("autoconfig.h");
|
||||
let mut file = std::fs::File::create(out_file)?;
|
||||
file.write_all(autoconf_file_string.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// TODO: Unittest autoconf generator.
|
||||
}
|
||||
|
@ -6,7 +6,3 @@ links = "csp"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "2"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.69"
|
||||
libcsp-cargo-build = { path = "../libcsp-cargo-build" }
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,63 +1 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
// Pass some important build script environment variables to the binary/library.
|
||||
// Remove this at a later stage, this belongs in a concrete example app.
|
||||
/*
|
||||
println!(
|
||||
"cargo:rustc-env=TARGET={}",
|
||||
std::env::var("TARGET").unwrap()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OUT_DIR={}",
|
||||
std::env::var("OUT_DIR").unwrap()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OPT_LEVEL={}",
|
||||
std::env::var("OPT_LEVEL").unwrap()
|
||||
);
|
||||
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
|
||||
*/
|
||||
|
||||
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
||||
// automatically know it must look for a `libcsp.a` file.
|
||||
println!("cargo:rustc-link-lib=csp");
|
||||
// println!("cargo:rustc-link-search={}/csp", project_dir);
|
||||
|
||||
// let mut csp_builder = Builder::new();
|
||||
// csp_builder.compile();
|
||||
|
||||
// The bindgen::Builder is the main entry point
|
||||
// to bindgen, and lets you build up options for
|
||||
// the resulting bindings.
|
||||
|
||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
/*
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
|
||||
bindings
|
||||
.write_to_file(out_path)
|
||||
.expect("Couldn't write bindings!");
|
||||
*/
|
||||
if let Ok(_str) = env::var("GEN_BINDINGS") {
|
||||
let bindings = bindgen::Builder::default()
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.clang_arg("-Ilibcsp/include")
|
||||
.clang_arg("-Icfg")
|
||||
.header("wrapper.h")
|
||||
.use_core()
|
||||
// Tell cargo to invalidate the built crate whenever any of the
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
let local_path = PathBuf::from("./bindings.rs");
|
||||
bindings
|
||||
.write_to_file(local_path)
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
||||
}
|
||||
fn main() {}
|
||||
|
@ -123,13 +123,13 @@ pub struct csp_conn_s {
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct csp_packet_s {
|
||||
pub __bindgen_anon_1: csp_packet_s_anon_union,
|
||||
pub packet_info: csp_packet_s_anon_union,
|
||||
pub length: u16,
|
||||
pub id: csp_id_t,
|
||||
pub next: *mut csp_packet_s,
|
||||
#[doc = " Additional header bytes, to prepend packed data before transmission\n This must be minimum 6 bytes to accomodate CSP 2.0. But some implementations\n require much more scratch working area for encryption for example.\n\n Ultimately after csp_id_pack() this area will be filled with the CSP header"]
|
||||
pub header: [u8; 8usize],
|
||||
pub __bindgen_anon_2: csp_packet_s_data_union,
|
||||
pub packet_data_union: csp_packet_s_data_union,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -222,12 +222,12 @@ impl CspPacket {
|
||||
impl Default for CspPacket {
|
||||
fn default() -> Self {
|
||||
Self(csp_packet_s {
|
||||
__bindgen_anon_1: Default::default(),
|
||||
packet_info: Default::default(),
|
||||
length: Default::default(),
|
||||
id: Default::default(),
|
||||
next: core::ptr::null_mut(),
|
||||
header: Default::default(),
|
||||
__bindgen_anon_2: Default::default(),
|
||||
packet_data_union: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -319,8 +319,7 @@ extern "C" {
|
||||
#[doc = " Initialize CSP.\n This will configure basic structures."]
|
||||
pub fn csp_init();
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
||||
pub fn csp_print_func(fmt: *const core::ffi::c_char, ...);
|
||||
|
||||
#[doc = " Bind port to socket.\n\n @param[in] socket socket to bind port to\n @param[in] port port number to bind, use #CSP_ANY for all ports. Bindnig to a specific will take precedence over #CSP_ANY.\n @return #CSP_ERR_NONE on success, otherwise an error code."]
|
||||
pub fn csp_bind(socket: *mut csp_socket_t, port: u8) -> core::ffi::c_int;
|
||||
|
Loading…
Reference in New Issue
Block a user