Skip to content

Commit

Permalink
Retrieve and build protobuf from remote URLs (#63)
Browse files Browse the repository at this point in the history
Currently, this project is using cargo git dependencies to reference the proto packages from other ESDV projects such as Freyja. This has caused compatibility issues and needs to be updated. This PR makes a change to pull the content from a remote URL and build the proto files within the repo. Inspired by UProtocol: https://github.com/eclipse-uprotocol/up-rust/blob/main/build.rs

Fixes #59
  • Loading branch information
wilyle authored Mar 25, 2024
1 parent f16863b commit 1c44ac1
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 92 deletions.
371 changes: 287 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ members = [
"freyja_apps/e2e",
"freyja_apps/ibeji_integration",
"freyja_apps/in_memory",
"proto/cloud_connector",
"proto/common"
]

[workspace.dependencies]
# Local dependencies
cloud-connector-proto = { path = "proto/cloud_connector" }
proto-common = { path = "proto/common" }

# ESDV dependencies
# Versioning is managed by the Cargo.lock file rather than copying rev properties to all of these

## Freyja
cloud-connector-proto = { git = "https://github.com/eclipse-ibeji/freyja" }
file-service-discovery-adapter = { git = "https://github.com/eclipse-ibeji/freyja" }
freyja = { git = "https://github.com/eclipse-ibeji/freyja" }
freyja-common = { git = "https://github.com/eclipse-ibeji/freyja" }
freyja-build-common = { git = "https://github.com/eclipse-ibeji/freyja" }
freyja-proto-common = { git = "https://github.com/eclipse-ibeji/freyja", package = "proto-common" }
grpc-cloud-adapter = { git = "https://github.com/eclipse-ibeji/freyja" }
grpc-digital-twin-adapter = { git = "https://github.com/eclipse-ibeji/freyja" }
grpc-service-discovery-adapter = { git = "https://github.com/eclipse-ibeji/freyja" }
Expand All @@ -42,9 +47,10 @@ futures = "0.3.30"
log = "0.4.21"
paho-mqtt = "0.12.1"
prost = "0.12.3"
prost-types = "0.12.3"
serde = "1.0.197"
serde_json = "1.0.114"
time = "0.3.34"
time = { version = "0.3.34", features = ["serde-human-readable"] }
tokio = "1.36.0"
tonic = "0.11.0"
tonic-build = "0.11.0"
15 changes: 9 additions & 6 deletions cloud_connectors/mqtt_connector/src/mqtt_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ impl CloudConnector for MQTTConnector {

#[cfg(test)]
mod azure_cloud_connector_tests {
use cloud_connector_proto::v1::UpdateDigitalTwinRequestBuilder;

use super::*;

#[tokio::test]
Expand All @@ -191,11 +189,16 @@ mod azure_cloud_connector_tests {
mqtt_event_grid_topic: String::new(),
};

let builder = UpdateDigitalTwinRequestBuilder::new().string_value(String::new());

let request = tonic::Request::new(builder.build());
let request = UpdateDigitalTwinRequest {
value: Some(Value {
kind: Some(Kind::StringValue(String::new())),
}),
..Default::default()
};

let result = consumer_impl.update_digital_twin(request).await;
let result = consumer_impl
.update_digital_twin(tonic::Request::new(request))
.await;

assert!(result.is_err());
}
Expand Down
19 changes: 19 additions & 0 deletions proto/cloud_connector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[package]
name = "cloud-connector-proto"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
prost = { workspace = true }
prost-types = { workspace = true }
tonic = { workspace = true }

[build-dependencies]
freyja-build-common = { workspace = true }
freyja-proto-common = { workspace = true }
proto-common = { workspace = true }
12 changes: 12 additions & 0 deletions proto/cloud_connector/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use freyja_build_common::compile_remote_proto;
use freyja_proto_common::interface_url;

fn main() -> Result<(), Box<dyn std::error::Error>> {
compile_remote_proto(interface_url!(freyja, CLOUD_CONNECTOR_INTERFACE), &[])?;

Ok(())
}
10 changes: 10 additions & 0 deletions proto/cloud_connector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

// Re-export this library so consumers have access to the types used in generation
pub use prost_types;

pub mod v1 {
tonic::include_proto!("cloud_connector");
}
11 changes: 11 additions & 0 deletions proto/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
# SPDX-License-Identifier: MIT

[package]
name = "proto-common"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
21 changes: 21 additions & 0 deletions proto/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

// This module contains constants related to remote protobuf files as well as helpers for referencing them.
// This also helps manage interface versions from a central location, which is particularly helpful for Ibeji since
// the interfaces are referenced in two different crates.

pub const GITHUB_BASE_URL: &str = "https://raw.githubusercontent.com";

pub mod freyja {
pub const REPO_NAME: &str = "eclipse-ibeji/freyja";
pub const VERSION: &str = "0.1.0";

pub mod interfaces {
pub const CLOUD_CONNECTOR_INTERFACE: &str =
"interfaces/cloud_connector/v1/cloud_connector.proto";
pub const MAPPING_SERVICE_INTERFACE: &str =
"interfaces/mapping_service/v1/mapping_service.proto";
}
}

0 comments on commit 1c44ac1

Please sign in to comment.