Skip to content

Commit

Permalink
feat(build): support for non-Linux IDEs
Browse files Browse the repository at this point in the history
Rust code generated by build script is now conditionally included from
the output directory for the Linux target, and included from ./.pregenerated/
directory for non-Linux targets.
This allows to copy files generated for Linux to a non-Linux platform,
and an IDE will recognize all the generated definitions.

Signed-off-by: Dmitry Savitskiy <[email protected]>
  • Loading branch information
dsavitskiy committed Sep 21, 2023
1 parent 9cc8d33 commit d693ea2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Cargo.lock

/rust-toolchain.toml
.idea
.vscode
.vscode
.pregenerated
14 changes: 14 additions & 0 deletions src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ impl FromStr for NvmeAnaState {
}
}

// Include Rust sources generated by protobuf.
#[cfg(target_os = "linux")]
include!(concat!(env!("OUT_DIR"), "/mayastor.rs"));

// In order to IDE to work properly with protobuf definitions on non-Linux platform,
// one can copy generated bindings (mayastor.rs) from a Linux target and put them
// to .pregenerated directory.
// This has to be done every time Mayastor API V0 is changed.
#[cfg(not(target_os = "linux"))]
mod v0_generated {
include!("../.pregenerated/mayastor.rs");
}

#[cfg(not(target_os = "linux"))]
pub use v0_generated::*;
10 changes: 10 additions & 0 deletions src/v1.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
//! Module to access v1 version of grpc APIs
use std::str::FromStr;

// dont export the raw pb generated code
mod pb {
// Include Rust sources generated by protobuf.
#![allow(unknown_lints)]
#![allow(clippy::derive_partial_eq_without_eq)]
#[cfg(target_os = "linux")]
include!(concat!(env!("OUT_DIR"), "/mayastor.v1.rs"));

// In order to IDE to work properly with protobuf definitions on non-Linux platform,
// one can copy generated bindings (mayastor.v1.rs) from a Linux target and put them
// to .pregenerated directory.
// This has to be done every time Mayastor API V1 is changed.
#[cfg(not(target_os = "linux"))]
include!("../.pregenerated/mayastor.v1.rs");
}

pub mod common {
Expand Down

0 comments on commit d693ea2

Please sign in to comment.