From 25bcc0d966a5473909e7d334f9afd4c6b35896ff Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 21 Nov 2023 15:13:59 -0800 Subject: [PATCH] fix: download arm64 clang when using Electron clang on Apple Silicon (#1113) --- src/clang-fetcher.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/clang-fetcher.ts b/src/clang-fetcher.ts index 8a6f624..13bae75 100644 --- a/src/clang-fetcher.ts +++ b/src/clang-fetcher.ts @@ -12,18 +12,22 @@ const d = debug('electron-rebuild'); const CDS_URL = 'https://commondatastorage.googleapis.com/chromium-browser-clang'; -function getPlatformUrlPrefix(hostOS: string) { +function getPlatformUrlPrefix(hostOS: string, hostArch: string) { const prefixMap = { 'linux': 'Linux_x64', 'darwin': 'Mac', 'win32': 'Win', + }; + let prefix = prefixMap[hostOS]; + if (prefix === 'Mac' && hostArch === 'arm64') { + prefix = 'Mac_arm64'; } - return CDS_URL + '/' + prefixMap[hostOS] + '/' + return CDS_URL + '/' + prefix + '/'; } -function getClangDownloadURL(packageFile: string, packageVersion: string, hostOS: string) { +function getClangDownloadURL(packageFile: string, packageVersion: string, hostOS: string, hostArch: string) { const cdsFile = `${packageFile}-${packageVersion}.tgz`; - return getPlatformUrlPrefix(hostOS) + cdsFile; + return getPlatformUrlPrefix(hostOS, hostArch) + cdsFile; } function getSDKRoot(): string { @@ -97,7 +101,7 @@ async function downloadClangVersion(electronVersion: string) { if (!clangVersionString) throw new Error('Failed to determine Clang revision from Electron version'); d('fetching clang:', clangVersionString); - const clangDownloadURL = getClangDownloadURL('clang', clangVersionString, process.platform); + const clangDownloadURL = getClangDownloadURL('clang', clangVersionString, process.platform, process.arch); const contents = await fetch(clangDownloadURL, 'buffer'); d('deflating clang');