-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve AW_WEBUI_DIR handling (#424)
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
use std::error::Error; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
// if aw-webui/dist does not exist or is empty, print a warning | ||
let path = std::path::Path::new("../aw-webui/dist"); | ||
let webui_var = std::env::var("AW_WEBUI_DIR"); | ||
let path = if let Ok(var_path) = &webui_var { | ||
std::path::Path::new(var_path) | ||
} else { | ||
let path = std::path::Path::new("../aw-webui/dist"); | ||
// ensure folder exists, since macro requires it | ||
std::fs::create_dir_all(path)?; | ||
println!("cargo:rustc-env=AW_WEBUI_DIR={}", path.display()); | ||
path | ||
}; | ||
|
||
let path_index = path.join("index.html"); | ||
if !path_index.exists() { | ||
println!("cargo:warning=`./aw-webui/dist` is not built, compiling without webui"); | ||
println!( | ||
"cargo:warning=`{}` is not built, compiling without webui", | ||
path.display() | ||
); | ||
} | ||
|
||
// ensure folder exists, since macro requires it | ||
std::fs::create_dir_all(path)?; | ||
println!("cargo:rustc-env=AW_WEBUI_DIR=../aw-webui/dist"); | ||
|
||
Ok(()) | ||
} |