Skip to content

Commit b39cc0c

Browse files
authored
Merge pull request #72 from nbigaouette-eai/fix_library_loading_on_nightly
Fix running under nightly: copy prebuilt `libtensorflow.so` to `OUT_DIR`
2 parents 92d60f9 + 05d4d2b commit b39cc0c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tensorflow-sys/build.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ fn install_prebuilt() {
112112
// Extract the tarball.
113113
let unpacked_dir = download_dir.join(base_name);
114114
let lib_dir = unpacked_dir.join("lib");
115-
if !lib_dir.join(format!("lib{}.so", LIBRARY)).exists() {
115+
let library_file = format!("lib{}.so", LIBRARY);
116+
let library_full_path = lib_dir.join(&library_file);
117+
if !library_full_path.exists() {
116118
extract(file_name, &unpacked_dir);
117119
}
118120

@@ -122,7 +124,16 @@ fn install_prebuilt() {
122124
}); // TODO: remove
123125

124126
println!("cargo:rustc-link-lib=dylib={}", LIBRARY);
125-
println!("cargo:rustc-link-search={}", lib_dir.display());
127+
let output = PathBuf::from(&get!("OUT_DIR"));
128+
let new_library_full_path = output.join(&library_file);
129+
if new_library_full_path.exists() {
130+
log!("File {} already exists, deleting.", new_library_full_path.display());
131+
std::fs::remove_file(&new_library_full_path).unwrap();
132+
}
133+
134+
log!("Copying {} to {}...", library_full_path.display(), new_library_full_path.display());
135+
std::fs::copy(&library_full_path, &new_library_full_path).unwrap();
136+
println!("cargo:rustc-link-search={}", output.display());
126137
}
127138

128139
fn build_from_src() {

0 commit comments

Comments
 (0)