|
2 | 2 | //!
|
3 | 3 | //! Uses values from the `CFG_VERSION` and `CFG_RELEASE` environment variables
|
4 | 4 | //! to set the product and file version information in the Windows resource file.
|
5 |
| -use std::{env, ffi, fs, path, process}; |
6 |
| - |
7 |
| -use cc::windows_registry; |
| 5 | +use std::{env, fs, path, process}; |
8 | 6 |
|
9 | 7 | /// The template for the Windows resource file.
|
10 | 8 | const RESOURCE_TEMPLATE: &str = include_str!("../rustc.rc.in");
|
@@ -35,8 +33,7 @@ pub fn compile_windows_resource_file(
|
35 | 33 | resources_dir.push("resources");
|
36 | 34 | fs::create_dir_all(&resources_dir).unwrap();
|
37 | 35 |
|
38 |
| - let resource_compiler = |
39 |
| - find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe"); |
| 36 | + let resource_compiler = find_resource_compiler().expect("found rc.exe"); |
40 | 37 |
|
41 | 38 | let rc_path = resources_dir.join(file_stem.with_extension("rc"));
|
42 | 39 |
|
@@ -134,25 +131,26 @@ fn parse_version(version: &str) -> Option<ResourceVersion> {
|
134 | 131 |
|
135 | 132 | /// Find the Windows SDK resource compiler `rc.exe` for the given architecture or target triple.
|
136 | 133 | /// Returns `None` if the tool could not be found.
|
137 |
| -fn find_resource_compiler(arch_or_target: &str) -> Option<path::PathBuf> { |
138 |
| - find_windows_sdk_tool(arch_or_target, "rc.exe") |
| 134 | +fn find_resource_compiler() -> Option<path::PathBuf> { |
| 135 | + find_windows_sdk_tool("rc.exe") |
139 | 136 | }
|
140 | 137 |
|
141 | 138 | /// Find a Windows SDK tool for the given architecture or target triple.
|
142 | 139 | /// Returns `None` if the tool could not be found.
|
143 |
| -fn find_windows_sdk_tool(arch_or_target: &str, tool_name: &str) -> Option<path::PathBuf> { |
144 |
| - // windows_registry::find_tool can only find MSVC tools, not Windows SDK tools, but |
145 |
| - // cc does include the Windows SDK tools in the PATH environment of MSVC tools. |
| 140 | +fn find_windows_sdk_tool(tool_name: &str) -> Option<path::PathBuf> { |
| 141 | + let (ucrt_dir, ucrt_version) = find_msvc_tools::get_ucrt_dir()?; |
146 | 142 |
|
147 |
| - let msvc_linker = windows_registry::find_tool(arch_or_target, "link.exe")?; |
148 |
| - let path = &msvc_linker.env().iter().find(|(k, _)| k == "PATH")?.1; |
149 |
| - find_tool_in_path(tool_name, path) |
150 |
| -} |
| 143 | + // Determine the host architecture to find the right subdirectory in the Windows SDK |
| 144 | + let host = match env::var("HOST").ok()?.split('-').next()? { |
| 145 | + "x86" => "x86", |
| 146 | + "x86_64" => "x64", |
| 147 | + "aarch64" => "arm64", |
| 148 | + _ => return None, |
| 149 | + }; |
| 150 | + |
| 151 | + let mut tool_path = ucrt_dir.join("bin").join(&ucrt_version).join(host); |
| 152 | + |
| 153 | + tool_path.push(tool_name); |
151 | 154 |
|
152 |
| -/// Find a tool in the directories in a given PATH-like string. |
153 |
| -fn find_tool_in_path<P: AsRef<ffi::OsStr>>(tool_name: &str, path: P) -> Option<path::PathBuf> { |
154 |
| - env::split_paths(path.as_ref()).find_map(|p| { |
155 |
| - let tool_path = p.join(tool_name); |
156 |
| - if tool_path.try_exists().unwrap_or(false) { Some(tool_path) } else { None } |
157 |
| - }) |
| 155 | + Some(tool_path) |
158 | 156 | }
|
0 commit comments