Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target specific versions for remote protobuf files #159

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"mocks/mock_mapping_service",
"proc_macros",
"proto/cloud_connector",
"proto/common",
"proto/core_protobuf_data_access",
"proto/mapping_service",
"proto/samples_protobuf_data_access",
Expand Down Expand Up @@ -53,6 +54,7 @@ mapping-service-proto = { path = "proto/mapping_service" }
mock-digital-twin = { path = "mocks/mock_digital_twin" }
mqtt-data-adapter = { path = "adapters/data/mqtt_data_adapter" }
proc-macros = { path = "proc_macros" }
proto-common = { path = "proto/common" }
sample-grpc-data-adapter = { path = "adapters/data/sample_grpc_data_adapter" }
samples-protobuf-data-access = { path = "proto/samples_protobuf_data_access" }
service_discovery_proto = { path = "proto/service_discovery_proto" }
Expand Down
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]
53 changes: 53 additions & 0 deletions proto/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 ibeji {
pub const REPO_NAME: &str = "eclipse-ibeji/ibeji";
pub const VERSION: &str = "0.1.1";

pub mod interfaces {
pub const INVEHICLE_DIGITAL_TWIN_INTERFACE: &str =
"interfaces/invehicle_digital_twin/v1/invehicle_digital_twin.proto";
pub const MANAGED_SUBSCRIBE_INTERFACE: &str =
"interfaces/module/managed_subscribe/v1/managed_subscribe.proto";
pub const SAMPLE_CONSUMER_INTERFACE: &str =
"samples/interfaces/sample_grpc/v1/digital_twin_consumer.proto";
pub const SAMPLE_PROVIDER_INTERFACE: &str =
"samples/interfaces/sample_grpc/v1/digital_twin_provider.proto";
}
}

pub mod chariott {
pub const REPO_NAME: &str = "eclipse-chariott/chariott";
pub const VERSION: &str = "0.2.1";

pub mod interfaces {
pub const SERVICE_REGISTRY_INTERFACE: &str =
"service_discovery/proto/core/v1/service_registry.proto";
}
}

/// Macro that simplifies the construction of URLs for remote protobuf interfaces.
///
/// # Arguments
/// - `service`: the service name. Corresponds to one of the submodules of `proto_common`.
/// - `interface`: the interface name. Corresponds to one of the constants in the `interfaces` sub-module of the `service` module.
#[macro_export]
macro_rules! interface_url {
($service:ident, $interface:ident) => {
format!(
"{}/{}/{}/{}",
proto_common::GITHUB_BASE_URL,
proto_common::$service::REPO_NAME,
proto_common::$service::VERSION,
proto_common::$service::interfaces::$interface
)
};
}
3 changes: 2 additions & 1 deletion proto/core_protobuf_data_access/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ serde = { workspace = true }
tonic = { workspace = true }

[build-dependencies]
freyja-build-common = { workspace = true }
freyja-build-common = { workspace = true }
proto-common = { workspace = true }
10 changes: 3 additions & 7 deletions proto/core_protobuf_data_access/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
// SPDX-License-Identifier: MIT

use freyja_build_common::{compile_remote_proto, SERDE_DERIVE_ATTRIBUTE};

const IBEJI_INTERFACES_BASE_URI: &str =
"https://raw.githubusercontent.com/eclipse-ibeji/ibeji/main/interfaces";
use proto_common::interface_url;

fn main() -> Result<(), Box<dyn std::error::Error>> {
compile_remote_proto(
format!(
"{IBEJI_INTERFACES_BASE_URI}/invehicle_digital_twin/v1/invehicle_digital_twin.proto"
),
interface_url!(ibeji, INVEHICLE_DIGITAL_TWIN_INTERFACE),
&[
("EndpointInfo", SERDE_DERIVE_ATTRIBUTE),
("EntityAccessInfo", SERDE_DERIVE_ATTRIBUTE),
],
)?;
compile_remote_proto(
format!("{IBEJI_INTERFACES_BASE_URI}/module/managed_subscribe/v1/managed_subscribe.proto"),
interface_url!(ibeji, MANAGED_SUBSCRIBE_INTERFACE),
&[
("Constraint", SERDE_DERIVE_ATTRIBUTE),
("CallbackPayload", SERDE_DERIVE_ATTRIBUTE),
Expand Down
3 changes: 2 additions & 1 deletion proto/samples_protobuf_data_access/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ prost-types = { workspace = true }
tonic = { workspace = true }

[build-dependencies]
freyja-build-common = { workspace = true }
freyja-build-common = { workspace = true }
proto-common = { workspace = true }
13 changes: 3 additions & 10 deletions proto/samples_protobuf_data_access/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
// SPDX-License-Identifier: MIT

use freyja_build_common::compile_remote_proto;

const IBEJI_SAMPLE_INTERFACES_BASE_URI: &str =
"https://raw.githubusercontent.com/eclipse-ibeji/ibeji/main/samples/interfaces";
const SAMPLE_GRPC_INTERFACE_PATH: &str = "sample_grpc/v1";
use proto_common::interface_url;

fn main() -> Result<(), Box<dyn std::error::Error>> {
compile_remote_proto(
format!("{IBEJI_SAMPLE_INTERFACES_BASE_URI}/{SAMPLE_GRPC_INTERFACE_PATH}/digital_twin_consumer.proto"),
&[])?;
compile_remote_proto(
format!("{IBEJI_SAMPLE_INTERFACES_BASE_URI}/{SAMPLE_GRPC_INTERFACE_PATH}/digital_twin_provider.proto"),
&[])?;
compile_remote_proto(interface_url!(ibeji, SAMPLE_CONSUMER_INTERFACE), &[])?;
compile_remote_proto(interface_url!(ibeji, SAMPLE_PROVIDER_INTERFACE), &[])?;

Ok(())
}
3 changes: 2 additions & 1 deletion proto/service_discovery_proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ prost-types = { workspace = true }
tonic = { workspace = true }

[build-dependencies]
freyja-build-common = { workspace = true }
freyja-build-common = { workspace = true }
proto-common = { workspace = true }
9 changes: 2 additions & 7 deletions proto/service_discovery_proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
// SPDX-License-Identifier: MIT

use freyja_build_common::compile_remote_proto;

const CHARIOTT_SERVICE_DISCOVERY_INTERFACES_BASE_URI: &str =
"https://raw.githubusercontent.com/eclipse-chariott/chariott/main/service_discovery/proto";
use proto_common::interface_url;

fn main() -> Result<(), Box<dyn std::error::Error>> {
compile_remote_proto(
format!("{CHARIOTT_SERVICE_DISCOVERY_INTERFACES_BASE_URI}/core/v1/service_registry.proto"),
&[],
)?;
compile_remote_proto(interface_url!(chariott, SERVICE_REGISTRY_INTERFACE), &[])?;

Ok(())
}
Loading