Skip to content

Commit

Permalink
feat: symlink dylibs to examples & test dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Nov 13, 2023
1 parent c7af2c8 commit e694ebc
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions ort-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,26 @@ fn extract_zip(filename: &Path, outpath: &Path) {
fn copy_libraries(lib_dir: &Path, out_dir: &Path) {
// get the target directory - we need to place the dlls next to the executable so they can be properly loaded by windows
let out_dir = out_dir.ancestors().nth(3).unwrap();

let lib_files = fs::read_dir(lib_dir).unwrap();
for lib_file in lib_files.filter(|e| {
e.as_ref().ok().map_or(false, |e| {
e.file_type().map_or(false, |e| !e.is_dir())
&& [".dll", ".so", ".dylib"]
.into_iter()
.any(|v| e.path().into_os_string().into_string().unwrap().contains(v))
})
}) {
let lib_file = lib_file.unwrap();
let lib_path = lib_file.path();
let lib_name = lib_path.file_name().unwrap();
let out_path = out_dir.join(lib_name);
if !out_path.exists() {
fs::copy(&lib_path, out_path).unwrap();
for out_dir in [out_dir.to_path_buf(), out_dir.join("examples"), out_dir.join("deps")] {
let lib_files = fs::read_dir(lib_dir).unwrap();
for lib_file in lib_files.filter(|e| {
e.as_ref().ok().map_or(false, |e| {
e.file_type().map_or(false, |e| !e.is_dir())
&& [".dll", ".so", ".dylib"]
.into_iter()
.any(|v| e.path().into_os_string().into_string().unwrap().contains(v))
})
}) {
let lib_file = lib_file.unwrap();
let lib_path = lib_file.path();
let lib_name = lib_path.file_name().unwrap();
let out_path = out_dir.join(lib_name);
if !out_path.exists() {
#[cfg(windows)]
std::os::windows::fs::symlink_file(&lib_path, out_path).unwrap();
#[cfg(unix)]
std::os::unix::fs::symlink(&lib_path, out_path).unwrap();
}
}
}
}
Expand Down

0 comments on commit e694ebc

Please sign in to comment.