mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Allow static generation of schema code
This commit is contained in:
parent
8c28e50cac
commit
bedde0e19f
@ -6,6 +6,10 @@ build = "build.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
generated = []
|
||||
gen_static = []
|
||||
|
||||
[dependencies]
|
||||
capnp = "0.14.3"
|
||||
capnpc = "0.14.4"
|
||||
|
30
api/build.rs
30
api/build.rs
@ -7,6 +7,7 @@ fn is_hidden(entry: &DirEntry) -> bool {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gen_static"))]
|
||||
fn main() {
|
||||
let mut compile_command = ::capnpc::CompilerCommand::new();
|
||||
compile_command
|
||||
@ -34,3 +35,32 @@ fn main() {
|
||||
println!("Compiling schemas...");
|
||||
compile_command.run().expect("Failed to generate API code");
|
||||
}
|
||||
|
||||
#[cfg(feature = "gen_static")]
|
||||
fn main() {
|
||||
let mut compile_command = ::capnpc::CompilerCommand::new();
|
||||
compile_command
|
||||
.src_prefix("schema")
|
||||
.output_path("src/schema")
|
||||
.default_parent_module(vec!["schema".to_string()]);
|
||||
|
||||
for entry in WalkDir::new("schema")
|
||||
.max_depth(2)
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.filter_map(Result::ok) // Filter all entries that access failed on
|
||||
.filter(|e| !e.file_type().is_dir()) // Filter directories
|
||||
// Filter non-schema files
|
||||
.filter(|e| e.file_name()
|
||||
.to_str()
|
||||
.map(|s| s.ends_with(".capnp"))
|
||||
.unwrap_or(false)
|
||||
)
|
||||
{
|
||||
println!("Collecting schema file {}", entry.path().display());
|
||||
compile_command
|
||||
.file(entry.path());
|
||||
}
|
||||
|
||||
compile_command.run().expect("Failed to generate extra API code");
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
//!
|
||||
//! This crate contains slightly nicer and better documented bindings for the FabAccess API.
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub mod schema;
|
||||
|
||||
/// Authentication subsystem
|
||||
|
@ -1,41 +1,57 @@
|
||||
pub use capnpc::schema_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod auth_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod auth_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod main_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/main_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod main_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod utils_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod utils_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod resource_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/resource_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod resource_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod resources_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/resources_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod resources_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod role_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/role_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod role_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod user_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/user_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod user_capnp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(feature = "generated")]
|
||||
pub mod users_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/users_capnp.rs"));
|
||||
}
|
||||
#[cfg(not(feature = "generated"))]
|
||||
pub mod users_capnp;
|
0
api/src/schema/.gitkeep
Normal file
0
api/src/schema/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user