Science: Google Chrome is based on Chromium, an open source project, so the Chromium project is the product of Chrome itself.

Environment depends on

First, make sure your network environment has access to Google’s developer-oriented services, including but not limited to:

  • *.appspot.com
  • *.github.com
  • *.googlesource.com
  • *.googleapis.com

This is the root cause of more than 99% of the errors reported during the whole process.

Second, make sure your Mac meets the following requirements:

  1. The ARM version of the Mac
  2. System version: 10.15.4+
  3. Xcode version: 12.2+ (because the compilation process relies on the clang compiler provided by Xcode)
  4. MacOS 11.0 SDK, this can be done by running lsxcode-select -p/ Platforms/MacOSX. Platform/Developer/SDKs to confirm

Download the build tool chain: DepTool

Deptool is a suite of tools to download and build the Chromium project, as well as other Google open source projects such as V8.

Use git to clone depTool project locally:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Copy the code

Command line tools such as fetch and gclient can now be accessed and executed using absolute paths, but can be added to your ~/.zshrc for convenience later:

export PATH="$PATH:/path/to/depot_tools"
Copy the code

When done, test the fetch command on the command line to see if it is available:

which fetch
Copy the code

Download the Chromium project code

Because gClient, Fetch and other tools are also dependent on Git in the process of core code download, there are suggestions to adjust git global Settings as follows:

git config --global http.postBuffer 524288000
git config --global core.precomposeUnicode true
Copy the code

Because chrommium project has a long history, git repository huge, for faster completion of the download code, you can ignore the history of the way to submit code pull:

fetch --no-history chromium
Copy the code

The domestic network may fail to pull due to unstable factors. It doesn’t matter. If the pull fails due to network reasons, you can use this command to continue the breakpoint transmission:

gclient sync
Copy the code

After repeated breakpoints, finally complete download, can start local compilation ~

The compiler

Google’s C++ projects mostly use ninja, a cross-platform compiler that calls apple’s clang compiler on the MAC.

Google also provides GN to generate ninjaFile based on the current environment. Autoninja compiles ninjaFile from the ninjaFile configuration file without setting any parameters.

The specific process is as follows:

gn gen out/Default
Copy the code

The out directory will now generate a list of parameters and configurations required to compile Chrome, and the compilation will begin (the whole process will take about 4-5 hours) :

autoninja -C out/Default chrome
Copy the code

Autoninja is actually much faster than it used to be. When I first compiled Chromium a few years ago, IT took me a whole night to compile it using the crappy official documentation.

Compilation is complete, you will see that appeared in the out directory. / out/Default/Chromium. The app/Contents/MacOS/Chromium such an executable file, command-line execution can be directly, will open your own native compilation of Chromium, The first opening speed is slow

The C++ code entry file for Mac is this:

src/chrome/app/chrome_exe_main_mac.cc

You can print STD ::cout to stdout in this file, but since Chrome is multi-process architecture, there is no direct output or debugging in child processes.

For debugging, check out: My Nuggets homepage

In addition, welcome friends who are interested in crawling to pay attention to my open source project Webster. The project uses Node.js combined with Chrome Headless mode to achieve a high availability web crawler crawling framework, so that Chrome can render the page. Can grab all js and Ajax rendered asynchronous content in a page; Combined with Redis, a task queue is implemented to make the crawler easily extend horizontally and vertically. It’s easy to deploy, and I’ve provided an official version of the basic runtime Docker image for Webster. If you want to get a sneak peek, you can also try the Webster Demo Docker image.

Reference source

The trampling notes in this article are from:

How to obtain The Chromium source code

Official documentation: Build Chromium project guide on Mac