From a75497c616e661a1543b5385afe1174cf2ba8e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Mon, 30 Sep 2024 14:45:03 +0100 Subject: [PATCH] chore: conditional build --- build.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build.rs b/build.rs index 6c5af77..36ae947 100644 --- a/build.rs +++ b/build.rs @@ -22,9 +22,13 @@ //! ); //! ``` +#[cfg(not(feature = "gen-mock"))] use built::write_built_file_with_opts; +#[cfg(not(feature = "gen-mock"))] use chrono::Utc; +#[cfg(not(feature = "gen-mock"))] use regex::Regex; +#[cfg(not(feature = "gen-mock"))] use std::{ env, fs::{File, OpenOptions}, @@ -34,10 +38,16 @@ use std::{ str, }; +#[cfg(not(feature = "gen-mock"))] const BUILD_OUT_FILE: &str = "build.rs"; + +#[cfg(not(feature = "gen-mock"))] const BUILD_ALL_OUT_FILE: &str = "_build.rs"; + +#[cfg(not(feature = "gen-mock"))] const GEN_DIR: &str = "./src/gen"; +#[cfg(not(feature = "gen-mock"))] fn main() { // in case we're running under docs.rs then we must return the control // flow immediately as it's not possible to generate files under the @@ -164,6 +174,10 @@ fn main() { write_built_file_with_opts(Some(manifest_path.as_ref()), &built_path).unwrap(); } +#[cfg(feature = "gen-mock")] +fn main() {} + +#[cfg(not(feature = "gen-mock"))] fn write_constant(file: &mut File, key: &str, val: T) where T: std::fmt::Display, @@ -178,11 +192,13 @@ where .unwrap_or_else(|_| panic!("Failed to write '{key}' to 'build_constants.rs'")); } +#[cfg(not(feature = "gen-mock"))] fn write_str_constant(file: &mut File, key: &str, val: &str) { writeln!(file, "pub const {key}: &str = \"{val}\";") .unwrap_or_else(|_| panic!("Failed to write '{key}' to 'build_constants.rs'")); } +#[cfg(not(feature = "gen-mock"))] fn write_vec_constant(file: &mut File, key: &str, vec: Vec) where T: std::fmt::Display,