forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
55 lines (49 loc) · 1.95 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
54
55
// Automatically generate README.md from rustdoc.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process;
fn main() {
// The code below emits `cfg` operators to conditionally compile this program based on the
// current variant.
// TODO: Replace this approach when the build system supports ideas like "variant
// tags": https://github.com/bottlerocket-os/bottlerocket/issues/1260
println!("cargo:rerun-if-env-changed=VARIANT");
if let Ok(variant) = env::var("VARIANT") {
if variant.starts_with("aws") {
println!("cargo:rustc-cfg=bottlerocket_platform=\"aws\"");
} else if variant.starts_with("vmware") {
println!("cargo:rustc-cfg=bottlerocket_platform=\"vmware\"");
} else if variant.starts_with("metal") {
println!("cargo:rustc-cfg=bottlerocket_platform=\"metal\"");
} else {
eprintln!(
"For local builds, you must set the 'VARIANT' environment variable so we know which data \
provider to build. Valid values are the directories in models/src/variants/, for \
example 'aws-ecs-1'."
);
process::exit(1);
}
}
// Check for environment variable "SKIP_README". If it is set,
// skip README generation
if env::var_os("SKIP_README").is_some() {
return;
}
let mut source = File::open("src/main.rs").unwrap();
let mut template = File::open("README.tpl").unwrap();
let content = cargo_readme::generate_readme(
&PathBuf::from("."), // root
&mut source, // source
Some(&mut template), // template
// The "add x" arguments don't apply when using a template.
true, // add title
false, // add badges
false, // add license
true, // indent headings
)
.unwrap();
let mut readme = File::create("README.md").unwrap();
readme.write_all(content.as_bytes()).unwrap();
}