Preface
It took two and a half days to compile a chrmomium project under linux.
There are some additional operations that are not available on official documents.
No matter which platform version of the chromium project is compiled, there is a strong feeling that their development machine is too slag:)
test
Official documents
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
chromium project compiled under linux, there is no good unofficial compilation data. Maybe I'll do one of these experiments.
The compilation process mainly looks at the official documents, and goes to google where compilation fails.
Installation environment requirements
Officially recommended Ubuntu 14.2 + 64 bits + 8 GB memory, I chose the newer Ubuntu 18.04.
Download OS Installation Media
ubuntu-18.04-desktop-amd64.iso
Installation of Virtual Machines
It should be tested on a real-time linxu machine, where downloading code from an official machine is 10 times faster than downloading code from a virtual machine. If you download the project code in the virtual machine, because of the timeout problem, the start code can not be downloaded.
There is no qualified Linux real machine, install a ubuntu18.04 virtual machine to complete the task of compiling chromium. I used the original code downloaded in win10, not runhooks version. If the code executed with runhooks is dependent on the win version, it will not compile under linux. The specific operation is described in the following test.
Virtual machine configuration, 8GB memory + 2*2 cpu + 200GB hard disk space
After the virtual machine is configured, the OS is not installed, the hard disk that has been configured is deleted, and a 200 GB hard disk is added. The disk space is pre-allocated and the disk file is saved as a complete file to improve the performance of the virtual machine.
Ubuntu 18.04 Installation Option = Normal Installation + Networking Update Software.
Choosing Chinese Language
After installation, update all the software that can be updated in the update manager.
Prepare compilation environment
Prepare a small ladder on the real machine, the virtual machine is installed, the default is NAT Internet access. At this time, Ubuntu 18.04 in the virtual machine can access the external network normally.
Open root user
After installing Ubuntu 18.04, root users are not turned on.
Configuring the compilation environment requires root identity or sudo when compiling chromium
So start the root user and change the root password.
sudo passwd root sudo passwd -u root
Cut to root users
su - root
Install vmtools
Copy the tar file on the CD to / home/dev, unlock it, and run that. pl as prompted by vmware.
Modify resolution
Resolution default is 800x600, the screen is too small, open a dialog box, can not see the confirmation button:) xrandr cvt 1280 800 xrandr --output Virtual1 --mode "1280x800" This method is temporary to change the resolution. After restarting the computer, it must be reset again.
Modify dns
Display application-all-settings-network=> Change dhcp to manual, fill in parameter bit 192.168.180.139, 255.255.255.0, 192.168.180.2, set DNS bit 8.8.8, 8.8.4.4, only retain ipv4, prohibit ipv6.
ping www.baidu.com
ping www.google.com
At this time, should be able to ping through, before going down.
Preparing test catalogue
Cut to root user mkdir /home/dev chmod 777 /home/dev # / home/dev is the catalogue of experiments cd /home/dev
Install Network Tools
Now ifconfig hasn't
apt install net-tools
Install git
Official tools download code using git
apt install git
Configure git
Because it's the first time to use it. git, To configure it git config --global user.name "my name" git config --global user.email "my-name@chromium.org" git config --global core.autocrlf false git config --global core.filemode false git config --global branch.autosetuprebase always
Install python
The official tool downloads the code and compiles the project with python
apt install python
Download official tools
cd /home/dev ping chromium.googlesource.com git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git If the progress is stuck, CTRL+C kills the process and comes back.
Add official tools to environmental variables
cp ~/.bashrc ~/.bashrc.bk vi ~/.bashrc # add /home/dev/depot_tools to PATH export PATH="$PATH:/home/dev/depot_tools"
Turn off the console, open a new console and cut it to the root user. echo $PATH You can see the full path of depot_tools, already in PATH.
Establishment of Engineering Catalogue
cd /home/dev mkdir ./chromium && cd ./chromium
Download code
fetch --nohooks chromium
Although the external network environment on the real machine is very good, after the virtual machine forwards one way, the performance degrades greatly.
In the real machine, ping www.google.com is 50ms, while in the virtual machine, ping www.google.com is 300ms~700ms.
This step was completed in the virtual machine, resulting in fetch timeout error. Code download speed is too slow (waited overnight, did not download much KB...). Or you can't download it at all (timeout).
Finally, I thought of a clumsy trick. I've compiled the win version of chrome and run fetch - nohooks chromium once again under win10 to get the original code without any modification. After tar is finished with 7zip software, it is copied to / home/dev /, through vmware shared folder (/ mnt/hgfs/chromium /), and then tar comes out.
Targeted Compressed Packet under win10 Decompression
ls@ubuntu18:/home/dev/chromium$ cp /mnt/hgfs/chromium/*.tar.* . /mnt/hgfs/chromium/*.tar.* yes win10 The next 7 zip Volume compression cat chromium.tar.* | tar -xv
ls@ubuntu18:/home/dev/chromium$ ls -a . chromium_dl_ok.tar.007 chromium_dl_ok.tar.015 chromium_dl_ok.tar.023 chromium_dl_ok.tar.031 .. chromium_dl_ok.tar.008 chromium_dl_ok.tar.016 chromium_dl_ok.tar.024 .gclient chromium_dl_ok.tar.001 chromium_dl_ok.tar.009 chromium_dl_ok.tar.017 chromium_dl_ok.tar.025 .gclient_entries chromium_dl_ok.tar.002 chromium_dl_ok.tar.010 chromium_dl_ok.tar.018 chromium_dl_ok.tar.026 src chromium_dl_ok.tar.003 chromium_dl_ok.tar.011 chromium_dl_ok.tar.019 chromium_dl_ok.tar.027 chromium_dl_ok.tar.004 chromium_dl_ok.tar.012 chromium_dl_ok.tar.020 chromium_dl_ok.tar.028 chromium_dl_ok.tar.005 chromium_dl_ok.tar.013 chromium_dl_ok.tar.021 chromium_dl_ok.tar.029 chromium_dl_ok.tar.006 chromium_dl_ok.tar.014 chromium_dl_ok.tar.022 chromium_dl_ok.tar.030
The effect of this dumb trick is the same as that of directly executing fetch --nohooks chromium in linux
When the download is completed, we also get two gclient configuration files and a project source directory.
.gclient .gclient_entries src
Using this original code to generate linux version project and compile linux version project, the final result is normal.
I've been thinking about this silly trick for a long time.
Download Tool Chain
cd /home/dev/chromium
gclient runhooks
At this point, in order to download the required tool chain software and dependency software from the code server and third-party server of the official network, it must be downloaded in the virtual machine (related to the real linux compilation environment). Fortunately, download at this step has retry function, as long as the external network connection is normal, download slowly can also be completed, download traffic is not so large, as if it is 1,2GB.
Synchronize the code again before Compilation
gclient sync
This step will check the integrity of the source code again (if the official code is updated or the code is not complete, the incremental part will be downloaded again) and runhooks (checking and updating tool chains and third-party software).
Generation of engineering documents
gn gen out/Default
This step was misreported.
ls@ubuntu18:/home/dev/chromium/src$ gn gen out/Default ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned non-zero exit code. pkgresult = exec_script(pkg_config_script, args, "value") ^---------- Current dir: /home/dev/chromium/src/out/Default/ Command: python -- /home/dev/chromium/src/build/config/linux/pkg-config.py -s /home/dev/chromium/src/build/linux/debian_sid_amd64-sysroot -a x64 pangocairo -v freetype Returned 1. stderr: Traceback (most recent call last): File "/home/dev/chromium/src/build/config/linux/pkg-config.py", line 232, in <module> sys.exit(main()) File "/home/dev/chromium/src/build/config/linux/pkg-config.py", line 139, in main prefix = GetPkgConfigPrefixToStrip(options, args) File "/home/dev/chromium/src/build/config/linux/pkg-config.py", line 80, in GetPkgConfigPrefixToStrip "--variable=prefix"] + args, env=os.environ) File "/usr/lib/python2.7/subprocess.py", line 216, in check_output process = Popen(stdout=PIPE, *popenargs, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory See //build/config/linux/pangocairo/BUILD.gn:9:3: whence it was called. pkg_config("pangocairo") { ^------------------------- See //ui/base/BUILD.gn:974:18: which caused the file to be included. configs += [ "//build/config/linux/pangocairo" ] ^--------------------------------
According to the information, the following components need to be installed.
sudo apt install libpango1.0-dev sudo apt install libcogl-pango-dev sudo apt install libjpeg-dev
Now the project file generation is successful
Start the compilation project
cd /home/dev/chromium/src
ninja -C out/Default chrome // first time
Watching the compilation start, happy, go to bed
Solving Compilation Error Problem
I wake up in the morning and see the compilation error stop.
ninja: Entering directory `out/Default' [4426/35533] ACTION //third_party/blink/renderer/core:make_core_generated_bison(//build/toolchain/linux:clang_x64) FAILED: gen/third_party/blink/renderer/core/xpath_grammar.cc gen/third_party/blink/renderer/core/xpath_grammar.h python ../../third_party/blink/renderer/build/scripts/rule_bison.py ../../third_party/blink/renderer/core/xml/xpath_grammar.y gen/third_party/blink/renderer/core bison Traceback (most recent call last): File "../../third_party/blink/renderer/build/scripts/rule_bison.py", line 83, in <module> returnCode = subprocess.call([bisonExe, '-d', '-p', prefix, inputFile, '-o', outputCpp]) File "/usr/lib/python2.7/subprocess.py", line 172, in call return Popen(*popenargs, **kwargs).wait() File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory [4431/35533] ACTION //third_party/angle/third_party/vulkan-valida...unique_objects_wrappers_helper(//build/toolchain/linux:clang_x64) ninja: build stopped: subcommand failed.
Solving the problem of error reporting
According to the error warning, when ubuntu18.04 is installed by default, there is no bison.
sudo apt install flex sudo apt install bison which flex /*Sanity check to make sure flex is installed*/ which bison /*Sanity check to make sure bison is installed*/
Continue to solve the problem of error reporting
[536/31103] ACTION //third_party/blink/renderer/core:make_core_generated_css_value_keywords(//build/toolchain/linux:clang_x64) FAILED: gen/third_party/blink/renderer/core/css_value_keywords.cc gen/third_party/blink/renderer/core/css_value_keywords.h python ../../third_party/blink/renderer/build/scripts/core/css/make_css_value_keywords.py ../../third_party/blink/renderer/core/css/CSSValueKeywords.json5 ../../third_party/blink/renderer/core/css/SVGCSSValueKeywords.json5 --output_dir gen/third_party/blink/renderer/core --gperf gperf Traceback (most recent call last): File "../../third_party/blink/renderer/build/scripts/core/css/make_css_value_keywords.py", line 75, in <module> json5_generator.Maker(CSSValueKeywordsWriter).main() File "../../third_party/blink/renderer/build/scripts/core/css/../../json5_generator.py", line 274, in main writer.write_files(args.output_dir) File "../../third_party/blink/renderer/build/scripts/core/css/../../json5_generator.py", line 242, in write_files self._write_file_if_changed(output_dir, generator(), file_name) File "../../third_party/blink/renderer/build/scripts/core/css/../../gperf.py", line 62, in generator_internal return generate_gperf(gperf_path, gperf_input, gperf_args) File "../../third_party/blink/renderer/build/scripts/core/css/../../gperf.py", line 45, in generate_gperf 127, gperf_args, output='Command not found.') subprocess.CalledProcessError: Command '['--key-positions=*', '-P', '-n', '-m', '50', '-D', '-Q', 'CSSValueStringPool']' returned non-zero exit status 127 ninja: build stopped: subcommand failed.
At first, I didn't see what components were not installed. First, try installing some system software.
sudo apt-get update sudo apt-get install autoconf sudo apt-get install libjson-perl sudo apt-get install emboss bioperl ncbi-blast+ gzip libjson-perl libtext-csv-perl libfile-slurp-perl liblwp-protocol-https-perl libwww-perl sudo apt install json which json
The same mistake
Finally, the gperf installed is normal.
sudo apt install gperf
Continue compilation
cd /home/dev/chromium
gclient sync
gn gen out/Default
cd /home/dev/chromium/src
autoninja -C out/Default chrome // second time
Compile successfully
At first, I was worried about which component was not installed in the middle, which caused compilation errors. It just depends on the compilation. From 8 a.m., compiled to 7 p.m., finally compiled.
Try to run the compiled output file
ls@ubuntu18:/home/dev/chromium/src$ ./out/Default/chrome
You can see that chromium is up and compiled successfully.
Follow-up issues
After compiling, I looked at the output file in / home/dev/chromium/src/out/Default, and found that there are hundreds of MB of executable files, so large?
To check, it's a problem caused by the compilation options with modulation symbols and debugging level. If the release version of debugging symbols is removed, the compiled output file (chromium + all so + all rc) is packaged, and only 40MB is needed.
When the compiler configuration is generated, the debugging symbols are removed, and the size after the build comes down.
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GaIYIzq6NGM
https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/AZZ04wssLoY/I2i53jg-CAAJ
Official gn Manual
Generating engineering files is generated by gn, which controls the command line of GN and removes debugging symbols.
https://www.chromium.org/developers/gn-build-configuration
Now there is no high-performance linux real machine, compiled too slowly, no further testing.
The compilation process is unbearable, compiling for more than 10 hours at a time.