Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo: Use the right LLVM tools and arguments for MSVC cross-compilation #160

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions xbuild/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,14 @@ impl CargoBuild {

pub fn use_windows_sdk(&mut self, path: &Path) -> Result<()> {
let path = dunce::canonicalize(path)?;
self.cfg_tool(Tool::Cc, "clang");
self.cfg_tool(Tool::Cxx, "clang++");
self.cfg_tool(Tool::Cc, "clang-cl");
self.cfg_tool(Tool::Cxx, "clang-cl");
self.cfg_tool(Tool::Ar, "llvm-lib");
self.cfg_tool(Tool::Linker, "rust-lld");
self.use_ld("lld-link");
self.add_target_feature("+crt-static");
self.add_cxxflag("-stdlib=libc++");
self.add_include_dir(&path.join("crt").join("include"));
self.add_include_dir(&path.join("sdk").join("include").join("um"));
self.add_include_dir(&path.join("sdk").join("include").join("ucrt"));
self.add_include_dir(&path.join("sdk").join("include").join("shared"));
self.cfg_tool(Tool::Linker, "rust-lld"); // Rust defaults to link.exe, use its rust-lld binary instead
self.add_msvc_include_dir(&path.join("crt").join("include"));
self.add_msvc_include_dir(&path.join("sdk").join("include").join("um"));
self.add_msvc_include_dir(&path.join("sdk").join("include").join("ucrt"));
self.add_msvc_include_dir(&path.join("sdk").join("include").join("shared"));
self.add_lib_dir(&path.join("crt").join("lib").join("x86_64"));
self.add_lib_dir(&path.join("sdk").join("lib").join("um").join("x86_64"));
self.add_lib_dir(&path.join("sdk").join("lib").join("ucrt").join("x86_64"));
Expand Down Expand Up @@ -439,6 +436,10 @@ impl CargoBuild {
self.c_flags.push_str(&format!("-I{} ", path.display()));
}

pub fn add_msvc_include_dir(&mut self, path: &Path) {
self.c_flags.push_str(&format!("-imsvc{} ", path.display()));
}

pub fn set_sysroot(&mut self, path: &Path) {
let arg = format!("--sysroot={}", path.display());
self.add_cflag(&arg);
Expand Down
Loading