Skip to content

Commit 16791f6

Browse files
authored
Merge pull request #13 from BOINC/vko_use_correct_runner_image_based_on_architecture
Detect OS architecture and install the corresponding boinc-buda-runner-wsl image
2 parents c52e470 + 12b3f25 commit 16791f6

1 file changed

Lines changed: 68 additions & 6 deletions

File tree

BudaRunnerCheck.cs

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,23 +510,53 @@ private static async Task<string> GetLatestDownloadUrlFromGitHubAsync()
510510
const string fallbackUrl = "https://github.com/BOINC/boinc-buda-runner-wsl/releases/latest";
511511
try
512512
{
513+
var architecture = GetSystemArchitecture();
514+
DebugLogger.LogConfiguration("Detected Architecture", architecture, COMPONENT);
515+
513516
using (var httpClient = new HttpClient())
514517
{
515518
httpClient.DefaultRequestHeaders.Add("User-Agent", "BOINC-BUDA-WSL-Installer");
516519

517520
DebugLogger.LogInfo($"Fetching download URL from GitHub: {GITHUB_RELEASES_URL}", COMPONENT);
518521
var response = await httpClient.GetStringAsync(GITHUB_RELEASES_URL);
519522

520-
// Find .wsl download URL
521-
var downloadMatches = Regex.Matches(response, @"""browser_download_url"":\s*""([^""]+\.wsl)""");
523+
// Find .wsl download URLs
524+
var downloadMatches = Regex.Matches(response, @"""browser_download_url""\s*:\s*""([^""]+\.wsl)""");
522525
DebugLogger.LogConfiguration("Download Matches Found", downloadMatches.Count, COMPONENT);
523526

524527
if (downloadMatches.Count > 0)
525528
{
526-
var downloadUrl = downloadMatches[0].Groups[1].Value;
527-
DebugLogger.LogConfiguration("GitHub Download URL", downloadUrl, COMPONENT);
528-
DebugLogger.LogMethodEnd("GetLatestDownloadUrlFromGitHubAsync", downloadUrl, COMPONENT);
529-
return downloadUrl;
529+
string preferredUrl = null;
530+
string firstUrl = downloadMatches[0].Groups[1].Value;
531+
532+
foreach (Match m in downloadMatches)
533+
{
534+
var url = m.Groups[1].Value;
535+
var filename = Path.GetFileName(url).ToLowerInvariant();
536+
DebugLogger.LogDebug($"Evaluating asset: {filename}", COMPONENT);
537+
538+
if (architecture.Equals("ARM64", StringComparison.OrdinalIgnoreCase))
539+
{
540+
if (filename.Contains("aarch64") || filename.Contains("arm64"))
541+
{
542+
preferredUrl = url;
543+
break; // exact arch match
544+
}
545+
}
546+
else // treat everything else as x64 preference
547+
{
548+
if (filename.Contains("x86_64") || filename.Contains("amd64") || filename.Contains("x64"))
549+
{
550+
preferredUrl = url;
551+
break; // exact arch match
552+
}
553+
}
554+
}
555+
556+
var resultUrl = preferredUrl ?? firstUrl;
557+
DebugLogger.LogConfiguration("Selected Download URL", resultUrl, COMPONENT);
558+
DebugLogger.LogMethodEnd("GetLatestDownloadUrlFromGitHubAsync", resultUrl, COMPONENT);
559+
return resultUrl;
530560
}
531561
else
532562
{
@@ -935,5 +965,37 @@ public static string GetStatusDisplayMessage(BudaRunnerCheckResult result)
935965
DebugLogger.LogMethodEnd("GetStatusDisplayMessage", message, COMPONENT);
936966
return message;
937967
}
968+
969+
private static string GetSystemArchitecture()
970+
{
971+
DebugLogger.LogMethodStart("GetSystemArchitecture", component: COMPONENT);
972+
try
973+
{
974+
DebugLogger.LogConfiguration("Environment.Is64BitOperatingSystem", Environment.Is64BitOperatingSystem, COMPONENT);
975+
var procArch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") ?? string.Empty;
976+
DebugLogger.LogConfiguration("PROCESSOR_ARCHITECTURE", procArch, COMPONENT);
977+
978+
if (procArch.Equals("ARM64", StringComparison.OrdinalIgnoreCase))
979+
{
980+
DebugLogger.LogMethodEnd("GetSystemArchitecture", "ARM64", COMPONENT);
981+
return "ARM64";
982+
}
983+
984+
if (Environment.Is64BitOperatingSystem)
985+
{
986+
DebugLogger.LogMethodEnd("GetSystemArchitecture", "x64", COMPONENT);
987+
return "x64";
988+
}
989+
990+
DebugLogger.LogMethodEnd("GetSystemArchitecture", "x86", COMPONENT);
991+
return "x86";
992+
}
993+
catch (Exception ex)
994+
{
995+
DebugLogger.LogException(ex, "Error detecting system architecture, defaulting to x64", COMPONENT);
996+
DebugLogger.LogMethodEnd("GetSystemArchitecture", "x64 (default)", COMPONENT);
997+
return "x64";
998+
}
999+
}
9381000
}
9391001
}

0 commit comments

Comments
 (0)