cargo fmt, and also pass argc/argv to c lib

This commit is contained in:
Erica Z 2024-10-29 12:29:04 +01:00
parent 66500f483c
commit 36b2cf989d
4 changed files with 11 additions and 11 deletions

1
Cargo.lock generated
View file

@ -9,7 +9,6 @@ dependencies = [
"glib-build-tools",
"gtk4",
"libadwaita",
"libc",
"libsecret",
]

View file

@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
adw = { version = "0.7.0", package = "libadwaita", features = ["v1_6"] }
gtk = { version = "0.9.2", package = "gtk4", features = ["v4_16"] }
libc = "0.2.161"
libsecret = { version = "0.5.0", features = ["v0_21"] }
[build-dependencies]

View file

@ -1,10 +1,7 @@
fn main() {
let meson_build_root = std::env::var("MESON_BUILD_ROOT").unwrap();
glib_build_tools::compile_resources(
&[
"resources",
&format!("{meson_build_root}/resources"),
],
&["resources", &format!("{meson_build_root}/resources")],
"resources/audrey.gresource.xml",
"audrey.gresource",
);

View file

@ -8,14 +8,19 @@ extern crate libsecret;
#[link(name = "json-glib-1.0")]
#[link(name = "mpv")]
#[link(name = "soup-3.0")]
extern {
fn c_main(argc: libc::c_int, argv: *mut *mut libc::c_char) -> libc::c_int;
extern "C" {
fn c_main(argc: std::ffi::c_int, argv: *const *const std::ffi::c_char) -> std::ffi::c_int;
}
fn main() {
gio::resources_register_include!("audrey.gresource").expect("could not register resources");
unsafe {
std::process::exit(c_main(0, std::ptr::null_mut()))
}
let args = std::env::args_os();
let argc = args.len();
let argv: Vec<std::ffi::CString> = args
.map(|arg| std::ffi::CString::new(std::ffi::OsStr::as_encoded_bytes(&arg)).unwrap())
.collect();
let argv: Vec<*const std::ffi::c_char> = argv.iter().map(|arg| arg.as_ptr()).collect();
unsafe { std::process::exit(c_main(argc as std::ffi::c_int, argv.as_ptr())) }
}