diff --git a/docs/development/build-instructions-linux.md b/docs/development/build-instructions-linux.md index 870f4fca61f1..97779f376c80 100644 --- a/docs/development/build-instructions-linux.md +++ b/docs/development/build-instructions-linux.md @@ -137,9 +137,9 @@ The default building configuration is targeted for major desktop Linux distributions, to build for a specific distribution or device, following information may help you. -### Build libchromiumcontent locally +### Building `libchromiumcontent` locally -To avoid using the prebuilt binaries of libchromiumcontent, you can pass the +To avoid using the prebuilt binaries of `libchromiumcontent`, you can pass the `--build_libchromiumcontent` switch to `bootstrap.py` script: ```bash @@ -150,5 +150,54 @@ Note that by default the `shared_library` configuration is not built, so you can only build `Release` version of Electron if you use this mode: ```bash -$ ./script/build.py -c D +$ ./script/build.py -c R ``` + +### Using system `clang` instead of downloaded `clang` binaries + +By default Electron is built with prebuilt `clang` binaries provided by Chromium +project. If for some reason you want to build with the `clang` installed in your +system, you can call `bootstrap.py` with `--clang_dir=` switch. By passing +it the build script will assume the clang binaries reside in `/bin/`. + +For example if you installed `clang` under `/user/local/bin/clang`: + +```bash +$ ./script/bootstrap.py -v --build_libchromiumcontent --clang_dir /usr/local +$ ./script/build.py -c R +``` + +### Using other compilers other than `clang` + +To build Electron with compilers like `g++`, you first need to disable `clang` +with `--disable_clang` switch first, and then set `CC` and `CXX` environment +variables to the ones you want. + +For example building with GCC toolchain: + +```bash +$ env CC=gcc CXX=g++ ./script/bootstrap.py -v --build_libchromiumcontent --disable_clang +$ ./script/build.py -c R +``` + +### Environment variables + +Apart from `CC` and `CXX`, you can also set following environment variables to +custom the building configurations: + +* `CPPFLAGS` +* `CPPFLAGS_host` +* `CFLAGS` +* `CFLAGS_host` +* `CXXFLAGS` +* `CXXFLAGS_host` +* `AR` +* `AR_host` +* `CC` +* `CC_host` +* `CXX` +* `CXX_host` +* `LDFLAGS` + +The environment variables have to be set when executing the `bootstrap.py` +script, it won't work in the `build.py` script. diff --git a/script/bootstrap.py b/script/bootstrap.py index 2aba23ba82f2..816a6182b201 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -26,6 +26,7 @@ def main(): os.chdir(SOURCE_ROOT) args = parse_args() + defines = args_to_defines(args) if not args.yes and PLATFORM != 'win32': check_root() if args.verbose: @@ -41,7 +42,7 @@ def main(): # Redirect to use local libchromiumcontent build. if args.build_libchromiumcontent: - build_libchromiumcontent(args.verbose, args.target_arch) + build_libchromiumcontent(args.verbose, args.target_arch, defines) dist_dir = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'libchromiumcontent', 'dist', 'main') libcc_source_path = os.path.join(dist_dir, 'src') @@ -49,7 +50,11 @@ def main(): libcc_static_library_path = os.path.join(dist_dir, 'static_library') if PLATFORM != 'win32': + # Download prebuilt clang binaries. update_clang() + if not args.disable_clang and args.clang_dir == '': + # Build with prebuilt clang. + set_clang_env(os.environ) setup_python_libs() update_node_modules('.') @@ -62,7 +67,7 @@ def main(): create_chrome_version_h() touch_config_gypi() - run_update() + run_update(defines) update_electron_modules('spec', args.target_arch) @@ -85,6 +90,9 @@ def parse_args(): 'prompts.') parser.add_argument('--target_arch', default=get_target_arch(), help='Manually specify the arch to build for') + parser.add_argument('--clang_dir', default='', help='Path to clang binaries') + parser.add_argument('--disable_clang', action='store_true', + help='Use compilers other than clang for building') parser.add_argument('--build_libchromiumcontent', action='store_true', help='Build local version of libchromiumcontent') parser.add_argument('--libcc_source_path', required=False, @@ -98,6 +106,16 @@ def parse_args(): return parser.parse_args() +def args_to_defines(args): + defines = '' + if args.disable_clang: + defines += ' clang=0' + if args.clang_dir: + defines += ' make_clang_dir=' + args.clang_dir + defines += ' clang_use_chrome_plugins=0' + return defines + + def check_root(): if os.geteuid() == 0: print "We suggest not running this as root, unless you're really sure." @@ -137,15 +155,19 @@ def bootstrap_brightray(is_dev, url, target_arch, libcc_source_path, execute_stdout([sys.executable, bootstrap] + args) +def set_clang_env(env): + llvm_dir = os.path.join(SOURCE_ROOT, 'vendor', 'llvm-build', + 'Release+Asserts', 'bin') + env['CC'] = os.path.join(llvm_dir, 'clang') + env['CXX'] = os.path.join(llvm_dir, 'clang++') + + def update_node_modules(dirname, env=None): if env is None: - env = os.environ + env = os.environ.copy() if PLATFORM == 'linux': # Use prebuilt clang for building native modules. - llvm_dir = os.path.join(SOURCE_ROOT, 'vendor', 'llvm-build', - 'Release+Asserts', 'bin') - env['CC'] = os.path.join(llvm_dir, 'clang') - env['CXX'] = os.path.join(llvm_dir, 'clang++') + set_clang_env(env) env['npm_config_clang'] = '1' with scoped_cwd(dirname): args = [NPM, 'install'] @@ -175,10 +197,12 @@ def update_win32_python(): execute_stdout(['git', 'clone', PYTHON_26_URL]) -def build_libchromiumcontent(verbose, target_arch): +def build_libchromiumcontent(verbose, target_arch, defines): args = [os.path.join(SOURCE_ROOT, 'script', 'build-libchromiumcontent.py')] if verbose: args += ['-v'] + if defines: + args += ['--defines', defines] execute_stdout(args + ['--target_arch', target_arch]) @@ -226,9 +250,9 @@ def touch_config_gypi(): f.write(content) -def run_update(): +def run_update(defines): update = os.path.join(SOURCE_ROOT, 'script', 'update.py') - execute_stdout([sys.executable, update]) + execute_stdout([sys.executable, update, '--defines', defines]) if __name__ == '__main__': diff --git a/script/build-libchromiumcontent.py b/script/build-libchromiumcontent.py index 2409d0125c3f..e0a95f69a465 100755 --- a/script/build-libchromiumcontent.py +++ b/script/build-libchromiumcontent.py @@ -19,7 +19,7 @@ def main(): enable_verbose_mode() # ./script/bootstrap - # ./script/update -t x64 + # ./script/update -t x64 --defines='' # ./script/build --no_shared_library -t x64 # ./script/create-dist -c static_library -t x64 --no_zip script_dir = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', @@ -29,7 +29,8 @@ def main(): build = os.path.join(script_dir, 'build') create_dist = os.path.join(script_dir, 'create-dist') execute_stdout([sys.executable, bootstrap]) - execute_stdout([sys.executable, update, '-t', args.target_arch]) + execute_stdout([sys.executable, update, '-t', args.target_arch, + '--defines', args.defines]) execute_stdout([sys.executable, build, '-R', '-t', args.target_arch]) execute_stdout([sys.executable, create_dist, '-c', 'static_library', '--no_zip', '-t', args.target_arch]) @@ -39,6 +40,8 @@ def parse_args(): parser = argparse.ArgumentParser(description='Build libchromiumcontent') parser.add_argument('--target_arch', help='Specify the arch to build for') + parser.add_argument('--defines', default='', + help='The definetions passed to gyp') parser.add_argument('-v', '--verbose', action='store_true', help='Prints the output of the subprocesses') return parser.parse_args() diff --git a/script/update.py b/script/update.py index 33a4cff50f64..f820248d0aa2 100755 --- a/script/update.py +++ b/script/update.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import argparse import os import platform import subprocess @@ -23,6 +24,13 @@ def main(): return update_gyp() +def parse_args(): + parser = argparse.ArgumentParser(description='Update build configurations') + parser.add_argument('--defines', default='', + help='The definetions passed to gyp') + return parser.parse_args() + + def update_external_binaries(): uf = os.path.join('script', 'update-external-binaries.py') subprocess.check_call([sys.executable, uf]) @@ -60,6 +68,7 @@ def run_gyp(target_arch, component): mas_build = 1 else: mas_build = 0 + defines = [ '-Dlibchromiumcontent_component={0}'.format(component), '-Dtarget_arch={0}'.format(target_arch), @@ -67,6 +76,13 @@ def run_gyp(target_arch, component): '-Dlibrary=static_library', '-Dmas_build={0}'.format(mas_build), ] + + # Add the defines passed from command line. + args = parse_args() + for define in [d.strip() for d in args.defines.split(' ')]: + if define: + defines += ['-D' + define] + return subprocess.call([python, gyp, '-f', 'ninja', '--depth', '.', 'electron.gyp', '-Icommon.gypi'] + defines, env=env) diff --git a/vendor/brightray b/vendor/brightray index 3d168efd1d27..9a5b443e4953 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 3d168efd1d27d4ac3869beac6290c5066c392721 +Subproject commit 9a5b443e4953fa51ddd0a8d4739e60edf0a666a3