forked from cncf/landscape2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
53 lines (46 loc) · 1.52 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use anyhow::{format_err, Result};
use std::process::Command;
use which::which;
fn main() -> Result<()> {
// Tell Cargo to rerun this build script if the source changes
println!("cargo:rerun-if-changed=embed/src");
println!("cargo:rerun-if-changed=embed/embed.html");
println!("cargo:rerun-if-changed=web/src");
println!("cargo:rerun-if-changed=web/static");
println!("cargo:rerun-if-changed=web/index.html");
// Check if required external tools are available
if which("yarn").is_err() {
return Err(format_err!(
"yarn not found in PATH (it is required to build the web application)"
));
}
// Build embeddable views
yarn(&["--cwd", "embed", "install"])?;
yarn(&["--cwd", "embed", "build"])?;
// Build web application
yarn(&["--cwd", "web", "install"])?;
yarn(&["--cwd", "web", "build"])?;
Ok(())
}
/// Run yarn command with the provided arguments.
fn yarn(args: &[&str]) -> Result<()> {
// Setup command based on the target OS
let mut cmd;
if cfg!(target_os = "windows") {
cmd = Command::new("cmd");
cmd.args(["/C", "yarn"]);
} else {
cmd = Command::new("yarn");
}
cmd.args(args);
// Run command and check output
let output = cmd.output()?;
if !output.status.success() {
return Err(format_err!(
"\n\n> {cmd:?} (stderr)\n{}\n> {cmd:?} (stdout)\n{}\n",
String::from_utf8(output.stderr)?,
String::from_utf8(output.stdout)?
));
}
Ok(())
}