From fe411ba1371205a6606af1bf935317c8c0b67989 Mon Sep 17 00:00:00 2001 From: shenjack-5600u <3695888@qq.com> Date: Tue, 11 Mar 2025 22:32:39 +0800 Subject: [PATCH] fix linux unuse warning and fix linux build --- ica-rs/src/py/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 527aa9f..af34197 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -2,7 +2,7 @@ pub mod call; pub mod class; pub mod config; -use std::ffi::{CString, OsStr}; +use std::ffi::CString; use std::fmt::Display; use std::path::Path; use std::sync::OnceLock; @@ -486,10 +486,10 @@ pub fn load_py_file(path: &PathBuf) -> std::io::Result { fn init_py_with_env_path(path: &str) { unsafe { - #[cfg(target_os = "linux")] - use std::os::unix::ffi::OsStrExt; #[cfg(target_os = "windows")] use std::os::windows::ffi::OsStrExt; + #[cfg(target_os = "windows")] + use std::ffi::OsStr; let mut config = std::mem::zeroed::(); let config_ptr = &mut config as *mut pyo3::ffi::PyConfig; @@ -497,6 +497,9 @@ fn init_py_with_env_path(path: &str) { // pyo3::ffi::PyConfig_InitIsolatedConfig(config_ptr); pyo3::ffi::PyConfig_InitPythonConfig(config_ptr); + #[cfg(target_os = "linux")] + let wide_path = path.as_bytes().iter().map(|i| *i as i32).collect::>(); + #[cfg(target_os = "windows")] let wide_path = OsStr::new(path).encode_wide().chain(Some(0)).collect::>(); // 设置 prefix 和 exec_prefix