Skip to content

Commit 959dd1e

Browse files
cdervclaude
andcommitted
perf(R): optimize ARM architecture checks and add documentation
Performance improvements: - Check isX64R first to short-circuit when R is ARM64 (correct setup) - Only check ARM architecture when R fails (x64 R on ARM always crashes) - Avoids FFI overhead for all successful R checks Documentation: - Explains why kernel32.dll FFI is needed and safe - Links to validation repo and Microsoft API docs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 277fabb commit 959dd1e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/core/knitr.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function checkWindowsArmR(platform: string | undefined): void {
8282

8383
const isX64R = platform.includes("x86_64") || platform.includes("i386");
8484

85-
if (isWindowsArm() && isX64R) {
85+
if (isX64R && isWindowsArm()) {
8686
throw new WindowsArmX64RError(
8787
"x64 R detected on Windows ARM.\n\n" +
8888
"x64 R runs under emulation and is not reliable for Quarto.\n" +
@@ -131,7 +131,6 @@ export async function knitrCapabilities(rBin: string | undefined) {
131131
)
132132
: false;
133133

134-
checkWindowsArmR(caps.platform);
135134
return caps;
136135
} else {
137136
debug("\n++ Problem with results of knitr capabilities check.");

src/core/windows.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ export async function safeWindowsExec(
166166

167167
// Detect Windows ARM hardware using IsWow64Process2 API
168168
// Returns true if running on ARM64 hardware (even from x64 Deno under emulation)
169+
//
170+
// Background: Deno.build.arch reports the architecture Deno was compiled for,
171+
// not the actual hardware architecture. When x64 Deno runs on ARM64 under
172+
// WOW64 emulation, Deno.build.arch still reports "x86_64".
173+
//
174+
// Solution: Use Windows IsWow64Process2 API which returns the native machine
175+
// architecture regardless of emulation. This is a standard Windows API function
176+
// available since Windows 10 (kernel32.dll is always present on Windows).
177+
//
178+
// Reference: Validated approach from https://github.com/cderv/quarto-windows-arm
179+
// See: https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-iswow64process2
169180
export function isWindowsArm(): boolean {
170181
if (!isWindows) {
171182
return false;

0 commit comments

Comments
 (0)