revive_llvm_builder/
llvm_path.rs1use std::path::PathBuf;
4use std::sync::OnceLock;
5
6pub static DIRECTORY_LLVM_TARGET: OnceLock<PathBuf> = OnceLock::new();
7
8pub struct LLVMPath {}
10
11impl LLVMPath {
12 pub const DIRECTORY_LLVM_SOURCE: &'static str = "./llvm/";
14
15 pub const DIRECTORY_LLVM_HOST_SOURCE: &'static str = Self::DIRECTORY_LLVM_SOURCE;
19
20 pub const DIRECTORY_EMSDK_SOURCE: &'static str = "./emsdk/";
22
23 pub fn llvm_host_module_llvm() -> anyhow::Result<PathBuf> {
25 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_HOST_SOURCE);
26 path.push("llvm");
27 crate::utils::absolute_path(path).inspect(|absolute_path| {
28 log::debug!(
29 "llvm stage 1 host llvm source module: {}",
30 absolute_path.display()
31 )
32 })
33 }
34
35 pub fn llvm_module_llvm() -> anyhow::Result<PathBuf> {
37 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
38 path.push("llvm");
39 crate::utils::absolute_path(path)
40 .inspect(|absolute_path| log::debug!("llvm source module: {}", absolute_path.display()))
41 }
42
43 pub fn musl_source(name: &str) -> anyhow::Result<PathBuf> {
45 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
46 path.push(name);
47 crate::utils::absolute_path(path)
48 .inspect(|absolute_path| log::debug!("musl source: {}", absolute_path.display()))
49 }
50
51 pub fn musl_build(source_directory: &str) -> anyhow::Result<PathBuf> {
53 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
54 path.push(source_directory);
55 path.push("build");
56 crate::utils::absolute_path(path)
57 .inspect(|absolute_path| log::debug!("musl build: '{}'", absolute_path.display()))
58 }
59
60 pub fn llvm_build_crt() -> anyhow::Result<PathBuf> {
62 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
63 path.push("build-crt");
64 crate::utils::absolute_path(path)
65 .inspect(|absolute_path| log::debug!("llvm build crt: {}", absolute_path.display()))
66 }
67
68 pub fn llvm_build_host() -> anyhow::Result<PathBuf> {
70 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
71 path.push("build-host");
72 crate::utils::absolute_path(path)
73 .inspect(|absolute_path| log::debug!("llvm build host: {}", absolute_path.display()))
74 }
75
76 pub fn llvm_build_final() -> anyhow::Result<PathBuf> {
78 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
79 path.push("build-final");
80 crate::utils::absolute_path(path)
81 .inspect(|absolute_path| log::debug!("llvm build final: {}", absolute_path.display()))
82 }
83
84 pub fn musl_target() -> anyhow::Result<PathBuf> {
86 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
87 path.push("target-musl");
88 crate::utils::absolute_path(path)
89 .inspect(|absolute_path| log::debug!("musl target: {}", absolute_path.display()))
90 }
91
92 pub fn llvm_target_crt() -> anyhow::Result<PathBuf> {
94 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
95 path.push("target-crt");
96 crate::utils::absolute_path(path)
97 .inspect(|absolute_path| log::debug!("llvm crt target: {}", absolute_path.display()))
98 }
99
100 pub fn llvm_target_host() -> anyhow::Result<PathBuf> {
102 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
103 path.push("target-host");
104 crate::utils::absolute_path(path)
105 .inspect(|absolute_path| log::debug!("llvm host target: {}", absolute_path.display()))
106 }
107
108 pub fn llvm_target_final() -> anyhow::Result<PathBuf> {
110 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
111 path.push("target-final");
112 crate::utils::absolute_path(path)
113 .inspect(|absolute_path| log::debug!("llvm final target: {}", absolute_path.display()))
114 }
115
116 pub fn llvm_module_compiler_rt() -> anyhow::Result<PathBuf> {
118 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
119 path.push("compiler-rt");
120 crate::utils::absolute_path(path).inspect(|absolute_path| {
121 log::debug!("compiler-rt source dir: {}", absolute_path.display())
122 })
123 }
124
125 pub fn llvm_target_compiler_rt() -> anyhow::Result<PathBuf> {
127 Self::llvm_target_final()
128 }
129
130 pub fn llvm_build_compiler_rt() -> anyhow::Result<PathBuf> {
132 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
133 path.push("build-compiler-rt");
134 crate::utils::absolute_path(path).inspect(|absolute_path| {
135 log::debug!("llvm compiler-rt build: {}", absolute_path.display())
136 })
137 }
138
139 pub fn llvm_target_final_bin(
142 target_env: crate::target_env::TargetEnv,
143 ) -> anyhow::Result<PathBuf> {
144 let mut path = Self::llvm_target_final()?;
145 path.push("bin");
146 path.push(format!("{target_env}"));
147 crate::utils::absolute_path(path).inspect(|absolute_path| {
148 log::debug!("llvm target final bin: {}", absolute_path.display())
149 })
150 }
151}