Skip to content
Permalink
Browse files

fix(bazel): Disable sandbox on Mac OS (#30460)

Removing the sandbox improves build time by almost 40%.

For a hello world (ng new) application:
ng build with sandbox: 22.0 seconds
ng build without sandbox: 13.3 seconds

PR Close #30460
  • Loading branch information...
kyliau authored and jasonaden committed May 14, 2019
1 parent 1aff524 commit b6b1aec22b2ccc326ef0965babe65c6d93ac107c
Showing with 21 additions and 0 deletions.
  1. +21 −0 packages/bazel/src/builders/bazel.ts
@@ -10,6 +10,7 @@

import {spawn} from 'child_process';
import {copyFileSync, existsSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync} from 'fs';
import {platform} from 'os';
import {dirname, join, normalize} from 'path';

export type Executable = 'bazel' | 'ibazel';
@@ -133,6 +134,24 @@ function replaceYarnWithNpm(source: string, dest: string) {
writeFileSync(dest, destContent);
}

/**
* Disable sandbox on Mac OS by setting spawn_strategy in .bazelrc.
* For a hello world (ng new) application, removing the sandbox improves build
* time by almost 40%.
* ng build with sandbox: 22.0 seconds
* ng build without sandbox: 13.3 seconds
*/
function disableSandbox(source: string, dest: string) {
const srcContent = readFileSync(source, 'utf-8');
const destContent = `${srcContent}
# Disable sandbox on Mac OS for performance reason.
build --spawn_strategy=local
run --spawn_strategy=local
test --spawn_strategy=local
`;
writeFileSync(dest, destContent);
}

/**
* Copy Bazel files (WORKSPACE, BUILD.bazel, etc) from the template directory to
* the project `root` directory, and return the absolute paths of the files
@@ -154,6 +173,8 @@ export function copyBazelFiles(root: string, templateDir: string) {
if (!existsSync(dest)) {
if (!useYarn && name === 'WORKSPACE') {
replaceYarnWithNpm(source, dest);
} else if (platform() === 'darwin' && name === '.bazelrc') {
disableSandbox(source, dest);
} else {
copyFileSync(source, dest);
}

0 comments on commit b6b1aec

Please sign in to comment.
You can’t perform that action at this time.