Skip to content

Commit

Permalink
fix: download arm64 clang when using Electron clang on Apple Silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Nov 18, 2023
1 parent ee3eb00 commit 795b94e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/clang-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 795b94e

Please sign in to comment.