2023-05-30 22:23:11 -07:00
|
|
|
#![allow(clippy::missing_safety_doc)]
|
2022-07-05 21:13:09 -07:00
|
|
|
#![feature(format_args_nl)]
|
2023-05-25 23:45:38 -07:00
|
|
|
#![feature(io_error_more)]
|
2023-09-12 17:35:01 -07:00
|
|
|
#![feature(utf8_chunks)]
|
2022-07-05 21:13:09 -07:00
|
|
|
|
2022-08-08 22:53:37 -07:00
|
|
|
pub use libc;
|
2023-10-13 16:59:54 -07:00
|
|
|
use num_traits::FromPrimitive;
|
2022-08-19 02:21:52 -07:00
|
|
|
|
2023-09-12 17:35:01 -07:00
|
|
|
pub use cstr::*;
|
2023-06-09 02:00:37 -07:00
|
|
|
use cxx_extern::*;
|
2022-09-15 01:17:05 -07:00
|
|
|
pub use files::*;
|
2022-07-01 04:53:41 -07:00
|
|
|
pub use logging::*;
|
2022-07-05 21:13:09 -07:00
|
|
|
pub use misc::*;
|
2022-07-01 04:53:41 -07:00
|
|
|
|
2023-09-12 17:35:01 -07:00
|
|
|
mod cstr;
|
2023-06-09 02:00:37 -07:00
|
|
|
mod cxx_extern;
|
2022-09-15 01:17:05 -07:00
|
|
|
mod files;
|
2022-07-01 04:53:41 -07:00
|
|
|
mod logging;
|
2022-07-05 21:13:09 -07:00
|
|
|
mod misc;
|
2022-08-08 22:53:37 -07:00
|
|
|
mod xwrap;
|
2022-07-01 04:53:41 -07:00
|
|
|
|
|
|
|
#[cxx::bridge]
|
|
|
|
pub mod ffi {
|
2022-07-06 01:16:08 -07:00
|
|
|
#[derive(Copy, Clone)]
|
2023-10-13 16:59:54 -07:00
|
|
|
#[repr(i32)]
|
|
|
|
#[cxx_name = "LogLevel"]
|
|
|
|
pub(crate) enum LogLevelCxx {
|
2023-06-29 16:44:44 -07:00
|
|
|
ErrorCxx,
|
2022-07-01 04:53:41 -07:00
|
|
|
Error,
|
|
|
|
Warn,
|
|
|
|
Info,
|
|
|
|
Debug,
|
|
|
|
}
|
|
|
|
|
2023-06-20 18:17:26 -07:00
|
|
|
unsafe extern "C++" {
|
|
|
|
include!("misc.hpp");
|
|
|
|
fn mut_u8_patch(buf: &mut [u8], from: &[u8], to: &[u8]) -> Vec<usize>;
|
|
|
|
}
|
|
|
|
|
2022-07-01 04:53:41 -07:00
|
|
|
extern "Rust" {
|
2023-08-24 00:50:38 -07:00
|
|
|
#[cxx_name = "log_with_rs"]
|
2023-10-13 16:59:54 -07:00
|
|
|
fn log_from_cxx(level: LogLevelCxx, msg: &[u8]);
|
|
|
|
#[cxx_name = "set_log_level_state"]
|
|
|
|
fn set_log_level_state_cxx(level: LogLevelCxx, enabled: bool);
|
2022-07-01 04:53:41 -07:00
|
|
|
fn exit_on_error(b: bool);
|
2022-07-06 01:16:08 -07:00
|
|
|
fn cmdline_logging();
|
2022-07-01 04:53:41 -07:00
|
|
|
}
|
2022-08-19 02:21:52 -07:00
|
|
|
|
2023-05-16 02:09:05 -07:00
|
|
|
#[namespace = "rust"]
|
2022-08-19 02:21:52 -07:00
|
|
|
extern "Rust" {
|
|
|
|
fn xpipe2(fds: &mut [i32; 2], flags: i32) -> i32;
|
2023-08-10 21:22:53 -07:00
|
|
|
#[cxx_name = "fd_path"]
|
|
|
|
fn fd_path_for_cxx(fd: i32, buf: &mut [u8]) -> isize;
|
|
|
|
#[cxx_name = "map_file"]
|
|
|
|
fn map_file_for_cxx(path: &[u8], rw: bool) -> &'static mut [u8];
|
|
|
|
#[cxx_name = "map_fd"]
|
|
|
|
fn map_fd_for_cxx(fd: i32, sz: usize, rw: bool) -> &'static mut [u8];
|
2022-08-19 02:21:52 -07:00
|
|
|
}
|
|
|
|
}
|
2023-10-13 16:59:54 -07:00
|
|
|
|
|
|
|
fn set_log_level_state_cxx(level: ffi::LogLevelCxx, enabled: bool) {
|
|
|
|
if let Some(level) = LogLevel::from_i32(level.repr) {
|
|
|
|
set_log_level_state(level, enabled)
|
|
|
|
}
|
|
|
|
}
|