This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.rs
195 lines (163 loc) · 5.86 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use bindgen::{
callbacks::{EnumVariantValue, ParseCallbacks},
Builder, CargoCallbacks,
};
use cmake::Config;
use std::{env, path::PathBuf, process::Command};
#[derive(Debug)]
struct CustomPrefixCallbacks;
impl ParseCallbacks for CustomPrefixCallbacks {
fn enum_variant_name(
&self,
_enum_name: Option<&str>,
original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<String> {
Some(String::from("__") + original_variant_name)
}
fn include_file(&self, filename: &str) {
CargoCallbacks::include_file(&CargoCallbacks, filename)
}
}
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut target_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
// @TODO What about cases where there is a custom target dir?
target_dir.push("target");
let path = PathBuf::from(out_dir);
println!("cargo:rustc-link-arg-bins=-Wl,--dynamic-list=scripts/dynamic_list_for_ld.txt");
Config::new(".")
.define("CMAKE_BUILD_TYPE", "Release")
.define("CMAKE_INSTALL_PREFIX", target_dir)
.build();
cc::Build::new()
.file("src/cpuid_loop.S")
.compile("cpuid_loop");
println!("cargo:rerun-if-changed=src/cpuid_loop.S");
cc::Build::new().file("src/rdtsc.c").compile("rdtsc");
println!("cargo:rerun-if-changed=src/rdtsc.c");
cc::Build::new().file("src/ioctl.c").compile("ioctl");
println!("cargo:rerun-if-changed=src/ioctl.c");
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_consts_x64_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_consts_x86_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_const_asserts_x86_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_const_asserts_x64_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_record_case_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("assembly_templates_generated.rs"))
.status()
.unwrap();
// These are typically not needed. Uncomment and use when necessary e.g. there are new syscalls
/*
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_consts_trait_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_consts_trait_impl_x86_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_consts_trait_impl_x64_generated.rs"))
.status()
.unwrap();
*/
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_name_arch_x64_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_name_arch_x86_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("syscall_helper_functions_generated.rs"))
.status()
.unwrap();
Command::new("scripts/generate_syscalls.py")
.arg(path.join("check_syscall_numbers_generated.rs"))
.status()
.unwrap();
println!("cargo:rerun-if-changed=scripts/generate_syscalls.py");
println!("cargo:rerun-if-changed=scripts/assembly_templates.py");
println!("cargo:rerun-if-changed=scripts/syscalls.py");
let perf_event_bindings = Builder::default()
.parse_callbacks(Box::new(CargoCallbacks))
.derive_default(true)
.prepend_enum_name(false)
.header("bindgen/perf_event_wrapper.h")
.generate()
.unwrap();
println!("cargo:rerun-if-changed=bindgen/perf_event_wrapper.h");
perf_event_bindings
.write_to_file(path.join("perf_event_bindings_generated.rs"))
.unwrap();
let kernel_abi_bindings = Builder::default()
.parse_callbacks(Box::new(CargoCallbacks))
.derive_default(true)
.prepend_enum_name(false)
.header("bindgen/kernel_wrapper.h")
.generate()
.unwrap();
println!("cargo:rerun-if-changed=bindgen/kernel_wrapper.h");
kernel_abi_bindings
.write_to_file(path.join("kernel_bindings_generated.rs"))
.unwrap();
let gdb_register_bindings = Builder::default()
.parse_callbacks(Box::new(CustomPrefixCallbacks))
.prepend_enum_name(false)
.header("bindgen/gdb_register_wrapper.h")
.generate()
.unwrap();
println!("cargo:rerun-if-changed=bindgen/gdb_register_wrapper.h");
gdb_register_bindings
.write_to_file(path.join("gdb_register_bindings_generated.rs"))
.unwrap();
let names = [
"signal",
"audit",
"fcntl",
"ptrace",
"sysexits",
"prctl",
"gdb_request",
"kernel_supplement",
"packet",
"personality",
"thread_db",
"misc_for_ioctl",
];
for &name in &names {
let bindings = Builder::default()
.parse_callbacks(Box::new(CargoCallbacks))
.header(format!("bindgen/{}_wrapper.h", name))
.prepend_enum_name(false)
.derive_default(true)
.generate()
.unwrap();
println!("cargo:rerun-if-changed=bindgen/{}_wrapper.h", name);
bindings
.write_to_file(path.join(format!("{}_bindings_generated.rs", name)))
.unwrap();
}
capnpc::CompilerCommand::new()
.file("schema/trace.capnp")
.run()
.unwrap();
println!("cargo:rerun-if-changed=schema/trace.capnp");
}