Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
82 lines (82 loc) · 2.49 KB
/
Copy pathbuild.rs
File metadata and controls
82 lines (82 loc) · 2.49 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
use std::path::PathBuf;
use std::process::Command;
fn compile(target: Option<&str>, source: &str, output: &std::path::Path, macos: bool) {
let mut build = cc::Build::new();
if let Some(target) = target {
build.target(target);
}
let compiler = build.get_compiler();
let mut command = compiler.to_command();
command.args([
"-fPIC",
"-O2",
"-g",
"-fno-omit-frame-pointer",
"-Wall",
"-Wextra",
"-Werror",
]);
if macos {
command.arg("-dynamiclib");
} else {
command.args(["-shared", "-Wl,-z,defs", "-ldl", "-pthread"]);
}
let status = command
.arg(source)
.arg("-o")
.arg(output)
.status()
.expect("launching heap helper compiler");
assert!(status.success(), "building native heap helper");
}
fn main() {
println!("cargo:rerun-if-changed=src/heap/recorder.c");
println!("cargo:rerun-if-changed=src/heap/finalizer.c");
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
let directory = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
if os == "macos" {
// Each CLI architecture can launch either kind of macOS target.
let arm = directory.join("finalizer-arm64.dylib");
let intel = directory.join("finalizer-x86_64.dylib");
let output = directory.join("libpprofessor_finalizer.dylib");
compile(
Some("aarch64-apple-darwin"),
"src/heap/finalizer.c",
&arm,
true,
);
compile(
Some("x86_64-apple-darwin"),
"src/heap/finalizer.c",
&intel,
true,
);
assert!(
Command::new("/usr/bin/lipo")
.arg("-create")
.arg(arm)
.arg(intel)
.arg("-output")
.arg(&output)
.status()
.expect("creating universal heap finalizer")
.success()
);
assert!(
Command::new("/usr/bin/codesign")
.args(["--force", "--sign", "-"])
.arg(output)
.status()
.expect("signing heap finalizer")
.success()
);
} else if os == "linux" && env == "gnu" {
compile(
None,
"src/heap/recorder.c",
&directory.join("libpprofessor_heap.so"),
false,
);
}
}