X-Git-Url: http://git.euphorik.ch/?p=rup.git;a=blobdiff_plain;f=backend%2Fbuild.rs;fp=backend%2Fbuild.rs;h=8837cfc46047816ed53049bb7b3019d3acfbf482;hp=0000000000000000000000000000000000000000;hb=1f84b22050cf470b00aef6b3c3ecb7ae70242e1a;hpb=295ca1daf01ff83964812c50fe1374dd679a0559
diff --git a/backend/build.rs b/backend/build.rs
new file mode 100644
index 0000000..8837cfc
--- /dev/null
+++ b/backend/build.rs
@@ -0,0 +1,41 @@
+/*
+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");
+
+ 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);
+ }
+}