Brian Silverman | e4c79ce | 2022-08-15 05:57:28 -0700 | [diff] [blame] | 1 | use std::{ffi::CString, sync::Once}; |
| 2 | |
| 3 | autocxx::include_cpp! ( |
| 4 | #include "aos/init.h" |
| 5 | |
| 6 | safety!(unsafe) |
| 7 | |
| 8 | generate!("aos::InitFromRust") |
| 9 | ); |
| 10 | |
Adam Snaider | c8b7e75 | 2023-09-14 14:27:53 -0700 | [diff] [blame] | 11 | /// Initializes AOS. |
Adam Snaider | 4351678 | 2023-06-26 15:14:18 -0700 | [diff] [blame] | 12 | pub fn init() { |
Brian Silverman | e4c79ce | 2022-08-15 05:57:28 -0700 | [diff] [blame] | 13 | 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 Silverman | e4c79ce | 2022-08-15 05:57:28 -0700 | [diff] [blame] | 20 | } |