<<<<<<< nkmumlpy 2a5b03c6 "chore: 版本号更新到 0.1.7" (rebase destination) fn main() {} ||||||| sxlwkwwz 32ed8f03 "fix: improve library extraction and bake RPATH into binary (#8)" (parents of rebased revision) use std::env; use std::path::PathBuf; fn main() { let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); if target_os == "linux" { // Set the RPATH for the binary println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/runtime"); // Optional: Automatically link the runtime folder into the target directory // so 'cargo run' works without extra RPATHs let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let profile_dir = out_dir.join("../../../"); // Points to target/debug or target/release let project_runtime = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("runtime"); let target_runtime = profile_dir.join("runtime"); if project_runtime.exists() && !target_runtime.exists() { #[cfg(unix)] let _ = std::os::unix::fs::symlink(project_runtime, target_runtime); } } } ======= use std::env; use std::fs; use std::path::Path; use std::path::PathBuf; use std::process::Command; #[cfg(unix)] fn ensure_symlink(target: &Path, link: &Path) { if link.exists() { return; } if let Some(parent) = link.parent() { let _ = fs::create_dir_all(parent); } let _ = std::os::unix::fs::symlink(target, link); } #[cfg(not(unix))] fn ensure_symlink(_target: &Path, _link: &Path) {} fn main() { let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); if target_os == "linux" { // Set the RPATH for the binary //println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN/runtime"); // Optional: Automatically link the runtime folder into the target directory // so 'cargo run' works without extra RPATHs let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let profile_dir = out_dir.join("../../../"); // Points to target/debug or target/release let project_runtime = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("runtime"); let target_runtime = profile_dir.join("runtime"); if project_runtime.exists() && !target_runtime.exists() { #[cfg(unix)] let _ = std::os::unix::fs::symlink(&project_runtime, target_runtime); } if project_runtime.exists() { for lib_name in ["libstdc++.so.6", "libgomp.so.1"] { if let Ok(output) = Command::new("gcc") .arg(format!("-print-file-name={}", lib_name)) .output() { if output.status.success() { let lib_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); let lib_path = PathBuf::from(lib_path); if lib_path.exists() && lib_path.file_name().is_some() { let link_path = project_runtime.join(lib_path.file_name().unwrap()); ensure_symlink(&lib_path, &link_path); } } } } } } } >>>>>>> xruvuyky 5f2a399a "修复了编译错误和onnx运行时链接错误" (rebased revision)