|
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"); |
@@ -38,7 +36,10 @@ pub fn compile_windows_resource_file( |
38 | 36 | let resource_compiler = if let Ok(path) = env::var("RUSTC_WINDOWS_RC") { |
39 | 37 | path.into() |
40 | 38 | } else { |
41 | | - find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe") |
| 39 | + find_msvc_tools::find_tool(&env::var("CARGO_CFG_TARGET_ARCH").unwrap(), "rc.exe") |
| 40 | + .expect("found rc.exe") |
| 41 | + .path() |
| 42 | + .to_owned() |
42 | 43 | }; |
43 | 44 |
|
44 | 45 | let rc_path = resources_dir.join(file_stem.with_extension("rc")); |
@@ -134,28 +135,3 @@ fn parse_version(version: &str) -> Option<ResourceVersion> { |
134 | 135 | Some(ResourceVersion { major, minor, patch, build: 0 }) |
135 | 136 | } |
136 | 137 | } |
137 | | - |
138 | | -/// Find the Windows SDK resource compiler `rc.exe` for the given architecture or target triple. |
139 | | -/// Returns `None` if the tool could not be found. |
140 | | -fn find_resource_compiler(arch_or_target: &str) -> Option<path::PathBuf> { |
141 | | - find_windows_sdk_tool(arch_or_target, "rc.exe") |
142 | | -} |
143 | | - |
144 | | -/// Find a Windows SDK tool for the given architecture or target triple. |
145 | | -/// Returns `None` if the tool could not be found. |
146 | | -fn find_windows_sdk_tool(arch_or_target: &str, tool_name: &str) -> Option<path::PathBuf> { |
147 | | - // windows_registry::find_tool can only find MSVC tools, not Windows SDK tools, but |
148 | | - // cc does include the Windows SDK tools in the PATH environment of MSVC tools. |
149 | | - |
150 | | - let msvc_linker = windows_registry::find_tool(arch_or_target, "link.exe")?; |
151 | | - let path = &msvc_linker.env().iter().find(|(k, _)| k == "PATH")?.1; |
152 | | - find_tool_in_path(tool_name, path) |
153 | | -} |
154 | | - |
155 | | -/// Find a tool in the directories in a given PATH-like string. |
156 | | -fn find_tool_in_path<P: AsRef<ffi::OsStr>>(tool_name: &str, path: P) -> Option<path::PathBuf> { |
157 | | - env::split_paths(path.as_ref()).find_map(|p| { |
158 | | - let tool_path = p.join(tool_name); |
159 | | - if tool_path.try_exists().unwrap_or(false) { Some(tool_path) } else { None } |
160 | | - }) |
161 | | -} |
0 commit comments