Better support M1 users (#117766)

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Spencer 2021-11-08 15:47:52 -07:00 committed by GitHub
parent d366cffb24
commit 62f7c9da0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 838 additions and 684 deletions

View file

@ -62,7 +62,8 @@
"backport-skip-ci": "backport --prDescription \"[skip-ci]\"",
"storybook": "node scripts/storybook",
"cover:report": "nyc report --temp-dir target/kibana-coverage/functional --report-dir target/coverage/report --reporter=lcov && open ./target/coverage/report/lcov-report/index.html",
"cover:functional:merge": "nyc report --temp-dir target/kibana-coverage/functional --report-dir target/coverage/report/functional --reporter=json-summary"
"cover:functional:merge": "nyc report --temp-dir target/kibana-coverage/functional --report-dir target/coverage/report/functional --reporter=json-summary",
"postinstall": "node scripts/kbn patch_native_modules"
},
"repository": {
"type": "git",

File diff suppressed because it is too large Load diff

View file

@ -32,6 +32,7 @@ import { CleanCommand } from './clean';
import { ResetCommand } from './reset';
import { RunCommand } from './run';
import { WatchCommand } from './watch';
import { PatchNativeModulesCommand } from './patch_native_modules';
import { Kibana } from '../utils/kibana';
export const commands: { [key: string]: ICommand } = {
@ -41,4 +42,5 @@ export const commands: { [key: string]: ICommand } = {
reset: ResetCommand,
run: RunCommand,
watch: WatchCommand,
patch_native_modules: PatchNativeModulesCommand,
};

View file

@ -0,0 +1,68 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import Path from 'path';
import Fs from 'fs';
import { CiStatsReporter } from '@kbn/dev-utils/ci_stats_reporter';
import { log } from '../utils/log';
import { spawn } from '../utils/child_process';
import { ICommand } from './index';
export const PatchNativeModulesCommand: ICommand = {
description: 'Patch native modules by running build commands on M1 Macs',
name: 'patch_native_modules',
async run(projects, _, { kbn }) {
const kibanaProjectPath = projects.get('kibana')?.path || '';
const reporter = CiStatsReporter.fromEnv(log);
if (process.platform !== 'darwin' || process.arch !== 'arm64') {
return;
}
const startTime = Date.now();
const nodeSassDir = Path.resolve(kibanaProjectPath, 'node_modules/node-sass');
const nodeSassNativeDist = Path.resolve(
nodeSassDir,
`vendor/darwin-arm64-${process.versions.modules}/binding.node`
);
if (!Fs.existsSync(nodeSassNativeDist)) {
log.info('Running build script for node-sass');
await spawn('npm', ['run', 'build'], {
cwd: nodeSassDir,
});
}
const re2Dir = Path.resolve(kibanaProjectPath, 'node_modules/re2');
const re2NativeDist = Path.resolve(re2Dir, 'build/Release/re2.node');
if (!Fs.existsSync(re2NativeDist)) {
log.info('Running build script for re2');
await spawn('npm', ['run', 'rebuild'], {
cwd: re2Dir,
});
}
log.success('native modules should be setup for native ARM Mac development');
// send timings
await reporter.timings({
upstreamBranch: kbn.kibanaProject.json.branch,
// prevent loading @kbn/utils by passing null
kibanaUuid: kbn.getUuid() || null,
timings: [
{
group: 'scripts/kbn bootstrap',
id: 'patch native modudles for arm macs',
ms: Date.now() - startTime,
},
],
});
},
};