Building WebKit Sensibly
WebKit builds can take a lot of space and time to build on Haiku.
To those working on WebKit, welcome! This blog post is primarily for those working on HaikuWebKit, Haiku’s fork of WebKit, but it may also be useful for you.
I will be covering some techniques that are useful to reduce the size of build files without significant disadvantages. I’ll also cover how to speed up linking.
There are some more techniques that can further reduce space such as shallow cloning and sparse checkouts that I won’t be discussing here. Maybe in a future blog post? With all the techniques combined, I’ve managed to get WebKit’s code and build in around 12 GB.
Compiling
Vanilla debug builds can be huge. This is due to the lack of build optimization and the inclusion of debug information.
Optimization level
By default, debug builds are unoptimized. But a little bit of optimization can, IIRC, reduce the build size by two or three times! In this case -Og
is a good optimization level since it doesn’t affect compilation time or debuggability significantly but yields a significant size reduction.
To use the -Og
optimization level add the following to Source/cmake/OptionsHaiku.cmake:
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Og")
This code won’t run unless the build is a debug build. Make sure you pass the --debug
option to build-webkit.
Debugging information
A quick test suggests that debugging information can double the size of the build! Also, debugging information can take a lot of memory for Debugger to load. I’m guessing that if debugging information is enabled everywhere, it could take at least 24 GB memory before Debugger has loaded all of the information! It makes sense, then, to only include debugging information for the folders you care about. So, start off by disabling debugging information everywhere by adding the following to Source/cmake/OptionsHaiku.cmake:
string(REPLACE "-g" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
Enabling debugging information for a subdirectory should then be as simple as adding the -g
flag to the CMAKE_CXX_FLAGS_DEBUG
variable. Unfortunately, the Debugger fails to read the source code lines in that case (likely a bug), so it is necessary to specify -gdwarf-4
. So, to enable debugging information for a directory, add the following to that directory’s CMakeLists.txt or PlatformHaiku.cmake file:
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -gdwarf-4")
Linking
By default, debug builds, and maybe release builds, attempt to use lld when possible. So, simply installing lld should suffice. Note that cmake must be rerun in order for the build system to recognize its existence and start using it. My tests show that this reduces recompilation times from 30 minutes to 1 minute for a small change.
Zardshard's blog
- [GSoC 2024] Porting WebKit2 Final Report
- [GSoC 2024] Can I get discuss.haiku-os.org to work?
- [GSoC 2024] Implementing Mouse Support
- [GSoC 2024] Drawing to the Screen!
- [GSoC 2024] Fixing IPC in WebKit
- [GSoC 2024] Fixing the crashing
- Building WebKit Sensibly
- [GSoC 2024] Plans for Fixing Haiku's WebKit2 Port
- [GSoC 2023] Improving Icon-O-Matic Final Report
- [GSOC 2023] Progress on perspective transformation