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

Detect msvc version if there is no default #696

Merged
merged 1 commit into from
Sep 24, 2023
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
47 changes: 40 additions & 7 deletions src/windows_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,10 @@ mod impl_ {

fn vs15plus_vc_paths(
target: &str,
instance_path: &PathBuf,
instance_path: &Path,
) -> Option<(PathBuf, PathBuf, PathBuf, PathBuf, PathBuf)> {
let version_path =
instance_path.join(r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt");
let mut version_file = File::open(version_path).ok()?;
let mut version = String::new();
version_file.read_to_string(&mut version).ok()?;
let version = version.trim();
let version = vs15plus_vc_read_version(instance_path)?;

let host = match host_arch() {
X86 => "X86",
X86_64 => "X64",
Expand Down Expand Up @@ -487,6 +483,43 @@ mod impl_ {
Some((path, bin_path, host_dylib_path, lib_path, include_path))
}

fn vs15plus_vc_read_version(dir: &Path) -> Option<String> {
// Try to open the default version file.
let mut version_path: PathBuf =
dir.join(r"VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt");
let mut version_file = if let Ok(f) = File::open(&version_path) {
f
} else {
// If the default doesn't exist, search for other version files.
// These are in the form Microsoft.VCToolsVersion.v143.default.txt
// where `143` is any three decimal digit version number.
// This sorts versions by lexical order and selects the highest version.
let mut version_file = String::new();
version_path.pop();
for file in version_path.read_dir().ok()? {
let name = file.ok()?.file_name();
let name = name.to_str()?;
if name.starts_with("Microsoft.VCToolsVersion.v")
&& name.ends_with(".default.txt")
&& name > &version_file
{
version_file.replace_range(.., name);
}
}
if version_file.is_empty() {
return None;
}
version_path.push(version_file);
File::open(version_path).ok()?
};

// Get the version string from the file we found.
let mut version = String::new();
version_file.read_to_string(&mut version).ok()?;
version.truncate(version.trim_end().len());
Some(version)
}

fn atl_paths(target: &str, path: &Path) -> Option<(PathBuf, PathBuf)> {
let atl_path = path.join("atlmfc");
let sub = lib_subdir(target)?;
Expand Down