Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download arm64 clang when using Electron clang on Apple Silicon #1113

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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