-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rs
More file actions
executable file
·95 lines (77 loc) · 2.21 KB
/
config.rs
File metadata and controls
executable file
·95 lines (77 loc) · 2.21 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//usr/bin/env rustc "$0" && ./config "$@"; exit
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#![feature(iter_intersperse)]
#![allow(non_camel_case_types, unused)]
macro_rules! options {
(
$(
$( #[$doc:meta] )*
$id:ident: $t:ty = $v:expr,
)+
) => {
struct Options {
$(
$( #[$doc] )*
$id: $t,
)+
}
const TYPECHECK: Options = Options {
$( $id: $v, )+
};
const OPTIONS: &[(&str, &str)] = &[
$( (stringify!($id), stringify!($v)), )+
];
}
}
options! {
/// Target architecture
arch: Arch = Arch::x64,
/// Enable graphic framebuffer console in qemu
graphic: bool = true,
/// Enable serial input/output
serial: bool = true,
/// Enable output of trace!() macro
trace: bool = true,
}
enum Arch {
x64,
aarch64,
}
fn main() {
let args = std::env::args().collect::<Vec<String>>();
let strs = args.iter().map(String::as_str).collect::<Vec<&str>>();
match &strs[..] {
[_p, "-m" | "--make"] => output_makefile(),
[_p, "-c" | "--cargo"] => output_cargo_args(),
_ => {
eprintln!("Usage: ./config.rs --make | --cargo");
std::process::exit(1);
}
};
}
fn output_makefile() {
println!("# Autogenerated from config.rs");
for (key, val) in OPTIONS {
let leaf = val.split("::").last().unwrap();
println!("CFG_{} = {}", key.to_uppercase(), leaf);
}
}
fn output_cargo_args() {
let mut flags = vec![];
for (key, val) in OPTIONS {
match *val {
"false" => continue,
"true" => {
flags.push(format!("--cfg={}", key));
}
_ => {
let leaf = val.split("::").last().unwrap();
flags.push(format!("--cfg={}_{}", key, leaf));
}
}
}
let output = flags.into_iter().intersperse("\x1f".to_owned()).collect::<String>();
print!("CARGO_ENCODED_RUSTFLAGS='{}'", output);
}