Actually use sccache and fix build with older Rust

This commit is contained in:
Andrzej Janik
2025-07-03 01:30:37 +00:00
parent f6979e5a3b
commit dbbc5e20b5
2 changed files with 18 additions and 2 deletions

View File

@ -14,6 +14,7 @@ const COMPONENTS: &[&'static str] = &[
fn main() {
let mut cmake = Config::new(r"../ext/llvm-project/llvm");
try_use_sccache(&mut cmake);
try_use_ninja(&mut cmake);
cmake
// It's not like we can do anything about the warnings
@ -52,6 +53,21 @@ fn main() {
compile_cxx_lib(cxxflags);
}
// https://github.com/mozilla/sccache/blob/main/README.md#usage
fn try_use_sccache(cmake: &mut Config) {
if let Ok(sccache) = std::env::var("SCCACHE_PATH") {
cmake.define("CMAKE_CXX_COMPILER_LAUNCHER", &*sccache);
cmake.define("CMAKE_C_COMPILER_LAUNCHER", &*sccache);
match std::env::var_os("CARGO_CFG_TARGET_OS") {
Some(os) if os == "windows" => {
cmake.define("CMAKE_MSVC_DEBUG_INFORMATION_FORMAT", "Embedded");
cmake.define("CMAKE_POLICY_CMP0141", "NEW");
}
_ => {}
}
}
}
fn try_use_ninja(cmake: &mut Config) {
let mut cmd = Command::new("ninja");
cmd.arg("--version");

View File

@ -26,7 +26,7 @@ fn get_ptx_from_wrapped_fatbin(image: *const ::core::ffi::c_void) -> Result<Vec<
let fatbin = Fatbin::new(&image).map_err(|_| CUerror::UNKNOWN)?;
let mut submodules = fatbin.get_submodules().map_err(|_| CUerror::UNKNOWN)?;
while let Some(current) = unsafe { submodules.next().map_err(|_| CUerror::UNKNOWN)? } {
while let Some(current) = unsafe { submodules.next().map_err(|_| CUerror::UNKNOWN)? } {
let mut files = current.get_files();
while let Some(file) = unsafe { files.next().map_err(|_| CUerror::UNKNOWN)? } {
if file.header.kind == FatbinFileHeader::HEADER_KIND_PTX {
@ -47,7 +47,7 @@ fn get_ptx(image: *const ::core::ffi::c_void) -> Result<String, CUerror> {
let ptx = if unsafe { *(image as *const u32) } == FatbincWrapper::MAGIC {
let ptx_bytes = get_ptx_from_wrapped_fatbin(image)?;
str::from_utf8(&ptx_bytes)
std::str::from_utf8(&ptx_bytes)
.map_err(|_| CUerror::UNKNOWN)?
.to_owned()
} else {