Environment Setup for Building Webkit on Linux
Although I've always wanted to contribute to Webkit, I've often found the issues to be too difficult or too time-consuming to tackle amidst my regular workload. However, I recently found myself with enough free time after Rust Nation, and decided to take on an issue that seemed straightforward enough to contribute to. Indeed the Webkit wiki provides comprehensive information for contributors, I wanted to share my own steps and tips for setting up the environment in the hopes of helping future developers get started on Webkit more quickly and painlessly.
Choose git repo as Source
Back in the days, I used to download release tarballs to test and debug, only to discover that they could conflict with builds installed by package managers in my distribution. Even worse, their build scripts didn't provide an uninstall option, so once you run ninja install
, there's no turning back. Because of this, I recommend building from the git repository, even though it takes longer to build from scratch. This way, you can avoid conflicts with other builds and easily uninstall if necessary.
Since Webkit has migrated to git, it's really easy to access it. Their main upstream is now on Github!
git clone https://github.com/WebKit/WebKit.git WebKit
Installing Dependencies
Before starting to build the project, it's important to make sure that all dependencies are up-to-date. Luckily, Webkit provides a flatpak runtime and SDK to simplify this process. However, these files can be quite large and need to be re-downloaded each time a new version is released. The worst part is that download speeds can sometimes be painfully slow. I've tried changing DNS or using a VPN, but none of them helped. If you find that the download speed is unreasonably low, try rerunning the following command. Whole flatpak dependency could be 5+ GB and take hours to download.
Tools/Scripts/update-webkitgtk-libs
Building and Running
The steps to build and run Webkit are quite straightforward; you can follow the instructions provided on the project's wiki, specifically the build page). However, it's important to note that building the project can take several hours to complete. If you want to perform debug builds, simply pass --debug
to each command. But the debug build will run pretty slow:
Tools/Scripts/build-webkit --gtk
Tools/Scripts/run-minibrowser --gtk
The source code of mini browser demo can be found in Tools/MiniBrowser/gtk/main.c
. It has a custom url scheme minibrowser-about
. But if you type about:
it will also redirect to this scheme.
Webit can also perform incremental compilation. So if you just edit some GTK related files under Source/
, it should take a few minutes to compile again. But if you have to edit the interface of WebCore, it will need to relink the libraries and hence take several hours to compile again. Try some advices from this page, if you want to speed up the build time.
Debugging and Testing
When you start fixing some issues or adding some features, you might want to search the codebase. Since the codebase of Webkit is huge, I suggest just browse the code through https://searchfox.org/wubkat/source. Even using ripgrep can take minutes to do the job.
Debugging page on wiki has pretty good adivce about how to debug Webkit. There are two test suites that might relate to you when you need to perform some testing. And if you want specific test, simply add the path of the test to them:
Tools/Scripts/run-webkit-tests --gtk http/tests/media/video-play-stall.html
Tools/Scripts/run-gtk-tests WebKitBuild/GTK/Release/bin/TestWebKitAPI/WebKitGTK/TestWebKitWebContext
Contributing
Again, contributing page has detailed walkthrough about it. Basically, yo need to make sure the tests you would like to run have to pass at least. And then check your code obeys the code style guidline:
Tools/Scripts/check-webkit-style
If you haven't made any commit yet, be sure to run the checkout setup script:
Tools/Scripts/git-webkit setup
This will give you a commit template when you are adding commit. You'll just need to fill out the required information. The last thing to note is webkit only allow one commit per PR. So remember to squash or amend the commit when updating PRs.