roll

Rolled my own static website builder 💻

NameSizeMode
..
build.rs 1K -rw-r--r--
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::{env, path::PathBuf, process};
use syntect::{parsing::SyntaxSet};

const SYNTAX_DEFS_SUBDIR:         &str = "syntax/";
const SYNTAX_SET_OUTPUT_FILENAME: &str = "syntax-set.dump";

fn main() {
  let cargo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

  let mut syntax_defs_dir = cargo_root.clone();
  syntax_defs_dir.push(SYNTAX_DEFS_SUBDIR);

  let syntax_set = match SyntaxSet::load_from_folder(&syntax_defs_dir) {
    Ok(syntax_set) => syntax_set,
    Err(e)         => {
      println!("cargo::error=Could not compile syntax defitions: {e}");
      process::exit(1);
    }
  };

  let mut syntax_set_output_path = PathBuf::from(env::var("OUT_DIR").unwrap());
  syntax_set_output_path.push(SYNTAX_SET_OUTPUT_FILENAME);
  if let Err(e) = syntect::dumps::dump_to_uncompressed_file(
      &syntax_set,
      syntax_set_output_path,
    ) {
      println!("cargo::error=Could not dump syntax defitions: {e}");
      process::exit(1);
  }

  println!("cargo:rerun-if-changed=config.toml");
}