Skip to content

Commit 5b2009c

Browse files
committed
Moving runtime bindings into their own crate
Currently the runtime bindings live inside of tensorflow-sys, which includes several packages for building tensorflow. These packages aren't needed for the runtime bindings at all, and this seems like the logical way to separate the two.
1 parent 015eb61 commit 5b2009c

File tree

14 files changed

+61
-32
lines changed

14 files changed

+61
-32
lines changed

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ features = ["private-docs-rs", "tensorflow_unstable", "ndarray", "eager"]
2323
libc = "0.2.132"
2424
num-complex = { version = "0.4.2", default-features = false }
2525
tensorflow-internal-macros = { version = "=0.0.3", path = "tensorflow-internal-macros" }
26-
tensorflow-sys = { version = "0.22.1", path = "tensorflow-sys" }
26+
tensorflow-sys = { version = "0.22.1", path = "tensorflow-sys", optional = true }
27+
tensorflow-sys-runtime = { path = "tensorflow-sys-runtime", optional = true }
2728
byteorder = "1.4.3"
2829
crc = "3.0.0"
2930
half = "2.1.0"
@@ -38,9 +39,10 @@ random = "0.12.2"
3839
serial_test = "0.9.0"
3940

4041
[features]
42+
default = ["tensorflow-sys"]
4143
tensorflow_gpu = ["tensorflow-sys/tensorflow_gpu"]
4244
tensorflow_unstable = []
43-
tensorflow_runtime_linking = ["tensorflow-sys/runtime_linking"]
45+
tensorflow_runtime_linking = ["tensorflow-sys-runtime"]
4446
eager = ["tensorflow-sys/eager"]
4547
# This is for testing purposes; users should not use this.
4648
examples_system_alloc = ["tensorflow-sys/examples_system_alloc"]
@@ -69,4 +71,4 @@ name = "xor"
6971

7072
[[example]]
7173
name = "mobilenetv3"
72-
required-features = ["eager"]
74+
required-features = ["eager"]

src/buffer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use std::ops::RangeTo;
1616
use std::os::raw::c_void as std_c_void;
1717
use std::process;
1818
use std::slice;
19+
#[cfg(feature = "default")]
1920
use tensorflow_sys as tf;
21+
#[cfg(feature = "tensorflow_runtime_linking")]
22+
use tensorflow_sys_runtime as tf;
2023

2124
/// Fixed-length heap-allocated vector.
2225
/// This is basically a `Box<[T]>`, except that that type can't actually be constructed.

src/graph.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ use std::slice;
2828
use std::str::FromStr;
2929
use std::str::Utf8Error;
3030
use std::sync::Arc;
31+
#[cfg(feature = "default")]
3132
use tensorflow_sys as tf;
33+
#[cfg(feature = "tensorflow_runtime_linking")]
34+
use tensorflow_sys_runtime as tf;
3235

3336
#[derive(Debug)]
3437
struct GraphImpl {

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ use std::process;
4949
use std::ptr;
5050
use std::slice;
5151
use std::str::Utf8Error;
52+
#[cfg(feature = "default")]
5253
use tensorflow_sys as tf;
54+
#[cfg(feature = "tensorflow_runtime_linking")]
55+
use tensorflow_sys_runtime as tf;
5356

5457
////////////////////////
5558

src/while_loop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use std::os::raw::c_int;
99
use std::ptr;
1010
use std::result;
1111
use std::slice;
12+
#[cfg(feature = "default")]
1213
use tensorflow_sys as tf;
14+
#[cfg(feature = "tensorflow_runtime_linking")]
15+
use tensorflow_sys_runtime as tf;
16+
1317

1418
// This exists purely to ensure TF_AbortWhile gets called properly, even on panic.
1519
#[derive(Debug)]

tensorflow-sys-runtime/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "tensorflow-sys-runtime"
3+
version = "0.1.0"
4+
authors = ["Brian Jones <[email protected]>"]
5+
license = "Apache-2.0"
6+
keywords = ["TensorFlow", "runtime bindings"]
7+
description = "The package provides runtime bindings to TensorFlow."
8+
documentation = "https://tensorflow.github.io/rust"
9+
homepage = "https://github.com/tensorflow/rust"
10+
repository = "https://github.com/tensorflow/rust"
11+
edition = "2018"
12+
13+
[dependencies]
14+
libc = "0.2.132"
15+
lazy_static = "1.4.0"
16+
libloading = "0.7.3"
17+
cfg-if = "1.0.0"
18+
log = "0.4.17"

tensorflow-sys/src/runtime_linking/c_api.rs renamed to tensorflow-sys-runtime/src/c_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include!("runtime.rs");
12
link! {
23
/* automatically generated by rust-bindgen 0.59.2 */
34

tensorflow-sys-runtime/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![allow(non_camel_case_types)]
2+
#![allow(non_snake_case)]
3+
#![allow(non_upper_case_globals)]
4+
include!("c_api.rs");
5+
include!("types.rs");
6+
include!("finder.rs");
7+
pub use crate::TF_AttrType::*;
8+
pub use crate::TF_Code::*;
9+
pub use crate::TF_DataType::*;
10+
11+
pub mod library {
12+
use std::path::PathBuf;
13+
14+
// Include the definition of `load` here. This allows hiding all of the "extra" linking-related
15+
// functions in the same place, without polluting the top-level namespace (which should only
16+
// contain foreign functions and types).
17+
#[doc(inline)]
18+
pub use super::load;
19+
20+
pub fn find() -> Option<PathBuf> {
21+
super::find("tensorflow")
22+
}
23+
}

0 commit comments

Comments
 (0)