feat(rust): add common primitive compatibility layer

Introduce the Rust static library and move the shared byte, bitstream, CPU,
error, xxHash, debug, and public-common implementations into it. Thin C shims
preserve the existing header-driven C build while original tests link the Rust
archive.

This establishes the ABI-safe foundation for later codec and CLI ports;
entropy coding, runtime support, codecs, dictionaries, and the CLI remain C.
The top-down migration map documents that boundary and its validation path.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release

Refs: rust/README.md
This commit is contained in:
2026-07-10 20:02:17 +02:00
parent f8745da6ff
commit 089f8e5b4d
18 changed files with 2270 additions and 136 deletions
+52
View File
@@ -0,0 +1,52 @@
#![allow(non_snake_case)]
/// Global debug verbosity level (C `g_debuglevel` from debug.c).
/// Only meaningful when debug logging is enabled at compile time.
#[no_mangle]
pub static mut g_debuglevel: i32 = 0;
/// Compile-time debug level for this Rust build (matches C `DEBUGLEVEL` default 0).
pub const DEBUGLEVEL: i32 = 0;
#[inline]
pub fn debug_enabled(level: i32) -> bool {
DEBUGLEVEL >= 2 && level <= unsafe { g_debuglevel }
}
/// No-op when DEBUGLEVEL < 2; otherwise would log to stderr.
#[macro_export]
macro_rules! RAWLOG {
($level:expr, $($arg:tt)*) => {{
if $crate::debug::debug_enabled($level) {
eprint!($($arg)*);
}
}};
}
/// No-op when DEBUGLEVEL < 2; otherwise would log file:line prefix + message.
#[macro_export]
macro_rules! DEBUGLOG {
($level:expr, $($arg:tt)*) => {{
if $crate::debug::debug_enabled($level) {
eprint!("{}:{}: ", file!(), line!());
eprintln!($($arg)*);
}
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_build_has_logging_disabled() {
assert_eq!(DEBUGLEVEL, 0);
assert!(!debug_enabled(i32::MIN));
}
#[test]
fn logging_macros_accept_format_arguments() {
RAWLOG!(2, "{}", 1);
DEBUGLOG!(2, "{}", 1);
}
}