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

feat: add support for Apple Silicon chromium builds #7546

Merged
merged 17 commits into from May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/node/BrowserFetcher.ts
Expand Up @@ -41,6 +41,7 @@ const downloadURLs = {
chrome: {
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
mac_arm: '%s/chromium-browser-snapshots/Mac_Arm/%d/%s.zip',
win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
},
Expand All @@ -67,7 +68,7 @@ const browserConfig = {
* Supported platforms.
* @public
*/
export type Platform = 'linux' | 'mac' | 'win32' | 'win64';
export type Platform = 'linux' | 'mac' | 'mac_arm' | 'win32' | 'win64';

function archiveName(
product: Product,
Expand All @@ -76,7 +77,7 @@ function archiveName(
): string {
if (product === 'chrome') {
if (platform === 'linux') return 'chrome-linux';
if (platform === 'mac') return 'chrome-mac';
if (platform === 'mac' || platform === 'mac_arm') return 'chrome-mac';
if (platform === 'win32' || platform === 'win64') {
// Windows archive name changed at r591479.
return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
Expand Down Expand Up @@ -198,21 +199,26 @@ export class BrowserFetcher {
options.path ||
path.join(projectRoot, browserConfig[this._product].destination);
this._downloadHost = options.host || browserConfig[this._product].host;
this.setPlatform(options.platform);
this.setPlatform(options.platform, this._product);
assert(
downloadURLs[this._product][this._platform],
'Unsupported platform: ' + this._platform
);
}

private setPlatform(platformFromOptions?: Platform): void {
private setPlatform(
platformFromOptions?: Platform,
productFromOptions?: Product
): void {
if (platformFromOptions) {
this._platform = platformFromOptions;
return;
}

const platform = os.platform();
if (platform === 'darwin') this._platform = 'mac';
if (platform === 'darwin' && productFromOptions === 'chrome')
this._platform = os.arch() === 'arm64' ? 'mac_arm' : 'mac';
else if (productFromOptions === 'firefox') this._platform = 'mac';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't feel right for me, but firefox ships universal build, so in downloadURLs we can't use the separate url for firefox for MacOS ARM because of string interpolation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as workaround we can pass platform as query parameter in firefox case and remove this hack

else if (platform === 'linux') this._platform = 'linux';
else if (platform === 'win32')
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
Expand Down Expand Up @@ -295,8 +301,7 @@ export class BrowserFetcher {
if (!(await existsAsync(this._downloadsFolder)))
await mkdirAsync(this._downloadsFolder);

// Use Intel x86 builds on Apple M1 until native macOS arm64
// Chromium builds are available.
// Use system Chromium builds on Linux ARM devices
if (os.platform() !== 'darwin' && os.arch() === 'arm64') {
handleArm64();
return;
Expand Down Expand Up @@ -351,7 +356,7 @@ export class BrowserFetcher {
const folderPath = this._getFolderPath(revision);
let executablePath = '';
if (this._product === 'chrome') {
if (this._platform === 'mac')
if (this._platform === 'mac' || this._platform === 'mac_arm')
executablePath = path.join(
folderPath,
archiveName(this._product, this._platform, revision),
Expand All @@ -374,7 +379,7 @@ export class BrowserFetcher {
);
else throw new Error('Unsupported platform: ' + this._platform);
} else if (this._product === 'firefox') {
if (this._platform === 'mac')
if (this._platform === 'mac' || this._platform === 'mac_arm')
executablePath = path.join(
folderPath,
'Firefox Nightly.app',
Expand Down
3 changes: 1 addition & 2 deletions src/node/Launcher.ts
Expand Up @@ -118,8 +118,7 @@ class ChromeLauncher implements ProductLauncher {

chromeExecutable = executablePathForChannel(channel);
} else if (!executablePath) {
// Use Intel x86 builds on Apple M1 until native macOS arm64
// Chromium builds are available.
// Use system Chromium builds on Linux ARM devices
if (os.platform() !== 'darwin' && os.arch() === 'arm64') {
chromeExecutable = '/usr/bin/chromium-browser';
} else {
Expand Down
11 changes: 3 additions & 8 deletions src/node/install.ts
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import os from 'os';
import https from 'https';
import ProgressBar from 'progress';
import puppeteer from '../node.js';
Expand Down Expand Up @@ -90,13 +89,9 @@ export async function downloadBrowser(): Promise<void> {
if (NPM_NO_PROXY) process.env.NO_PROXY = NPM_NO_PROXY;

function onSuccess(localRevisions: string[]): void {
// Use Intel x86 builds on Apple M1 until native macOS arm64
// Chromium builds are available.
if (os.platform() !== 'darwin' && os.arch() !== 'arm64') {
logPolitely(
`${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`
);
}
logPolitely(
OrKoN marked this conversation as resolved.
Show resolved Hide resolved
`${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}`
);
localRevisions = localRevisions.filter(
(revision) => revision !== revisionInfo.revision
);
Expand Down
2 changes: 1 addition & 1 deletion src/revisions.ts
Expand Up @@ -20,6 +20,6 @@ type Revisions = Readonly<{
}>;

export const PUPPETEER_REVISIONS: Revisions = {
chromium: '901912',
chromium: '916291',
firefox: 'latest',
};
7 changes: 5 additions & 2 deletions utils/check_availability.js
Expand Up @@ -21,7 +21,7 @@ const https = require('https');
const BrowserFetcher =
require('../lib/cjs/puppeteer/node/BrowserFetcher.js').BrowserFetcher;

const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64'];
const SUPPORTER_PLATFORMS = ['linux', 'mac', 'mac_arm', 'win32', 'win64'];
const fetchers = SUPPORTER_PLATFORMS.map(
(platform) => new BrowserFetcher('', { platform })
);
Expand Down Expand Up @@ -139,6 +139,9 @@ async function checkOmahaProxyAvailability() {
fetch(
'https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE'
),
fetch(
'https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/LAST_CHANGE'
),
fetch(
'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE'
),
Expand Down Expand Up @@ -191,7 +194,7 @@ async function checkRangeAvailability({
toRevision,
stopWhenAllAvailable,
}) {
const table = new Table([10, 7, 7, 7, 7]);
const table = new Table([10, 7, 7, 7, 7, 7]);
table.drawRow([''].concat(SUPPORTER_PLATFORMS));

const inc = fromRevision < toRevision ? 1 : -1;
Expand Down