Be able to use 'sass.bat' on Windows.
[rup.git] / backend / build.rs
1 /*
2 Additionnal build, doc: https://doc.rust-lang.org/cargo/reference/build-scripts.html
3
4 What is build here:
5 - Compile the SASS file to CSS file.
6 */
7
8 use std::{ env, process::{ Command, Output }, path::Path };
9
10 fn exists_in_path<P>(filename: P) -> bool
11 where P: AsRef<Path> {
12 for path in env::split_paths(&env::var_os("PATH").unwrap()) {
13 if path.join(&filename).is_file() { return true; }
14 }
15 false
16 }
17
18 fn main() {
19 println!("cargo:rerun-if-changed=style.scss");
20
21 fn run_sass(command: &mut Command) -> Output {
22 command
23 .arg("style.scss")
24 .arg("static/style.css")
25 .output()
26 .expect("Unable to compile SASS file, install SASS, see https://sass-lang.com/")
27 }
28
29 let output =
30 if exists_in_path("sass.bat") {
31 run_sass(Command::new("cmd").args(&["/C", "sass.bat"]))
32 } else {
33 run_sass(&mut Command::new("sass"))
34 };
35
36 if !output.status.success() {
37 // SASS will put the error in the file.
38 let error = std::fs::read_to_string("./static/style.css").expect("unable to read style.css");
39 panic!(error);
40 }
41 }