Skip to content

Fix architecture detection by using .NET runtime architecture instead of system architecture#544

Merged
MikaelMayer merged 5 commits intomasterfrom
fix-dotnet-architecture-detection
Sep 9, 2025
Merged

Fix architecture detection by using .NET runtime architecture instead of system architecture#544
MikaelMayer merged 5 commits intomasterfrom
fix-dotnet-architecture-detection

Conversation

@MikaelMayer
Copy link
Copy Markdown
Member

@MikaelMayer MikaelMayer commented Sep 9, 2025

Problem Analysis

The previous fix (#543) attempted to solve architecture detection issues by using system architecture, but root cause analysis reveals the real problem:

Confirmed user system:

  • Hardware: ARM64 Mac (M1/M2) - uname -m returns arm64
  • .NET Binary: x86_64 - lipo -archs /usr/local/bin/dotnet returns x86_64
  • .NET Runtime: RID: osx-x64 - running under Rosetta translation
  • Error: have 'arm64', need 'x86_64'

What was happening:

  1. Extension detected ARM64 system → downloaded ARM64 Dafny binaries
  2. .NET runtime was x64 (Rosetta) → tried to load ARM64 libraries
  3. Architecture mismatch → incompatible architecture error

Root Cause

The issue isn't system architecture detection - it's that .NET can run under Rosetta translation on ARM64 Macs. When this happens:

  • System architecture: ARM64
  • .NET runtime architecture: x64
  • We need x64 Dafny binaries, not ARM64

Solution

Detect .NET runtime architecture instead of system architecture:

  1. Use dotnet --info to get actual .NET runtime information
  2. Parse RID (Runtime Identifier): osx-x64 vs osx-arm64
  3. Parse Architecture field: x64 vs Arm64
  4. Download matching Dafny binaries for the .NET runtime architecture
  5. Fallback chain: .NET detection → system detection → os.arch()

Why This Fixes The Issue

  • ARM64 Mac + Native .NET: Downloads ARM64 Dafny ✅
  • ARM64 Mac + Rosetta .NET: Downloads x64 Dafny ✅
  • x64 Mac: Downloads x64 Dafny ✅
  • Other platforms: Unchanged behavior ✅

This addresses the actual compatibility requirement: Dafny binaries must match .NET runtime architecture, not system hardware architecture.

Confirmed Fix

With the user's confirmed data (RID: osx-x64), this fix will:

  1. Parse osx-x64 from dotnet --info output
  2. Extract x64 architecture
  3. Download dafny-4.11.0-x64-macos-13.zip instead of dafny-4.11.0-arm64-macos-13.zip
  4. Resolve the architecture mismatch error

Testing

The fix includes comprehensive logging to help debug architecture detection issues and verify the correct architecture is being selected.

Supersedes #543 with the correct approach based on root cause analysis.

The previous fix detected system architecture but the real issue is that
.NET can run under Rosetta translation on ARM64 Macs, requiring x64 Dafny
binaries even on ARM64 hardware.

Root cause analysis:
- User has ARM64 Mac (uname -m returns arm64)
- But .NET runtime is x64 (running under Rosetta)
- Extension downloaded ARM64 Dafny but .NET needs x64 libraries
- Error: 'have arm64, need x86_64'

Solution:
- Use 'dotnet --info' to detect actual .NET runtime architecture
- Parse RID (Runtime Identifier) or Architecture field
- Download Dafny binaries matching .NET runtime, not system hardware
- Fallback to system detection if .NET detection fails

This ensures compatibility when .NET runs under Rosetta translation.
- Remove trailing spaces
- Use RegExp.exec() instead of String.match()
- Fix keyword spacing for catch
- Remove space after catch
- Remove trailing spaces
@MikaelMayer MikaelMayer marked this pull request as ready for review September 9, 2025 16:32
- Reuse single execAsync instance for both dotnet --info and uname -m
- Remove duplicate import statements and setup code
- Cleaner, more maintainable implementation
Copy link
Copy Markdown

@ssomayyajula ssomayyajula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting the process on this one

@MikaelMayer MikaelMayer merged commit ef51aa0 into master Sep 9, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants