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
pub mod build_type;
pub mod llvm_path;
pub mod lock;
pub mod platforms;
pub mod utils;
pub use self::build_type::BuildType;
pub use self::llvm_path::LLVMPath;
pub use self::lock::Lock;
use std::path::PathBuf;
use std::process::Command;
pub fn clone(lock: Lock) -> anyhow::Result<()> {
utils::check_presence("git")?;
let destination_path = PathBuf::from(LLVMPath::DIRECTORY_LLVM_SOURCE);
if destination_path.exists() {
anyhow::bail!(
"The repository is already cloned at {:?}. Use `checkout` instead",
destination_path
);
}
utils::command(
Command::new("git").args([
"clone",
"--branch",
lock.branch.as_str(),
lock.url.as_str(),
destination_path.to_string_lossy().as_ref(),
]),
"LLVM repository cloning",
)?;
if let Some(r#ref) = lock.r#ref {
utils::command(
Command::new("git").args(["checkout", r#ref.as_str()]),
"LLVM repository commit checking out",
)?;
}
Ok(())
}
pub fn checkout(lock: Lock, force: bool) -> anyhow::Result<()> {
let destination_path = PathBuf::from(LLVMPath::DIRECTORY_LLVM_SOURCE);
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["fetch", "--all", "--tags"]),
"LLVM repository data fetching",
)?;
if force {
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["clean", "-d", "-x", "--force"]),
"LLVM repository cleaning",
)?;
}
utils::command(
Command::new("git")
.current_dir(destination_path.as_path())
.args(["checkout", "--force", lock.branch.as_str()]),
"LLVM repository data pulling",
)?;
if let Some(r#ref) = lock.r#ref {
let mut checkout_command = Command::new("git");
checkout_command.current_dir(destination_path.as_path());
checkout_command.arg("checkout");
if force {
checkout_command.arg("--force");
}
checkout_command.arg(r#ref);
utils::command(&mut checkout_command, "LLVM repository checking out")?;
}
Ok(())
}
pub fn build(build_type: BuildType, enable_tests: bool) -> anyhow::Result<()> {
std::fs::create_dir_all(LLVMPath::DIRECTORY_LLVM_TARGET)?;
if cfg!(target_arch = "x86_64") {
if cfg!(target_os = "linux") {
if cfg!(target_env = "gnu") {
platforms::x86_64_linux_gnu::build(build_type, enable_tests)?;
} else if cfg!(target_env = "musl") {
platforms::x86_64_linux_musl::build(build_type, enable_tests)?;
}
} else if cfg!(target_os = "macos") {
platforms::x86_64_macos::build(build_type, enable_tests)?;
} else if cfg!(target_os = "windows") && cfg!(target_env = "gnu") {
platforms::x86_64_windows_gnu::build(build_type, enable_tests)?;
}
} else if cfg!(target_arch = "aarch64") {
if cfg!(target_os = "macos") {
platforms::aarch64_macos::build(build_type, enable_tests)?;
}
} else {
anyhow::bail!("Unsupported on your machine");
}
Ok(())
}
pub fn clean() -> anyhow::Result<()> {
Ok(std::fs::remove_dir_all(PathBuf::from(
LLVMPath::DIRECTORY_LLVM_TARGET,
))?)
}