From 36b2cf989d3f1836affec09810ffa439bc7d074e Mon Sep 17 00:00:00 2001 From: Erica Z Date: Tue, 29 Oct 2024 12:29:04 +0100 Subject: [PATCH] cargo fmt, and also pass argc/argv to c lib --- Cargo.lock | 1 - Cargo.toml | 1 - build.rs | 5 +---- src/main.rs | 15 ++++++++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e753eff..8a128fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,6 @@ dependencies = [ "glib-build-tools", "gtk4", "libadwaita", - "libc", "libsecret", ] diff --git a/Cargo.toml b/Cargo.toml index b3f1ebc..6b298ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/build.rs b/build.rs index e316884..cb09dd1 100644 --- a/build.rs +++ b/build.rs @@ -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", ); diff --git a/src/main.rs b/src/main.rs index 643a360..5c9f657 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = 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())) } }