-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
78 lines (67 loc) · 2.17 KB
/
Copy pathbuild.rs
File metadata and controls
78 lines (67 loc) · 2.17 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
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=inject/kpc_inject.c");
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
if target_os != "macos" || target_arch != "aarch64" {
panic!(
"apmc only supports macOS on Apple Silicon (aarch64). \
Current target: {target_os}/{target_arch}"
);
}
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let dylib_path = out_dir.join("libkpc_inject.dylib");
// Map the Rust build profile to C compiler optimization flags.
let opt_flag = match env::var("PROFILE").as_deref() {
Ok("release") => "-O2",
_ => "-O0",
};
let mut cc = Command::new("cc");
cc.args([
"-dynamiclib",
opt_flag,
"-Wall",
"-Wpedantic",
"-Werror",
"-o",
dylib_path.to_str().unwrap(),
"inject/kpc_inject.c",
"-lpthread",
]);
// Include debug symbols in debug builds.
if env::var("PROFILE").as_deref() != Ok("release") {
cc.arg("-g");
}
let status = cc
.status()
.expect("failed to invoke cc — is Xcode or CommandLineTools installed?");
assert!(
status.success(),
"failed to compile inject/kpc_inject.c into dylib"
);
println!("cargo:rustc-env=KPC_INJECT_DYLIB={}", dylib_path.display());
// Build the C region mode example.
println!("cargo:rerun-if-changed=examples/region_test.c");
let example_path = out_dir.join("region_test_c");
let mut cc_example = Command::new("cc");
cc_example.args([
opt_flag,
"-Wall",
"-Wpedantic",
"-Werror",
"-I",
"include",
"-o",
example_path.to_str().unwrap(),
"examples/region_test.c",
]);
if env::var("PROFILE").as_deref() != Ok("release") {
cc_example.arg("-g");
}
let status = cc_example
.status()
.expect("failed to compile examples/region_test.c");
assert!(status.success(), "failed to compile examples/region_test.c");
}