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
//!
//! The zkEVM LLVM builder constants.
//!

use std::path::PathBuf;

///
/// The LLVM path resolver.
///
pub struct LLVMPath {}

impl LLVMPath {
    /// The LLVM source directory.
    pub const DIRECTORY_LLVM_SOURCE: &str = "./llvm/";

    /// The LLVM target directory.
    pub const DIRECTORY_LLVM_TARGET: &str = "./target-llvm/";

    ///
    /// Returns the path to the `llvm` LLVM source module directory.
    ///
    pub fn llvm_module_llvm() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_SOURCE);
        path.push("llvm");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the MUSL build directory.
    ///
    pub fn musl_build(source_directory: &str) -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push(source_directory);
        path.push("build");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM CRT build directory.
    ///
    pub fn llvm_build_crt() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("build-crt");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM host build directory.
    ///
    pub fn llvm_build_host() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("build-host");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM final build directory.
    ///
    pub fn llvm_build_final() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("build-final");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the MUSL target directory.
    ///
    pub fn musl_target() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("target-musl");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM CRT target directory.
    ///
    pub fn llvm_target_crt() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("target-crt");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM host target directory.
    ///
    pub fn llvm_target_host() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("target-host");
        crate::utils::absolute_path(path)
    }

    ///
    /// Returns the path to the LLVM final target directory.
    ///
    pub fn llvm_target_final() -> anyhow::Result<PathBuf> {
        let mut path = PathBuf::from(Self::DIRECTORY_LLVM_TARGET);
        path.push("target-final");
        crate::utils::absolute_path(path)
    }
}