Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/cc-rs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: rust-lang/cc-rs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: NobodyXu-patch-1
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jan 15, 2025

  1. Copy the full SHA
    c59c072 View commit details
Showing with 21 additions and 4 deletions.
  1. +21 −4 src/lib.rs
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -332,6 +332,7 @@ pub struct Build {
shell_escaped_flags: Option<bool>,
build_cache: Arc<BuildCache>,
inherit_rustflags: bool,
prefer_clang_cl_over_msvc: bool,
}

/// Represents the types of errors that may occur while using cc-rs.
@@ -458,6 +459,7 @@ impl Build {
shell_escaped_flags: None,
build_cache: Arc::default(),
inherit_rustflags: true,
prefer_clang_cl_over_msvc: false,
}
}

@@ -1359,6 +1361,14 @@ impl Build {
self
}

/// Prefer to use clang-cl over msvc.
///
/// This option defaults to `false`.
pub fn prefer_clang_cl_over_msvc(&mut self, prefer_clang_cl_over_msvc: bool) -> &mut Build {
self.prefer_clang_cl_over_msvc = prefer_clang_cl_over_msvc;
self
}

#[doc(hidden)]
pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Build
where
@@ -2732,10 +2742,17 @@ impl Build {
}
let target = self.get_target()?;
let raw_target = self.get_raw_target()?;
let (env, msvc, gnu, traditional, clang) = if self.cpp {
("CXX", "cl.exe", "g++", "c++", "clang++")

let msvc = if self.prefer_clang_cl_over_msvc {
"clang-cl.exe"
} else {
"cl.exe"
};

let (env, gnu, traditional, clang) = if self.cpp {
("CXX", "g++", "c++", "clang++")
} else {
("CC", "cl.exe", "gcc", "cc", "clang")
("CC", "gcc", "cc", "clang")
};

// On historical Solaris systems, "cc" may have been Sun Studio, which
@@ -2748,7 +2765,7 @@ impl Build {
traditional
};

let cl_exe = self.windows_registry_find_tool(&target, "cl.exe");
let cl_exe = self.windows_registry_find_tool(&target, msvc);

let tool_opt: Option<Tool> = self
.env_tool(env)