2 Additionnal build, doc: https://doc.rust-lang.org/cargo/reference/build-scripts.html
5 - Compile the SASS file to CSS file.
8 use std
::{ env
, process
::{ Command
, Output
}, path
::Path
};
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; }
19 println!("cargo:rerun-if-changed=style.scss");
21 fn run_sass(command
: &mut Command
) -> Output
{
24 .arg("static/style.css")
26 .expect("Unable to compile SASS file, install SASS, see https://sass-lang.com/")
29 // Create static directory if it doesn't exist.
30 if !Path
::new("static").exists() {
31 std
::fs
::create_dir("static").unwrap();
35 if exists_in_path("sass.bat") {
36 run_sass(Command
::new("cmd").args(&["/C", "sass.bat"]))
38 run_sass(&mut Command
::new("sass"))
41 if !output
.status
.success() {
42 // SASS will put the error in the file.
43 let error
= std
::fs
::read_to_string("./static/style.css").expect("unable to read style.css");
44 panic!("Error from SASS: {}", error
);