Skip to content

Commit 0088790

Browse files
committed
[rust] Read PROCESSOR_ARCHITECTURE env in Windows to determine architecture
1 parent a56ac18 commit 0088790

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

rust/src/config.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use crate::config::OS::{LINUX, MACOS, WINDOWS};
1919
use crate::shell::{run_powershell_command, run_shell_command_by_os};
2020
use crate::{
21-
default_cache_folder, format_one_arg, path_to_string, Command, REQUEST_TIMEOUT_SEC,
22-
UNAME_COMMAND,
21+
default_cache_folder, format_one_arg, path_to_string, Command, ENV_CPU_ARCHITECTURE,
22+
REQUEST_TIMEOUT_SEC, UNAME_COMMAND,
2323
};
2424
use crate::{ARCH_AMD64, ARCH_ARM64, ARCH_X86, PS_GET_OS_COMMAND, TTL_SEC};
2525
use anyhow::anyhow;
@@ -69,11 +69,14 @@ impl ManagerConfig {
6969

7070
let self_os = OS;
7171
let self_arch = if WINDOWS.is(self_os) {
72-
let get_os_command = Command::new_single(PS_GET_OS_COMMAND.to_string());
73-
let output = run_powershell_command(get_os_command).unwrap_or_default();
74-
if output.contains("32") {
72+
let mut cpu_arch = env::var(ENV_CPU_ARCHITECTURE).unwrap_or_default();
73+
if cpu_arch.is_empty() {
74+
let get_os_command = Command::new_single(PS_GET_OS_COMMAND.to_string());
75+
cpu_arch = run_powershell_command(get_os_command).unwrap_or_default();
76+
}
77+
if cpu_arch.contains("32") {
7578
ARCH_X86.to_string()
76-
} else if output.contains("ARM") {
79+
} else if cpu_arch.contains("ARM") {
7780
ARCH_ARM64.to_string()
7881
} else {
7982
ARCH_AMD64.to_string()

rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub const SINGLE_QUOTE: &str = "'";
9595
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
9696
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
9797
pub const ENV_LOCALAPPDATA: &str = "LOCALAPPDATA";
98+
pub const ENV_CPU_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
9899
pub const ENV_X86: &str = " (x86)";
99100
pub const ARCH_X86: &str = "x86";
100101
pub const ARCH_AMD64: &str = "amd64";

0 commit comments

Comments
 (0)