MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / find_llvm_config

Function find_llvm_config

crates/rustc_codegen_nvvm/build.rs:63–120  ·  view source on GitHub ↗
(target: &str)

Source from the content-addressed store, hash-verified

61}
62
63fn find_llvm_config(target: &str) -> PathBuf {
64 // first, if LLVM_CONFIG is set then see if its llvm version if 7.x, if so, use that.
65 let config_env = tracked_env_var_os("LLVM_CONFIG");
66 // if LLVM_CONFIG is not set, try using llvm-config as a normal app in PATH.
67 let path_to_try = config_env.unwrap_or_else(|| "llvm-config".into());
68
69 // if USE_PREBUILT_LLVM is set to 1 then download prebuilt llvm without trying llvm-config
70 if tracked_env_var_os("USE_PREBUILT_LLVM") != Some("1".into()) {
71 let cmd = Command::new(&path_to_try).arg("--version").output();
72
73 if let Ok(out) = cmd {
74 let version = String::from_utf8(out.stdout).unwrap();
75 if version.starts_with(&REQUIRED_MAJOR_LLVM_VERSION.to_string()) {
76 return PathBuf::from(path_to_try);
77 }
78 }
79 }
80
81 // otherwise, download prebuilt LLVM.
82 println!("cargo:warning=Downloading prebuilt LLVM");
83 let mut url = tracked_env_var_os("PREBUILT_LLVM_URL")
84 .map(|x| x.to_string_lossy().to_string())
85 .unwrap_or_else(|| PREBUILT_LLVM_URL.to_string());
86
87 let prebuilt_name = target_to_llvm_prebuilt(target);
88 url = format!("{}{}", url, prebuilt_name);
89
90 let out = env::var("OUT_DIR").expect("OUT_DIR was not set");
91 let mut easy = Easy::new();
92
93 easy.url(&url).unwrap();
94 let _redirect = easy.follow_location(true).unwrap();
95 let mut xz_encoded = Vec::with_capacity(20_000_000); // 20mb
96 {
97 let mut transfer = easy.transfer();
98 transfer
99 .write_function(|data| {
100 xz_encoded.extend_from_slice(data);
101 Ok(data.len())
102 })
103 .expect("Failed to download prebuilt LLVM");
104 transfer
105 .perform()
106 .expect("Failed to download prebuilt LLVM");
107 }
108
109 let decompressor = XzDecoder::new(xz_encoded.as_slice());
110 let mut ar = Archive::new(decompressor);
111
112 ar.unpack(&out).expect("Failed to unpack LLVM to LLVM dir");
113 let out_path = PathBuf::from(out).join(prebuilt_name.strip_suffix(".tar.xz").unwrap());
114
115 println!("cargo:rerun-if-changed={}", out_path.display());
116
117 out_path
118 .join("bin")
119 .join(format!("llvm-config{}", std::env::consts::EXE_SUFFIX))
120}

Callers 1

rustc_llvm_buildFunction · 0.85

Calls 6

tracked_env_var_osFunction · 0.85
newFunction · 0.85
target_to_llvm_prebuiltFunction · 0.85
expectMethod · 0.45
lenMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected