forked from tgstation/rust-g
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
42 lines (36 loc) · 1.25 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
//! Buildscript which will save a `rust_g.dm` with the DLL's public API.
use std::{fs::File, io::Write};
macro_rules! feature_dm_file {
($name:expr) => {
&"dmsrc/{}.dm".replace("{}", $name)
};
}
macro_rules! feature_dm_exists {
($name:expr) => {
std::path::Path::new(feature_dm_file!($name)).exists()
};
}
fn main() {
let mut f = File::create("target/rust_g.dm").unwrap();
// header
writeln!(
f,
"{}",
std::fs::read_to_string(feature_dm_file!("main")).unwrap()
)
.unwrap();
for (key, _value) in std::env::vars() {
// CARGO_FEATURE_<name> — For each activated feature of the package being built, this environment variable will be present where <name> is the name of the feature uppercased and having - translated to _.
if let Some(uprfeature) = key.strip_prefix("CARGO_FEATURE_") {
let feature = uprfeature.to_lowercase().replace('_', "-"); // actual proper name of the enabled feature
if feature_dm_exists!(&feature) {
writeln!(
f,
"{}",
std::fs::read_to_string(feature_dm_file!(&feature)).unwrap()
)
.unwrap();
}
}
}
}