WebKit is a world-recognized excellent open source browser kernel. It has the advantages of fast rendering speed, flexibility and customization, and multi-platform support. The well-known domestic Maxthon and UCWeb have selected WebKit as the browser core. Google and Apple have only built Chrome browser and Safari browser respectively based on WebKit.
Although WebKit has been increasingly accepted by programmers, its compilation process is very painful. Below I will share with you my experience in compiling WebKit code.
1) Get the WebKit source code
WebKit source code is managed using the Subversion tool. Therefore, anyone with a Subversion client can obtain the source code from http://svn.webkit.org/repository/webkit/trunk . However, this is not the best way. The code obtained through svn during the actual compilation process may cause you a lot of troubles. Therefore, I recommend downloading the WebKit source code tarball directly from WebKit's Nightly build. The specific address is: http://nightly.webkit.org/builds/trunk/src/1 It’s amazing that a project as big as WebKit still follows the principle of Daily Build.
At the time of writing this article, the version of WebKit source code is r52221, but I have not been able to successfully compile this version of WebKit in the past two days. The reason is that after a few minutes of opening a project using Visual Studio 2005, Visual Studio 2005 stops responding. I have tested version r50006, which is the first version starting with 5, and there is no such problem. The larger the version number, the newer the source code, and vice versa.
2) Construction of WebKit compilation environment
There is an article on the WebKit website that explains the environment construction of WebKit under the Windows platform: http://webkit.org/building/tools.html But this article is too simple. This is where WebKit most devastates people. After dozens of failures, I finally found a shortcut to my goal.
Hardware
It is best to find a computer with more than 2G of memory. Because the WebKit project is too large, hundreds of .obj files will be generated. When performing a link operation, approximately 1.6G of memory will be required. If your machine is installed with a memory-hungry operating system such as Vista, then wait until link.exe tells you "Out of memory". The memory of the machine I installed Vista on was only 2G, and I tried to link it several times without success. Finally, I was forced to compile in safe mode (I didn’t even dare to load the network card driver), and finally passed the test when the peak memory reached 1.99G. , it’s so exciting, so exciting.
Of course, the bigger the hard disk, the better, because the WebKit source code takes up 160M-190M of disk space after expansion, and the intermediate files generated by the compilation process require about 4G of storage space. In addition to the disk space occupied by Cygwin Visual Studio, etc., these are quite large. The most important thing is to reserve about 4G of space on the system disk.
In fact, using a multi-core CPU is also beneficial to compiling WebKit. The compilation script can call cl.exe to compile WebKit in parallel at the same time, which greatly shortens the compilation time.
Software
First you need to install Visual Studio 2005 SP1. If it is Vista or Window 7, you need to install SP1 update for vista. Visual C++ 2005 Express can also compile WebKit, but the Platform SDK needs to be installed separately. Practice has proven that WebKit can be compiled and passed on Platform 5.0 6.0.
This also raises a question, what if Visual Studio 2008 is already installed on your machine? Don't worry, Visual Studio 2005 and Visual Studio 2008 can coexist, and Visual Studio 2005 can be installed after Viusal Studio 2008. However, it should be noted that when Visual Studio 2005 is installed after Visual Studio 2008, WebKit's perl script will only go to "System DiskProgram FilesMicrosoft Visual Studio" to find the VC bin folder (that is, cl .exe folder). If the VS 2005 you installed is not on the system disk, you need to copy the VC bin folder to the directory on the system disk.
After installing Visual Studio 2005, you need to install another big piece of Cygwin. Cygwin actually simulates a Unix environment on Windows. It is best not to directly use the setup.exe file given on the Cygwin website when installing Cygwin. Instead, use the cygwin-downloader tool given on the WebKit.org website. cygwin-downloader will download 101 tools required to compile WebKit (there may be a few more now), such as perl, zlib, bash, etc. After the download is complete, run Cygwin's installation tool Setup.exe and choose to install from the local directory. Please pay attention! Cygwin needs to be installed under the system disk partition. If the C drive is the system disk, then Cygwin must be installed under C:cygwin. After the installation is completed, it will occupy approximately several hundred megabytes of space.
Next, what still needs to be installed is the QuickTime SDK. Some people say that you don't need to install the QuickTime SDK, but I found that if you don't install it, the QTMovie project in the WebKit solution will not be compiled successfully. QuickTime must be installed under:Program FilesQucikTime SDK on the system disk. Do not change the installation path.
Finally, after decompressing the WebKit source code file, you need to go to the webKit.org site to download the WebKitSupportLibrary.zip file. This file is a pre-compiled version of some third-party libraries on the Windows platform. For use when linking to WebKit. After downloading, the zip file does not need to be decompressed and can be placed directly in the root directory of WebKit.
Compilation steps
1) Set environment variables. Set WEBKITLIBRARIESDIR to the WebKit source code directoryWebKitLibrarieswin path; set WEBKITOUTPUTDIR to the output folder where you plan to store obj and dll. Of course, the partition where this folder is located must have at least 4G of remaining space.
2) Execute the update script. Please run the cygwin command line window on the desktop, and then use the CD command (the same as the DOS CD command) to jump to the WebKit source code directoryWebKitToolsScripts folder. For example, my WebKit source code is placed in the F drive, which is cd F:/WebKit/WebKitTools/Scripts/ and run the two scripts Update-WebKit and Update-WebKit-Support-libs in this directory. This step is not mentioned on many blogs. In fact, this step is the key to successful compilation.
3) After successfully executing the above two steps, you can use Visual Studio 2005 to open the WebKit.sln solution located in the WebKit source code directory WebKitwinWebKit.vcproj directory. This sln comes with six compilation configurations Debug, Debug_all, Debug_Cairo, Release, Debug_Internal, and Release_Cairo by default. The version compiled with Release uses Apple's own rendering engine, which is consistent with Safari's. The version compiled with Release_Cairo supports the Cairo rendering engine. This version can be run independently of Apple's environment, but it cannot be run in Apple's Safari environment. To monitor whether the compilation is successful, you can use the WinLauncher.exe application to load WebKit for testing.
I’ll write it here for now, and I’ll add more later if I think of anything.