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 const DIRECTORY_PATCHES: &'static str = "./patches/llvm/";
25
26 pub fn llvm_host_module_llvm() -> anyhow::Result<PathBuf> {
28 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_HOST_SOURCE);
29 path.push("llvm");
30 crate::utils::absolute_path(path).inspect(|absolute_path| {
31 log::debug!(
32 "llvm stage 1 host llvm source module: {}",
33 absolute_path.display()
34 )
35 })
36 }
37
38 pub fn llvm_module_llvm() -> anyhow::Result<PathBuf> {
40 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
41 path.push("llvm");
42 crate::utils::absolute_path(path)
43 .inspect(|absolute_path| log::debug!("llvm source module: {}", absolute_path.display()))
44 }
45
46 pub fn musl_source(name: &str) -> anyhow::Result<PathBuf> {
48 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
49 path.push(name);
50 crate::utils::absolute_path(path)
51 .inspect(|absolute_path| log::debug!("musl source: {}", absolute_path.display()))
52 }
53
54 pub fn musl_build(source_directory: &str) -> anyhow::Result<PathBuf> {
56 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
57 path.push(source_directory);
58 path.push("build");
59 crate::utils::absolute_path(path)
60 .inspect(|absolute_path| log::debug!("musl build: '{}'", absolute_path.display()))
61 }
62
63 pub fn llvm_build_crt() -> anyhow::Result<PathBuf> {
65 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
66 path.push("build-crt");
67 crate::utils::absolute_path(path)
68 .inspect(|absolute_path| log::debug!("llvm build crt: {}", absolute_path.display()))
69 }
70
71 pub fn llvm_build_host() -> anyhow::Result<PathBuf> {
73 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
74 path.push("build-host");
75 crate::utils::absolute_path(path)
76 .inspect(|absolute_path| log::debug!("llvm build host: {}", absolute_path.display()))
77 }
78
79 pub fn llvm_build_final() -> anyhow::Result<PathBuf> {
81 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
82 path.push("build-final");
83 crate::utils::absolute_path(path)
84 .inspect(|absolute_path| log::debug!("llvm build final: {}", absolute_path.display()))
85 }
86
87 pub fn musl_target() -> anyhow::Result<PathBuf> {
89 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
90 path.push("target-musl");
91 crate::utils::absolute_path(path)
92 .inspect(|absolute_path| log::debug!("musl target: {}", absolute_path.display()))
93 }
94
95 pub fn llvm_target_crt() -> anyhow::Result<PathBuf> {
97 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
98 path.push("target-crt");
99 crate::utils::absolute_path(path)
100 .inspect(|absolute_path| log::debug!("llvm crt target: {}", absolute_path.display()))
101 }
102
103 pub fn llvm_target_host() -> anyhow::Result<PathBuf> {
105 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
106 path.push("target-host");
107 crate::utils::absolute_path(path)
108 .inspect(|absolute_path| log::debug!("llvm host target: {}", absolute_path.display()))
109 }
110
111 pub fn llvm_target_final() -> anyhow::Result<PathBuf> {
113 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
114 path.push("target-final");
115 crate::utils::absolute_path(path)
116 .inspect(|absolute_path| log::debug!("llvm final target: {}", absolute_path.display()))
117 }
118
119 pub fn llvm_module_compiler_rt() -> anyhow::Result<PathBuf> {
121 let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
122 path.push("compiler-rt");
123 crate::utils::absolute_path(path).inspect(|absolute_path| {
124 log::debug!("compiler-rt source dir: {}", absolute_path.display())
125 })
126 }
127
128 pub fn llvm_target_compiler_rt() -> anyhow::Result<PathBuf> {
130 Self::llvm_target_final()
131 }
132
133 pub fn llvm_build_compiler_rt() -> anyhow::Result<PathBuf> {
135 let mut path = PathBuf::from(DIRECTORY_LLVM_TARGET.get().unwrap());
136 path.push("build-compiler-rt");
137 crate::utils::absolute_path(path).inspect(|absolute_path| {
138 log::debug!("llvm compiler-rt build: {}", absolute_path.display())
139 })
140 }
141
142 pub fn llvm_target_final_bin(
145 target_env: crate::target_env::TargetEnv,
146 ) -> anyhow::Result<PathBuf> {
147 let mut path = Self::llvm_target_final()?;
148 path.push("bin");
149 path.push(format!("{target_env}"));
150 crate::utils::absolute_path(path).inspect(|absolute_path| {
151 log::debug!("llvm target final bin: {}", absolute_path.display())
152 })
153 }
154}