Grant Limberg 4 недель назад
Родитель
Сommit
d4ee95e445
2 измененных файлов с 27 добавлено и 14 удалено
  1. 22 14
      rustybits/build.rs
  2. 5 0
      rustybits/src/ext.rs

+ 22 - 14
rustybits/build.rs

@@ -5,20 +5,28 @@ use std::env;
 use std::path::PathBuf;
 
 fn main() {
-    let mut prost_build = prost_build::Config::new();
-
-    prost_build
-        .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
-        .compile_protos(
-            &[
-                "src/pubsub/metadata.proto",
-                "src/pubsub/network.proto",
-                "src/pubsub/member.proto",
-                "src/pubsub/member_status.proto",
-            ],
-            &["src/pubsub/"],
-        )
-        .expect("Failed to compile protobuf files");
+    #[cfg(feature = "ztcontroller")]
+    {
+        // Ensure the `cbindgen` crate is available
+        cbindgen::generate("src/ext.rs")
+            .expect("Unable to generate bindings")
+            .write_to_file("rustybits.h");
+
+        let mut prost_build = prost_build::Config::new();
+
+        prost_build
+            .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
+            .compile_protos(
+                &[
+                    "src/pubsub/metadata.proto",
+                    "src/pubsub/network.proto",
+                    "src/pubsub/member.proto",
+                    "src/pubsub/member_status.proto",
+                ],
+                &["src/pubsub/"],
+            )
+            .expect("Failed to compile protobuf files");
+    }
 
     let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
 

+ 5 - 0
rustybits/src/ext.rs

@@ -14,15 +14,20 @@ use std::ffi::{CStr, CString};
 use std::os::raw::c_char;
 #[cfg(feature = "ztcontroller")]
 use std::os::raw::c_void;
+#[cfg(feature = "ztcontroller")]
 use std::sync::Arc;
+#[cfg(feature = "ztcontroller")]
 use std::time::Duration;
 #[cfg(feature = "ztcontroller")]
 use tokio::runtime;
 use url::Url;
 
+#[cfg(feature = "ztcontroller")]
 static mut RT: Option<tokio::runtime::Runtime> = None;
 
+#[cfg(feature = "ztcontroller")]
 static START: std::sync::Once = std::sync::Once::new();
+#[cfg(feature = "ztcontroller")]
 static SHUTDOWN: std::sync::Once = std::sync::Once::new();
 
 #[cfg(feature = "ztcontroller")]