Skip to content

Commit 9af3d6e

Browse files
committed
[rust] Read PROCESSOR_ARCHITECTURE env in Windows to determine architecture
1 parent c29317c commit 9af3d6e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ test --test_env=JRUBY_OPTS="--dev"
105105

106106
test:windows --test_env=PATH
107107
test:windows --test_env=LOCALAPPDATA
108+
test:windows --test_env=PROCESSOR_ARCHITECTURE
108109
test:windows --test_env=PROGRAMFILES="C:\\Program Files"
109110
test:windows --test_env=PROGRAMFILES(X86)="C:\\Program Files (x86)"
110111

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_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_PROCESSOR_ARCHITECTURE,
22+
REQUEST_TIMEOUT_SEC, UNAME_COMMAND,
2323
};
2424
use crate::{ARCH_AMD64, ARCH_ARM64, ARCH_X86, TTL_SEC, WMIC_COMMAND_OS};
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 wmic_command = Command::new_single(WMIC_COMMAND_OS.to_string());
73-
let wmic_output = run_shell_command_by_os(self_os, wmic_command).unwrap_or_default();
74-
if wmic_output.contains("32") {
72+
let mut architecture = env::var(ENV_PROCESSOR_ARCHITECTURE).unwrap_or_default();
73+
if architecture.is_empty() {
74+
let get_os_command = Command::new_single(WMIC_COMMAND_OS.to_string());
75+
architecture = run_shell_command_by_os(self_os, get_os_command).unwrap_or_default();
76+
}
77+
if architecture.contains("32") {
7578
ARCH_X86.to_string()
76-
} else if wmic_output.contains("ARM") {
79+
} else if architecture.contains("ARM") {
7780
ARCH_ARM64.to_string()
7881
} else {
7982
ARCH_AMD64.to_string()

rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub const SINGLE_QUOTE: &str = "'";
9494
pub const ENV_PROGRAM_FILES: &str = "PROGRAMFILES";
9595
pub const ENV_PROGRAM_FILES_X86: &str = "PROGRAMFILES(X86)";
9696
pub const ENV_LOCALAPPDATA: &str = "LOCALAPPDATA";
97+
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
9798
pub const ENV_X86: &str = " (x86)";
9899
pub const ARCH_X86: &str = "x86";
99100
pub const ARCH_AMD64: &str = "amd64";
100101
pub const ARCH_ARM64: &str = "arm64";
101-
pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE";
102102
pub const TTL_SEC: u64 = 3600;
103103
pub const UNAME_COMMAND: &str = "uname -{}";
104104
pub const ESCAPE_COMMAND: &str = r#"printf %q "{}""#;

0 commit comments

Comments
 (0)