mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-04-27 06:20:28 +00:00
Improve Rust SDK build flags / reduce dependencies.
This reduces the amount of dependencies in case not all features are being used. E.g. tonic is only needed if using gRPC and pbjson, pbjson-types and serde are only needed if using the JSON serialization.
This commit is contained in:
parent
4917de2b32
commit
8fe0c7c6c2
11
api/rust/Cargo.toml
vendored
11
api/rust/Cargo.toml
vendored
@ -9,21 +9,22 @@ repository = "https://github.com/chirpstack/chirpstack"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = ["api"]
|
||||
default = ["api", "json"]
|
||||
api = ["tonic/transport", "tonic-build/transport", "tokio"]
|
||||
json = ["pbjson", "pbjson-types", "serde"]
|
||||
internal = []
|
||||
|
||||
[dependencies]
|
||||
prost = "0.11"
|
||||
prost-types = "0.11"
|
||||
pbjson = "0.5"
|
||||
pbjson-types = "0.5"
|
||||
hex = "0.4"
|
||||
rand = "0.8"
|
||||
|
||||
tonic = { version = "0.8", features = ["codegen", "prost"], default-features = false }
|
||||
tonic = { version = "0.8", features = ["codegen", "prost"], default-features = false, optional = true }
|
||||
tokio = { version = "1.25", features = ["macros"], optional = true }
|
||||
serde = { version = "1.0" }
|
||||
pbjson = { version = "0.5", optional = true }
|
||||
pbjson-types = { version = "0.5", optional = true }
|
||||
serde = { version = "1.0", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = { version = "0.8", features = ["prost"], default-features = false }
|
||||
|
94
api/rust/build.rs
vendored
94
api/rust/build.rs
vendored
@ -16,12 +16,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
std::fs::create_dir_all(out_dir.join("meta")).unwrap();
|
||||
std::fs::create_dir_all(out_dir.join("api")).unwrap();
|
||||
|
||||
#[cfg(feature = "json")]
|
||||
let well_known_types_path = "::pbjson_types";
|
||||
|
||||
#[cfg(not(feature = "json"))]
|
||||
let well_known_types_path = "::prost_types";
|
||||
|
||||
// common
|
||||
tonic_build::configure()
|
||||
.out_dir(out_dir.join("common"))
|
||||
.file_descriptor_set_path(out_dir.join("common").join("proto_descriptor.bin"))
|
||||
.compile_well_known_types(true)
|
||||
.extern_path(".google.protobuf", "::pbjson_types")
|
||||
.extern_path(".google.protobuf", well_known_types_path)
|
||||
.compile(
|
||||
&[cs_dir.join("common").join("common.proto").to_str().unwrap()],
|
||||
&[
|
||||
@ -30,18 +36,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
],
|
||||
)?;
|
||||
|
||||
let descriptor_set = std::fs::read(out_dir.join("common").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("common"))
|
||||
.build(&[".common"])?;
|
||||
#[cfg(feature = "json")]
|
||||
{
|
||||
let descriptor_set = std::fs::read(out_dir.join("common").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("common"))
|
||||
.build(&[".common"])?;
|
||||
}
|
||||
|
||||
// gw
|
||||
tonic_build::configure()
|
||||
.out_dir(out_dir.join("gw"))
|
||||
.file_descriptor_set_path(out_dir.join("gw").join("proto_descriptor.bin"))
|
||||
.compile_well_known_types(true)
|
||||
.extern_path(".google.protobuf", "::pbjson_types")
|
||||
.extern_path(".google.protobuf", well_known_types_path)
|
||||
.extern_path(".common", "crate::common")
|
||||
.compile(
|
||||
&[cs_dir.join("gw").join("gw.proto").to_str().unwrap()],
|
||||
@ -51,19 +60,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
],
|
||||
)?;
|
||||
|
||||
let descriptor_set = std::fs::read(out_dir.join("gw").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("gw"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.build(&[".gw"])?;
|
||||
#[cfg(feature = "json")]
|
||||
{
|
||||
let descriptor_set = std::fs::read(out_dir.join("gw").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("gw"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.build(&[".gw"])?;
|
||||
}
|
||||
|
||||
// internal
|
||||
tonic_build::configure()
|
||||
.out_dir(out_dir.join("internal"))
|
||||
.file_descriptor_set_path(out_dir.join("internal").join("proto_descriptor.bin"))
|
||||
.compile_well_known_types(true)
|
||||
.extern_path(".google.protobuf", "::pbjson_types")
|
||||
.extern_path(".google.protobuf", well_known_types_path)
|
||||
.extern_path(".common", "crate::common")
|
||||
.compile(
|
||||
&[cs_dir
|
||||
@ -77,19 +89,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
],
|
||||
)?;
|
||||
|
||||
let descriptor_set = std::fs::read(out_dir.join("internal").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("internal"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.build(&[".internal"])?;
|
||||
#[cfg(feature = "json")]
|
||||
{
|
||||
let descriptor_set = std::fs::read(out_dir.join("internal").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("internal"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.build(&[".internal"])?;
|
||||
}
|
||||
|
||||
// integration
|
||||
tonic_build::configure()
|
||||
.out_dir(out_dir.join("integration"))
|
||||
.file_descriptor_set_path(out_dir.join("integration").join("proto_descriptor.bin"))
|
||||
.compile_well_known_types(true)
|
||||
.extern_path(".google.protobuf", "::pbjson_types")
|
||||
.extern_path(".google.protobuf", well_known_types_path)
|
||||
.extern_path(".common", "crate::common")
|
||||
.extern_path(".gw", "crate::gw")
|
||||
.compile(
|
||||
@ -104,14 +119,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
],
|
||||
)?;
|
||||
|
||||
let descriptor_set = std::fs::read(out_dir.join("integration").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.emit_fields()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("integration"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.extern_path(".gw", "crate::gw")
|
||||
.build(&[".integration"])?;
|
||||
#[cfg(feature = "json")]
|
||||
{
|
||||
let descriptor_set =
|
||||
std::fs::read(out_dir.join("integration").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.emit_fields()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("integration"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.extern_path(".gw", "crate::gw")
|
||||
.build(&[".integration"])?;
|
||||
}
|
||||
|
||||
// meta
|
||||
tonic_build::configure()
|
||||
@ -125,13 +144,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
&[proto_dir.join("chirpstack").to_str().unwrap()],
|
||||
)?;
|
||||
|
||||
let descriptor_set = std::fs::read(out_dir.join("meta").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("meta"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.extern_path(".gw", "crate::gw")
|
||||
.build(&[".meta"])?;
|
||||
#[cfg(feature = "json")]
|
||||
{
|
||||
let descriptor_set = std::fs::read(out_dir.join("meta").join("proto_descriptor.bin"))?;
|
||||
pbjson_build::Builder::new()
|
||||
.register_descriptors(&descriptor_set)?
|
||||
.out_dir(out_dir.join("meta"))
|
||||
.extern_path(".common", "crate::common")
|
||||
.extern_path(".gw", "crate::gw")
|
||||
.build(&[".meta"])?;
|
||||
}
|
||||
|
||||
// api
|
||||
tonic_build::configure()
|
||||
|
3
api/rust/src/common.rs
vendored
3
api/rust/src/common.rs
vendored
@ -2,7 +2,8 @@ use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
tonic::include_proto!("common/common");
|
||||
include!(concat!(env!("OUT_DIR"), "/common/common.rs"));
|
||||
#[cfg(feature = "json")]
|
||||
include!(concat!(env!("OUT_DIR"), "/common/common.serde.rs"));
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
|
3
api/rust/src/gw.rs
vendored
3
api/rust/src/gw.rs
vendored
@ -2,7 +2,8 @@ use rand::Rng;
|
||||
use std::error::Error;
|
||||
use std::str::FromStr;
|
||||
|
||||
tonic::include_proto!("gw/gw");
|
||||
include!(concat!(env!("OUT_DIR"), "/gw/gw.rs"));
|
||||
#[cfg(feature = "json")]
|
||||
include!(concat!(env!("OUT_DIR"), "/gw/gw.serde.rs"));
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
|
3
api/rust/src/integration.rs
vendored
3
api/rust/src/integration.rs
vendored
@ -1,4 +1,5 @@
|
||||
tonic::include_proto!("integration/integration");
|
||||
include!(concat!(env!("OUT_DIR"), "/integration/integration.rs"));
|
||||
#[cfg(feature = "json")]
|
||||
include!(concat!(
|
||||
env!("OUT_DIR"),
|
||||
"/integration/integration.serde.rs"
|
||||
|
3
api/rust/src/internal.rs
vendored
3
api/rust/src/internal.rs
vendored
@ -1,2 +1,3 @@
|
||||
tonic::include_proto!("internal/internal");
|
||||
include!(concat!(env!("OUT_DIR"), "/internal/internal.rs"));
|
||||
#[cfg(feature = "json")]
|
||||
include!(concat!(env!("OUT_DIR"), "/internal/internal.serde.rs"));
|
||||
|
3
api/rust/src/meta.rs
vendored
3
api/rust/src/meta.rs
vendored
@ -1,2 +1,3 @@
|
||||
tonic::include_proto!("meta/meta");
|
||||
include!(concat!(env!("OUT_DIR"), "/meta/meta.rs"));
|
||||
#[cfg(feature = "json")]
|
||||
include!(concat!(env!("OUT_DIR"), "/meta/meta.serde.rs"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user