Skip to content

Commit

Permalink
Fix running under nightly: copy prebuilt libtensorflow.so to OUT_DIR
Browse files Browse the repository at this point in the history
A change in cargo nightly (merged on February 7th 2017) changed how
dynamic libraries are loaded. This prevented the `tensorflow-sys` crate's
tests to run.

To fix, simply copy the `libtensorflow.so` pre-built library to `OUT_DIR`
and change `cargo:rustc-link-search=` path so cargo can find it when
running the tests.

See:
* issue: tensorflow#71
* cargo's pull request: rust-lang/cargo#3651
  • Loading branch information
nbigaouette-eai committed Mar 17, 2017
1 parent 8bd62df commit b6bf663
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tensorflow-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ fn install_prebuilt() {
// Extract the tarball.
let unpacked_dir = download_dir.join(base_name);
let lib_dir = unpacked_dir.join("lib");
if !lib_dir.join(format!("lib{}.so", LIBRARY)).exists() {
let library_file = format!("lib{}.so", LIBRARY);
let library_full_path = lib_dir.join(&library_file);
if !library_full_path.exists() {
extract(file_name, &unpacked_dir);
}

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

println!("cargo:rustc-link-lib=dylib={}", LIBRARY);
println!("cargo:rustc-link-search={}", lib_dir.display());
let output = PathBuf::from(&get!("OUT_DIR"));
let new_library_full_path = output.join(&library_file);
if new_library_full_path.exists() {
println!("File {} already exists, deleting.", new_library_full_path.display());
std::fs::remove_file(&new_library_full_path).unwrap();
}

println!("Copying {} to {}...", library_full_path.display(), new_library_full_path.display());
std::fs::copy(&library_full_path, &new_library_full_path).unwrap();
println!("cargo:rustc-link-search={}", output.display());
}

fn build_from_src() {
Expand Down

0 comments on commit b6bf663

Please sign in to comment.