build.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //! Builds libthreema (d'oh!).
  2. use std::io::Result;
  3. #[cfg(feature = "uniffi")]
  4. use uniffi as _;
  5. fn main() -> Result<()> {
  6. // Configure and compile protobuf
  7. println!("cargo:rerun-if-changed=../threema-protocols/src/");
  8. let mut builder = prost_build::Config::new();
  9. // Definitions
  10. // -----------
  11. // Enums that should be convertable from/to a clap `ValueEnum`.
  12. let clap_convertable_enums = ["d2m.DeviceSlotState"];
  13. // Define enums that should be accessible across the FFI boundary.
  14. let ffi_accessible_enums = ["d2d_sync.WorkAvailabilityStatusCategory"];
  15. // Apply definitions
  16. // -----------------
  17. // General protobuf annotations to apply.
  18. let builder = builder
  19. .message_attribute(".", "#[libthreema_macros::protobuf_annotations]")
  20. .enable_type_names();
  21. // Apply attributes as required by above definition section.
  22. let builder = clap_convertable_enums.iter().fold(builder, |builder, path| {
  23. builder.enum_attribute(path, r#"#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]"#)
  24. });
  25. let builder = ffi_accessible_enums.iter().fold(builder, |builder, path| {
  26. builder.enum_attribute(
  27. path,
  28. r#"
  29. #[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
  30. #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
  31. #[cfg_attr(
  32. feature = "wasm",
  33. derive(tsify::Tsify, serde::Serialize, serde::Deserialize),
  34. serde(rename_all = "kebab-case"),
  35. tsify(into_wasm_abi, from_wasm_abi)
  36. )]
  37. "#,
  38. )
  39. });
  40. builder.compile_protos(
  41. &[
  42. "../threema-protocols/src/common.proto",
  43. "../threema-protocols/src/csp-e2e.proto",
  44. "../threema-protocols/src/directory.proto",
  45. "../threema-protocols/src/md-d2d.proto",
  46. "../threema-protocols/src/md-d2d-sync.proto",
  47. "../threema-protocols/src/md-d2d-rendezvous.proto",
  48. "../threema-protocols/src/md-d2m.proto",
  49. ],
  50. &["../threema-protocols/src/"],
  51. )?;
  52. // Done
  53. Ok(())
  54. }