Skip to content

Commit

Permalink
chore: conditional build
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 30, 2024
1 parent 7e10b07 commit a75497c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down Expand Up @@ -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<T>(file: &mut File, key: &str, val: T)
where
T: std::fmt::Display,
Expand All @@ -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<T>(file: &mut File, key: &str, vec: Vec<T>)
where
T: std::fmt::Display,
Expand Down

0 comments on commit a75497c

Please sign in to comment.