mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-04-27 22:39:41 +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"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["api"]
|
default = ["api", "json"]
|
||||||
api = ["tonic/transport", "tonic-build/transport", "tokio"]
|
api = ["tonic/transport", "tonic-build/transport", "tokio"]
|
||||||
|
json = ["pbjson", "pbjson-types", "serde"]
|
||||||
internal = []
|
internal = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
prost = "0.11"
|
prost = "0.11"
|
||||||
prost-types = "0.11"
|
prost-types = "0.11"
|
||||||
pbjson = "0.5"
|
|
||||||
pbjson-types = "0.5"
|
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
rand = "0.8"
|
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 }
|
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]
|
[build-dependencies]
|
||||||
tonic-build = { version = "0.8", features = ["prost"], default-features = false }
|
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("meta")).unwrap();
|
||||||
std::fs::create_dir_all(out_dir.join("api")).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
|
// common
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.out_dir(out_dir.join("common"))
|
.out_dir(out_dir.join("common"))
|
||||||
.file_descriptor_set_path(out_dir.join("common").join("proto_descriptor.bin"))
|
.file_descriptor_set_path(out_dir.join("common").join("proto_descriptor.bin"))
|
||||||
.compile_well_known_types(true)
|
.compile_well_known_types(true)
|
||||||
.extern_path(".google.protobuf", "::pbjson_types")
|
.extern_path(".google.protobuf", well_known_types_path)
|
||||||
.compile(
|
.compile(
|
||||||
&[cs_dir.join("common").join("common.proto").to_str().unwrap()],
|
&[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"))?;
|
#[cfg(feature = "json")]
|
||||||
pbjson_build::Builder::new()
|
{
|
||||||
.register_descriptors(&descriptor_set)?
|
let descriptor_set = std::fs::read(out_dir.join("common").join("proto_descriptor.bin"))?;
|
||||||
.out_dir(out_dir.join("common"))
|
pbjson_build::Builder::new()
|
||||||
.build(&[".common"])?;
|
.register_descriptors(&descriptor_set)?
|
||||||
|
.out_dir(out_dir.join("common"))
|
||||||
|
.build(&[".common"])?;
|
||||||
|
}
|
||||||
|
|
||||||
// gw
|
// gw
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.out_dir(out_dir.join("gw"))
|
.out_dir(out_dir.join("gw"))
|
||||||
.file_descriptor_set_path(out_dir.join("gw").join("proto_descriptor.bin"))
|
.file_descriptor_set_path(out_dir.join("gw").join("proto_descriptor.bin"))
|
||||||
.compile_well_known_types(true)
|
.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(".common", "crate::common")
|
||||||
.compile(
|
.compile(
|
||||||
&[cs_dir.join("gw").join("gw.proto").to_str().unwrap()],
|
&[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"))?;
|
#[cfg(feature = "json")]
|
||||||
pbjson_build::Builder::new()
|
{
|
||||||
.register_descriptors(&descriptor_set)?
|
let descriptor_set = std::fs::read(out_dir.join("gw").join("proto_descriptor.bin"))?;
|
||||||
.out_dir(out_dir.join("gw"))
|
pbjson_build::Builder::new()
|
||||||
.extern_path(".common", "crate::common")
|
.register_descriptors(&descriptor_set)?
|
||||||
.build(&[".gw"])?;
|
.out_dir(out_dir.join("gw"))
|
||||||
|
.extern_path(".common", "crate::common")
|
||||||
|
.build(&[".gw"])?;
|
||||||
|
}
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.out_dir(out_dir.join("internal"))
|
.out_dir(out_dir.join("internal"))
|
||||||
.file_descriptor_set_path(out_dir.join("internal").join("proto_descriptor.bin"))
|
.file_descriptor_set_path(out_dir.join("internal").join("proto_descriptor.bin"))
|
||||||
.compile_well_known_types(true)
|
.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(".common", "crate::common")
|
||||||
.compile(
|
.compile(
|
||||||
&[cs_dir
|
&[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"))?;
|
#[cfg(feature = "json")]
|
||||||
pbjson_build::Builder::new()
|
{
|
||||||
.register_descriptors(&descriptor_set)?
|
let descriptor_set = std::fs::read(out_dir.join("internal").join("proto_descriptor.bin"))?;
|
||||||
.out_dir(out_dir.join("internal"))
|
pbjson_build::Builder::new()
|
||||||
.extern_path(".common", "crate::common")
|
.register_descriptors(&descriptor_set)?
|
||||||
.build(&[".internal"])?;
|
.out_dir(out_dir.join("internal"))
|
||||||
|
.extern_path(".common", "crate::common")
|
||||||
|
.build(&[".internal"])?;
|
||||||
|
}
|
||||||
|
|
||||||
// integration
|
// integration
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.out_dir(out_dir.join("integration"))
|
.out_dir(out_dir.join("integration"))
|
||||||
.file_descriptor_set_path(out_dir.join("integration").join("proto_descriptor.bin"))
|
.file_descriptor_set_path(out_dir.join("integration").join("proto_descriptor.bin"))
|
||||||
.compile_well_known_types(true)
|
.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(".common", "crate::common")
|
||||||
.extern_path(".gw", "crate::gw")
|
.extern_path(".gw", "crate::gw")
|
||||||
.compile(
|
.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"))?;
|
#[cfg(feature = "json")]
|
||||||
pbjson_build::Builder::new()
|
{
|
||||||
.emit_fields()
|
let descriptor_set =
|
||||||
.register_descriptors(&descriptor_set)?
|
std::fs::read(out_dir.join("integration").join("proto_descriptor.bin"))?;
|
||||||
.out_dir(out_dir.join("integration"))
|
pbjson_build::Builder::new()
|
||||||
.extern_path(".common", "crate::common")
|
.emit_fields()
|
||||||
.extern_path(".gw", "crate::gw")
|
.register_descriptors(&descriptor_set)?
|
||||||
.build(&[".integration"])?;
|
.out_dir(out_dir.join("integration"))
|
||||||
|
.extern_path(".common", "crate::common")
|
||||||
|
.extern_path(".gw", "crate::gw")
|
||||||
|
.build(&[".integration"])?;
|
||||||
|
}
|
||||||
|
|
||||||
// meta
|
// meta
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
@ -125,13 +144,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
&[proto_dir.join("chirpstack").to_str().unwrap()],
|
&[proto_dir.join("chirpstack").to_str().unwrap()],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let descriptor_set = std::fs::read(out_dir.join("meta").join("proto_descriptor.bin"))?;
|
#[cfg(feature = "json")]
|
||||||
pbjson_build::Builder::new()
|
{
|
||||||
.register_descriptors(&descriptor_set)?
|
let descriptor_set = std::fs::read(out_dir.join("meta").join("proto_descriptor.bin"))?;
|
||||||
.out_dir(out_dir.join("meta"))
|
pbjson_build::Builder::new()
|
||||||
.extern_path(".common", "crate::common")
|
.register_descriptors(&descriptor_set)?
|
||||||
.extern_path(".gw", "crate::gw")
|
.out_dir(out_dir.join("meta"))
|
||||||
.build(&[".meta"])?;
|
.extern_path(".common", "crate::common")
|
||||||
|
.extern_path(".gw", "crate::gw")
|
||||||
|
.build(&[".meta"])?;
|
||||||
|
}
|
||||||
|
|
||||||
// api
|
// api
|
||||||
tonic_build::configure()
|
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::fmt;
|
||||||
use std::str::FromStr;
|
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"));
|
include!(concat!(env!("OUT_DIR"), "/common/common.serde.rs"));
|
||||||
|
|
||||||
#[allow(clippy::from_over_into)]
|
#[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::error::Error;
|
||||||
use std::str::FromStr;
|
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"));
|
include!(concat!(env!("OUT_DIR"), "/gw/gw.serde.rs"));
|
||||||
|
|
||||||
#[allow(clippy::from_over_into)]
|
#[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!(
|
include!(concat!(
|
||||||
env!("OUT_DIR"),
|
env!("OUT_DIR"),
|
||||||
"/integration/integration.serde.rs"
|
"/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"));
|
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"));
|
include!(concat!(env!("OUT_DIR"), "/meta/meta.serde.rs"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user