X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=backend%2Fbuild.rs;h=9ae79dee296ec8a2703f7346968f6b88500ab320;hb=cdb883c3c4ccbb82774ecfbfad059f3392e75432;hp=c5f9e2e84f20db5f55a484bea6944f3c65283148;hpb=3ebbe8172b0430bae5c554925a4582c9fec545f3;p=recipes.git diff --git a/backend/build.rs b/backend/build.rs index c5f9e2e..9ae79de 100644 --- a/backend/build.rs +++ b/backend/build.rs @@ -1,11 +1,41 @@ -use std::process::Command; +/* +Additionnal build, doc: https://doc.rust-lang.org/cargo/reference/build-scripts.html + +What is build here: + - Compile the SASS file to CSS file. +*/ + +use std::{ env, process::{ Command, Output }, path::Path }; + +fn exists_in_path

(filename: P) -> bool + where P: AsRef { + for path in env::split_paths(&env::var_os("PATH").unwrap()) { + if path.join(&filename).is_file() { return true; } + } + false +} fn main() { println!("cargo:rerun-if-changed=style.scss"); - Command::new("sass") - .arg("./style.scss") - .arg("./static/style.css") - .output() - .expect("Unable to compile SASS file, install SASS, see https://sass-lang.com/"); + fn run_sass(command: &mut Command) -> Output { + command + .arg("style.scss") + .arg("static/style.css") + .output() + .expect("Unable to compile SASS file, install SASS, see https://sass-lang.com/") + } + + let output = + if exists_in_path("sass.bat") { + run_sass(Command::new("cmd").args(&["/C", "sass.bat"])) + } else { + run_sass(&mut Command::new("sass")) + }; + + if !output.status.success() { + // SASS will put the error in the file. + let error = std::fs::read_to_string("./static/style.css").expect("unable to read style.css"); + panic!("{}", error); + } } \ No newline at end of file