blob: 13066f101656a409074d2cfc60eb5d2e60bae99e [file] [log] [blame]
Brian Silvermane4c79ce2022-08-15 05:57:28 -07001use std::{ffi::CString, sync::Once};
2
3autocxx::include_cpp! (
4#include "aos/init.h"
5
6safety!(unsafe)
7
8generate!("aos::InitFromRust")
9);
10
Adam Snaiderc8b7e752023-09-14 14:27:53 -070011/// Initializes AOS.
Adam Snaider43516782023-06-26 15:14:18 -070012pub fn init() {
Brian Silvermane4c79ce2022-08-15 05:57:28 -070013 static ONCE: Once = Once::new();
14 ONCE.call_once(|| {
15 let argv0 = std::env::args().next().expect("must have argv[0]");
16 let argv0 = CString::new(argv0).expect("argv[0] may not have NUL");
17 // SAFETY: argv0 is a NUL-terminated string.
18 unsafe { ffi::aos::InitFromRust(argv0.as_ptr()) };
19 });
Brian Silvermane4c79ce2022-08-15 05:57:28 -070020}