compiler_llvm_builder/platforms/
x86_64_windows_gnu.rs1use std::collections::HashSet;
6use std::path::PathBuf;
7use std::process::Command;
8
9use crate::build_type::BuildType;
10use crate::ccache_variant::CcacheVariant;
11use crate::llvm_path::LLVMPath;
12use crate::llvm_project::LLVMProject;
13use crate::platforms::Platform;
14use crate::sanitizer::Sanitizer;
15use crate::target_triple::TargetTriple;
16
17#[allow(clippy::too_many_arguments)]
21pub fn build(
22 build_type: BuildType,
23 targets: HashSet<Platform>,
24 llvm_projects: HashSet<LLVMProject>,
25 enable_rtti: bool,
26 default_target: Option<TargetTriple>,
27 enable_tests: bool,
28 enable_coverage: bool,
29 extra_args: Vec<String>,
30 ccache_variant: Option<CcacheVariant>,
31 enable_assertions: bool,
32 sanitizer: Option<Sanitizer>,
33) -> anyhow::Result<()> {
34 crate::utils::exists("cmake")?;
35 crate::utils::exists("clang")?;
36 crate::utils::exists("clang++")?;
37 crate::utils::exists("lld")?;
38 crate::utils::exists("ninja")?;
39
40 let llvm_module_llvm =
41 LLVMPath::llvm_module_llvm().and_then(crate::utils::path_windows_to_unix)?;
42 let llvm_build_final =
43 LLVMPath::llvm_build_final().and_then(crate::utils::path_windows_to_unix)?;
44 let llvm_target_final =
45 LLVMPath::llvm_target_final().and_then(crate::utils::path_windows_to_unix)?;
46
47 crate::utils::command(
48 Command::new("cmake")
49 .args([
50 "-S",
51 llvm_module_llvm.to_string_lossy().as_ref(),
52 "-B",
53 llvm_build_final.to_string_lossy().as_ref(),
54 "-G",
55 "Ninja",
56 format!(
57 "-DCMAKE_INSTALL_PREFIX='{}'",
58 llvm_target_final.to_string_lossy().as_ref(),
59 )
60 .as_str(),
61 format!("-DCMAKE_BUILD_TYPE='{build_type}'").as_str(),
62 "-DCMAKE_C_COMPILER='clang'",
63 "-DCMAKE_CXX_COMPILER='clang++'",
64 format!(
65 "-DLLVM_TARGETS_TO_BUILD='{}'",
66 targets
67 .into_iter()
68 .map(|platform| platform.to_string())
69 .collect::<Vec<String>>()
70 .join(";")
71 )
72 .as_str(),
73 format!(
74 "-DLLVM_ENABLE_PROJECTS='{}'",
75 llvm_projects
76 .into_iter()
77 .map(|project| project.to_string())
78 .collect::<Vec<String>>()
79 .join(";")
80 )
81 .as_str(),
82 "-DLLVM_USE_LINKER='lld'",
83 ])
84 .args(crate::platforms::shared::shared_build_opts_default_target(
85 default_target,
86 ))
87 .args(crate::platforms::shared::shared_build_opts_tests(
88 enable_tests,
89 ))
90 .args(crate::platforms::shared::shared_build_opts_coverage(
91 enable_coverage,
92 ))
93 .args(crate::platforms::shared::SHARED_BUILD_OPTS)
94 .args(crate::platforms::shared::SHARED_BUILD_OPTS_NOT_MUSL)
95 .args(crate::platforms::shared::shared_build_opts_werror())
96 .args(extra_args)
97 .args(crate::platforms::shared::shared_build_opts_ccache(
98 ccache_variant,
99 ))
100 .args(crate::platforms::shared::shared_build_opts_assertions(
101 enable_assertions,
102 ))
103 .args(crate::platforms::shared::shared_build_opts_rtti(
104 enable_rtti,
105 ))
106 .args(crate::platforms::shared::shared_build_opts_sanitizers(
107 sanitizer,
108 )),
109 "LLVM building cmake",
110 )?;
111
112 crate::utils::ninja(llvm_build_final.as_ref())?;
113
114 let libstdcpp_source_path = match std::env::var("LIBSTDCPP_SOURCE_PATH") {
115 Ok(libstdcpp_source_path) => PathBuf::from(libstdcpp_source_path),
116 Err(error) => anyhow::bail!(
117 "The `LIBSTDCPP_SOURCE_PATH` must be set to the path to the libstdc++.a static library: {error}"
118 ),
119 };
120 let mut libstdcpp_destination_path = llvm_target_final;
121 libstdcpp_destination_path.push("./lib/libstdc++.a");
122 fs_extra::file::copy(
123 crate::utils::path_windows_to_unix(libstdcpp_source_path)?,
124 crate::utils::path_windows_to_unix(libstdcpp_destination_path)?,
125 &fs_extra::file::CopyOptions::default(),
126 )?;
127
128 Ok(())
129}