revive_build_utils/
lib.rs1pub const REVIVE_LLVM_HOST_PREFIX: &str = "LLVM_SYS_211_PREFIX";
5
6pub const REVIVE_LLVM_TARGET_PREFIX: &str = "REVIVE_LLVM_TARGET_PREFIX";
8
9pub const REVIVE_LLVM_BUILDER_HELP_LINK: &str =
11 "https://github.com/paritytech/revive?tab=readme-ov-file#building-from-source";
12
13pub fn llvm_host_tool(name: &str) -> std::path::PathBuf {
17 std::env::var_os(REVIVE_LLVM_HOST_PREFIX)
18 .map(Into::<std::path::PathBuf>::into)
19 .unwrap_or_else(|| {
20 panic!("install LLVM using the revive-llvm builder and export '{REVIVE_LLVM_HOST_PREFIX}'; see also: {REVIVE_LLVM_BUILDER_HELP_LINK}")
21 })
22 .join("bin")
23 .join(name)
24}
25
26pub fn llvm_lib_dir() -> std::path::PathBuf {
30 std::path::PathBuf::from(llvm_config("--libdir").trim())
31}
32
33pub fn llvm_cxx_flags() -> String {
37 llvm_config("--cxxflags")
38}
39
40fn llvm_config(arg: &str) -> String {
42 let llvm_config = llvm_host_tool("llvm-config");
43 let output = std::process::Command::new(&llvm_config)
44 .arg(arg)
45 .output()
46 .unwrap_or_else(|error| panic!("`{} {arg}` failed: {error}", llvm_config.display()));
47
48 String::from_utf8(output.stdout)
49 .unwrap_or_else(|_| panic!("output of `{} {arg}` should be utf8", llvm_config.display()))
50}