Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tensorflow-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ compiled library will be picked up.
**macOS Note**: Via [Homebrew](https://brew.sh/), you can just run
`brew install libtensorflow`.

To statically link Tensorflow, set the environment variable
`TENSORFLOW_LIB_STATIC` to the directory containing `libtensorflow.a`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point to tensorflow/tensorflow#28388 (I assume tensorflow/tensorflow#28388 (comment) specifically) for how to build libtensorflow.a? We may want to include explicit instructions here, e.g.

bazel build --config=monolithic -j 1 //tensorflow:libtensorflow_cc.so
ar -cr libtensorflow.a $(cat bazel-bin/tensorflow/libtensorflow_cc.so.*.params | grep '\.o$')

(Which is what I did, anyway.)


## Resources

[bazel]: http://www.bazel.io
Expand Down
25 changes: 25 additions & 0 deletions tensorflow-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ fn main() {
return;
}

if check_static_link() {
log!(
"Returing early because {} is being statically linked",
LIBRARY
);
return;
}

if check_windows_lib() {
log!("Returning early because {} was already found", LIBRARY);
return;
Expand Down Expand Up @@ -469,3 +477,20 @@ fn check_bazel() -> Result<(), Box<dyn Error>> {
}
Ok(())
}

fn check_static_link() -> bool {
if let Ok(path) = env::var("TENSORFLOW_LIB_STATIC") {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=static={}", LIBRARY);
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=dylib=stdc++");
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-lib=c++");
println!("cargo:rustc-link-lib=framework=foundation");
}
true
} else {
false
}
}