compiler_llvm_builder/
llvm_path.rs

1//!
2//! The ZKsync LLVM builder constants.
3//!
4
5use std::path::PathBuf;
6
7///
8/// The LLVM path resolver.
9///
10pub struct LLVMPath {}
11
12impl LLVMPath {
13    /// The LLVM host source directory for stage 1 of multistage MUSL builds.
14    pub const DIRECTORY_LLVM_HOST_SOURCE: &'static str = "./llvm-host/";
15
16    /// The LLVM source directory.
17    pub const DIRECTORY_LLVM_SOURCE: &'static str = "./llvm/";
18
19    /// The LLVM target directory.
20    pub const DIRECTORY_LLVM_TARGET: &'static str = "./target-llvm/";
21
22    ///
23    /// Returns the path to the `llvm` stage 1 host LLVM source module directory.
24    ///
25    pub fn llvm_host_module_llvm() -> anyhow::Result<PathBuf> {
26        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_HOST_SOURCE);
27        path.push("llvm");
28        crate::utils::absolute_path(path)
29    }
30
31    ///
32    /// Returns the path to the `llvm` LLVM source module directory.
33    ///
34    pub fn llvm_module_llvm() -> anyhow::Result<PathBuf> {
35        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
36        path.push("llvm");
37        crate::utils::absolute_path(path)
38    }
39
40    ///
41    /// Returns the path to the MUSL source.
42    ///
43    pub fn musl_source(name: &str) -> anyhow::Result<PathBuf> {
44        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
45        path.push(name);
46        crate::utils::absolute_path(path)
47    }
48
49    ///
50    /// Returns the path to the MUSL build directory.
51    ///
52    pub fn musl_build(source_directory: &str) -> anyhow::Result<PathBuf> {
53        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
54        path.push(source_directory);
55        path.push("build");
56        crate::utils::absolute_path(path)
57    }
58
59    ///
60    /// Returns the path to the LLVM CRT build directory.
61    ///
62    pub fn llvm_build_crt() -> anyhow::Result<PathBuf> {
63        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
64        path.push("build-crt");
65        crate::utils::absolute_path(path)
66    }
67
68    ///
69    /// Returns the path to the LLVM host build directory.
70    ///
71    pub fn llvm_build_host() -> anyhow::Result<PathBuf> {
72        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
73        path.push("build-host");
74        crate::utils::absolute_path(path)
75    }
76
77    ///
78    /// Returns the path to the LLVM final build directory.
79    ///
80    pub fn llvm_build_final() -> anyhow::Result<PathBuf> {
81        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
82        path.push("build-final");
83        crate::utils::absolute_path(path)
84    }
85
86    ///
87    /// Returns the path to the MUSL target directory.
88    ///
89    pub fn musl_target() -> anyhow::Result<PathBuf> {
90        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
91        path.push("target-musl");
92        crate::utils::absolute_path(path)
93    }
94
95    ///
96    /// Returns the path to the LLVM CRT target directory.
97    ///
98    pub fn llvm_target_crt() -> anyhow::Result<PathBuf> {
99        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
100        path.push("target-crt");
101        crate::utils::absolute_path(path)
102    }
103
104    ///
105    /// Returns the path to the LLVM host target directory.
106    ///
107    pub fn llvm_target_host() -> anyhow::Result<PathBuf> {
108        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
109        path.push("target-host");
110        crate::utils::absolute_path(path)
111    }
112
113    ///
114    /// Returns the path to the LLVM final target directory.
115    ///
116    pub fn llvm_target_final() -> anyhow::Result<PathBuf> {
117        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
118        path.push("target-final");
119        crate::utils::absolute_path(path)
120    }
121}