build.rs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = [
  15. "data_backup.Poll.PollState",
  16. "data_backup.Poll.PollDisplayMode",
  17. "data_backup.Poll.PollAnswerType",
  18. "data_backup.Poll.PollAnnounceType",
  19. "d2d_sync.Contact.AcquaintanceLevel",
  20. "d2d_sync.Contact.ActivityState",
  21. "d2d_sync.Contact.IdentityType",
  22. "d2d_sync.Contact.SyncState",
  23. "d2d_sync.Contact.VerificationLevel",
  24. "d2d_sync.Contact.WorkVerificationLevel",
  25. "d2d_sync.ConversationCategory",
  26. "d2d_sync.ConversationVisibility",
  27. "d2d_sync.Group.UserState",
  28. "d2d_sync.NotificationSoundPolicy",
  29. "d2d_sync.ReadReceiptPolicy",
  30. "d2d_sync.Settings.ContactSyncPolicy",
  31. "d2d_sync.Settings.GroupCallPolicy",
  32. "d2d_sync.Settings.KeyboardDataCollectionPolicy",
  33. "d2d_sync.Settings.O2oCallConnectionPolicy",
  34. "d2d_sync.Settings.O2oCallPolicy",
  35. "d2d_sync.Settings.O2oCallVideoPolicy",
  36. "d2d_sync.Settings.ScreenshotPolicy",
  37. "d2d_sync.Settings.UnknownContactPolicy",
  38. "d2d_sync.TypingIndicatorPolicy",
  39. "d2d_sync.WorkAvailabilityStatusCategory",
  40. ];
  41. // Apply definitions
  42. // -----------------
  43. // General protobuf annotations to apply.
  44. let builder = builder
  45. .message_attribute(".", "#[libthreema_macros::protobuf_annotations]")
  46. .enum_attribute(".", "#[derive(libthreema_macros::Name)]")
  47. .enable_type_names();
  48. // Apply attributes as required by above definition section.
  49. let builder = clap_convertable_enums.iter().fold(builder, |builder, path| {
  50. builder.enum_attribute(path, r#"#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]"#)
  51. });
  52. let builder = ffi_accessible_enums.iter().fold(builder, |builder, path| {
  53. builder.enum_attribute(
  54. path,
  55. r#"
  56. #[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
  57. #[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
  58. #[cfg_attr(
  59. feature = "wasm",
  60. derive(tsify::Tsify, serde::Serialize, serde::Deserialize),
  61. serde(rename_all = "kebab-case"),
  62. tsify(into_wasm_abi, from_wasm_abi)
  63. )]
  64. "#,
  65. )
  66. });
  67. builder.compile_protos(
  68. &[
  69. "../threema-protocols/src/common.proto",
  70. "../threema-protocols/src/data-backup.proto",
  71. "../threema-protocols/src/csp-e2e.proto",
  72. "../threema-protocols/src/data-backup.proto",
  73. "../threema-protocols/src/directory.proto",
  74. "../threema-protocols/src/md-d2d.proto",
  75. "../threema-protocols/src/md-d2d-join.proto",
  76. "../threema-protocols/src/md-d2d-sync.proto",
  77. "../threema-protocols/src/md-d2d-rendezvous.proto",
  78. "../threema-protocols/src/md-d2m.proto",
  79. ],
  80. &["../threema-protocols/src/"],
  81. )?;
  82. // Done
  83. Ok(())
  84. }