Skip to content

Commit

Permalink
allow custom build scritps
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Sep 12, 2024
1 parent 37c4bce commit d2ee14e
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/codegen/sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ fn generate_build_script(w: &mut dyn Write, env: &Env, split_build_rs: bool) ->
general::start_comments(w, &env.config)?;
writeln!(w)?;
}

let scripts = find_custom_build_scripts(env).unwrap_or_default();
for script in &scripts {
writeln!(w, "mod {};", script)?;
}
if !scripts.is_empty() {
writeln!(w)?;
}

writeln!(
w,
"{}",
r#"#[cfg(not(docsrs))]
use std::process;"#
)?;
Expand All @@ -61,11 +69,49 @@ fn main() {
println!("cargo:warning={s}");
process::exit(1);
}
}
"#
"#
)?;

for script in &scripts {
writeln!(w, "{}::main();", script)?;
}

write!(
w,
"
}}
"
)
}

fn find_custom_build_scripts(env: &Env) -> Result<Vec<String>> {
let mut vec = Vec::<String>::new();
for entry in std::fs::read_dir(&env.config.auto_path.parent().unwrap())? {

Check failure on line 90 in src/codegen/sys/build.rs

View workflow job for this annotation

GitHub Actions / Hygiene (ubuntu-latest, stable)

the borrowed expression implements the required traits
let path = entry?.path();
let Some(ext) = path.extension() else {
continue;
};
if ext != "rs" {
continue;
}
let file_stem = path.file_stem().expect("No file name");
let file_stem = file_stem
.to_str()
.expect("Can't convert file name to string")
.to_owned();

if !file_stem.starts_with("build_") {
continue;
}

vec.push(file_stem);
}
vec.sort();

Ok(vec)
}

fn generate_build_version(w: &mut dyn Write, env: &Env) -> Result<()> {
general::start_comments(w, &env.config)?;
writeln!(w)?;
Expand Down

0 comments on commit d2ee14e

Please sign in to comment.