|
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");
|
@@ -36,15 +34,16 @@ pub fn compile_windows_resource_file(
|
36 | 34 | fs::create_dir_all(&resources_dir).unwrap();
|
37 | 35 |
|
38 | 36 | let resource_compiler =
|
39 |
| - find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe"); |
| 37 | + find_msvc_tools::find_tool(&env::var("CARGO_CFG_TARGET_ARCH").unwrap(), "rc.exe") |
| 38 | + .expect("found rc.exe"); |
40 | 39 |
|
41 | 40 | let rc_path = resources_dir.join(file_stem.with_extension("rc"));
|
42 | 41 |
|
43 | 42 | write_resource_script_file(&rc_path, file_description, filetype);
|
44 | 43 |
|
45 | 44 | let res_path = resources_dir.join(file_stem.with_extension("res"));
|
46 | 45 |
|
47 |
| - let status = process::Command::new(resource_compiler) |
| 46 | + let status = process::Command::new(resource_compiler.path()) |
48 | 47 | .arg("/fo")
|
49 | 48 | .arg(&res_path)
|
50 | 49 | .arg(&rc_path)
|
@@ -131,28 +130,3 @@ fn parse_version(version: &str) -> Option<ResourceVersion> {
|
131 | 130 | Some(ResourceVersion { major, minor, patch, build: 0 })
|
132 | 131 | }
|
133 | 132 | }
|
134 |
| - |
135 |
| -/// Find the Windows SDK resource compiler `rc.exe` for the given architecture or target triple. |
136 |
| -/// 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") |
139 |
| -} |
140 |
| - |
141 |
| -/// Find a Windows SDK tool for the given architecture or target triple. |
142 |
| -/// 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. |
146 |
| - |
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 |
| -} |
151 |
| - |
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 |
| - }) |
158 |
| -} |
0 commit comments