WPEWebKit2.46调试环境
以下讨论均基于`https://github.com/WebPlatformForEmbedded/WPEWebKit的
commit 38067c965fd39dbc4294c1be8f9394fb4c39d90c (HEAD -> wpe-2.46, origin/wpe-2.46, origin/HEAD)
Author: Philippe Normand <philn@igalia.com>
Date: Tue Nov 1 15:51:24 2022 +0000
pointer-lock WIP
编译
之前已经编过几次,最近一次:WebKit调试环境配置 - 赵裕的博客。
这一次的不同:
- 上次是安装依赖后自己定义的cmake……本次从官方编译脚本切入
- 上次是Devcloud(CentOS 8)+Docker,这次是Ubuntu24+Docker,完全是本地的环境,预期是Docker编出来本机能直接跑
安装镜像,启动容器:
sudo docker pull ubuntu:24.04
sudo docker run -v /home/vimerzhao/research:/home/vimerzhao/research \
-d --privileged -it --cpus 16 --name research_webkit ubuntu:24.04 /bin/bash
参考这个文章:Building Options - WebKit Documentation:
Building the WPE Port¶
For production builds:
cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja
sudo ninja install
For development builds:
Tools/wpe/install-dependencies
Tools/Scripts/update-webkitwpe-libs
Tools/Scripts/build-webkit --wpe --debug
进入Docker,安装依赖:
$ apt update # 必需
$ Tools/wpe/install-dependencies
安装依赖遇到一个错误但好像没什么影响:
Created symlink /etc/systemd/system/sysinit.target.wants/systemd-pstore.service → /usr/lib/systemd/system/systemd-pstore.service.
Initializing machine ID from random generator.
/usr/lib/tmpfiles.d/systemd-network.conf:10: Failed to resolve user 'systemd-network': No such process
/usr/lib/tmpfiles.d/systemd-network.conf:11: Failed to resolve user 'systemd-network': No such process
/usr/lib/tmpfiles.d/systemd-network.conf:12: Failed to resolve user 'systemd-network': No such process
/usr/lib/tmpfiles.d/systemd-network.conf:13: Failed to resolve user 'systemd-network': No such process
/usr/lib/tmpfiles.d/systemd.conf:22: Failed to resolve group 'systemd-journal': No such process
/usr/lib/tmpfiles.d/systemd.conf:23: Failed to resolve group 'systemd-journal': No such process
/usr/lib/tmpfiles.d/systemd.conf:28: Failed to resolve group 'systemd-journal': No such process
/usr/lib/tmpfiles.d/systemd.conf:29: Failed to resolve group 'systemd-journal': No such process
/usr/lib/tmpfiles.d/systemd.conf:30: Failed to resolve group 'systemd-journal': No such process
Creating group 'systemd-journal' with GID 999.
Creating group 'systemd-network' with GID 998.
准备环境,这一步下载比较多,并默认使用了WebKitBuild
目录:
$ Tools/Scripts/update-webkitwpe-libs
Downloading six-1.16.0...
Installed six-1.16.0!
............
Nothing to do.
Installing from webkit-sdk org.webkit.Platform x86_64 23.08
Looking for matches…
ID Branch Op Remote Download
1. [✓] org.freedesktop.Platform.GL.default 23.08 i webkit-sdk 163.5 MB / 486.2 MB
2. [✓] org.freedesktop.Platform.GL.default 23.08-extra i webkit-sdk 17.8 MB / 486.2 MB
3. [✓] org.webkit.Platform.Locale 23.08 i webkit-sdk 166.0 MB / 1.5 GB
4. [✓] org.webkit.Platform 23.08 i webkit-sdk 510.1 MB / 1.5 GB
Installation complete.
Installing from webkit-sdk org.webkit.Sdk x86_64 23.08
Looking for matches…
ID Branch Op Remote Download
1. [✓] org.webkit.Sdk.Locale 23.08 i webkit-sdk 43.8 MB / 1.5 GB
2. [—] org.webkit.Sdk 23.08 i webkit-sdk 4.3 MB / 2.7 GB
Installing 2/2… █▌ 8% 432.4 kB/s 01:55
Installation complete.
SDK version: 296715@main
Updating icecc/sccache standalone toolchain archives
Error connecting: Cannot autolaunch D-Bus without X11 $DISPLAY
Failed to get a11y address Command '('gdbus', 'call', '-e', '-d', 'org.a11y.Bus', '-o', '/org/a11y/bus', '-m', 'org.a11y.Bus.GetAddress')' returned non-zero exit status 1.
error: Could not connect: No such file or directory
The following command returned a non-zero exit status: flatpak run --user --die-with-parent --filesystem=host --allow=devel --share=network --talk-name=org.gtk.vfs --talk-name=org.gtk.vfs.* --device=all --device=dri --share=ipc --socket=pulseaudio --socket=session-bus --socket=system-bus --socket=wayland --socket=x11 --system-talk-name=org.a11y.Bus --system-talk-name=org.freedesktop.GeoClue2 --talk-name=org.freedesktop.Flatpak --talk-name=org.freedesktop.secrets --env=TEST_RUNNER_INJECTED_BUNDLE_FILENAME=/app/webkit/WebKitBuild/Release/lib/libTestRunnerInjectedBundle.so --env=PATH=/usr/lib/sdk/llvm18/bin:/usr/bin:/usr/lib/sdk/rust-stable/bin/ --env=TZ=America/Los_Angeles --unset-env=LC_CTYPE --command=/usr/bin/which org.webkit.Sdk gcc
Output: b''
以上错误是Docker中没有D-Bus和X11,Deepseek整理解决如下:
apt install -y dbus
apt install dbus-x11
apt install at-spi2-core
# 启动 D-Bus 服务
dbus-daemon --system --fork # 系统级服务
# 启动 DBus 用户会话(容器内需执行)
dbus-launch --sh-syntax # 用户级会话
# copy result to bash
# 验证服务状态
dbus-send --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListNames
gdbus call -e -d org.a11y.Bus -o /org/a11y/bus -m org.a11y.Bus.GetAddress
再次执行可能遇到这个错误:
bwrap: Creating new namespace failed: Operation not permitted
这也是Docker的原因,所以启动时加了--privileged
,正常执行完Tools/Scripts/update-webkitwpe-libs:
root@05f21ec27f2e:/home/vimerzhao/research/WPEWebKit# ./Tools/Scripts/update-webkitwpe-libs
Ensuring the local Flatpak repository is not corrupted
[20/22] Verifying webkit-sdk:runtime/org.webkit.Platform/x86_64/23.08…
Checking remotes...
Pruning objects
Updating Flatpak environment
Looking for updates…
Nothing to do.
SDK version: 296715@main
root@05f21ec27f2e:/home/vimerzhao/research/WPEWebKit#
再就是编译Tools/Scripts/build-webkit --wpe --debug
,可能遇到:
-- Disabling ENABLE_WPE_PLATFORM_DRM since USE_GBM is disabled.
CMake Error at Source/cmake/WebKitFeatures.cmake:324 (message):
ENABLE_WPE_PLATFORM conflicts with ENABLE_WPE_1_1_API. You must disable
one or the other.
Call Stack (most recent call first):
Source/cmake/WebKitFeatures.cmake:332 (_WEBKIT_OPTION_ENFORCE_CONFLICTS)
Source/cmake/WebKitFeatures.cmake:357 (_WEBKIT_OPTION_ENFORCE_ALL_CONFLICTS)
Source/cmake/OptionsWPE.cmake:150 (WEBKIT_OPTION_END)
Source/cmake/WebKitCommon.cmake:237 (include)
CMakeLists.txt:16 (include)
关掉ENABLE_WPE_1_1_API
即可,等待编译….
跑的东西太多,一卡一卡的:
运行
根本运行不起来…集中在以下几错误
$ Tools/Scripts/run-minibrowser --debug --jsc-only
Unsupported platform. at Tools/Scripts/old-run-minibrowser line 46.
# 原因是python脚本写的有问题,默认走了Ma平台
这个DBus一直失败,猜测是Docker编译,Host运行锅
$ ./run-minibrowser --debug --port=jsc-only --platform=wpe
ERROR: Failed to make thread real time: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dio_2derror_2dquark.Code1: Could not map tid: Process ids could not be found: 77
/app/webkit/Source/WTF/wtf/linux/RealTimeThreads.cpp(224) : void WTF::RealTimeThreads::realTimeKitMakeThreadRealTime(uint64_t, uint64_t, uint32_t)
$sudo ./run-minibrowser --debug --port=jsc-only --platform=wpe
ERROR: Failed to connect to RealtimeKit: Error spawning command line “dbus-launch --autolaunch=9b32a4a3b5394933a484f7caa10e0223 --binary-syntax --close-stderr”: Child process exited with code 1
/app/webkit/Source/WTF/wtf/linux/RealTimeThreads.cpp(192) : void WTF::RealTimeThreads::realTimeKitMakeThreadRealTime(uint64_t, uint64_t, uint32_t)
先不折腾了,直接Host编译。这个套编译脚本,后面再慢慢研究五今天是搞不定……..
本机编译
还是重复上面步骤
安装完成。
Installing from flathub org.freedesktop.Platform.GL.Debug.default x86_64 23.08-extra
寻找匹配项…
ID 分支 操作 远程 下载
1. [✓] org.freedesktop.Platform.GL.Debug.default 23.08-extra i flathub 691.5 MB / 699.9 MB
安装完成。
SDK version:
Updating icecc/sccache standalone toolchain archives
Created /home/vimerzhao/research/WPEWebKit/WebKitBuild/UserFlatpak/Toolchains/webkit-sdk-gcc-7b9bee4f2b5d32b5fbfb556c0889131d.tar.gz self-contained toolchain archive
Created /home/vimerzhao/research/WPEWebKit/WebKitBuild/UserFlatpak/Toolchains/webkit-sdk-clang-78eb8e141520124fff551fbef1a57caf.tar.gz self-contained toolchain archive
No authentication token provided. Re-run this with the -t option if an sccache token was provided to you. Skipping sccache configuration for now.
运行时还是报错
~/research/WPEWebKit (wpe-2.46 ✗) Tools/Scripts/run-minibrowser --debug --wpe
Using Cog as MiniBrowser
miniBrowser: /app/webkit/WebKitBuild/WPE/Debug/Tools/cog-prefix/src/cog-build/launcher/cog
(cog:17): Cog-Core-WARNING **: 18:31:06.748: cog_modules_get_preferred: cannot find module 'wpe'
(cog:17): Cog-Core-WARNING **: 18:31:06.749: cog_modules_get_preferred: preferred module 'wpe' not supported
(cog:17): Cog-Core-ERROR **: 18:31:06.749: Requested platform 'wpe' not usable.
ScriptError raised: Failed to run "['/app/webkit/WebKitBuild/WPE/Debug/Tools/cog-prefix/src/cog-build/launcher/cog', '--platform=wpe']" exit_code: -5 cwd: /app/webkit
Traceback (most recent call last):
File "/app/webkit/Tools/Scripts/webkitpy/minibrowser/run_webkit_app.py", line 68, in main
return port.run_minibrowser(browser_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
研究了下脚本和Cog,最后发现是文档说的启动方式不对,cog要指定平台(可用平台参见源码的docs文档):
$ Tools/Scripts/run-minibrowser --debug --wpe -- --platform=wl vimerzhao.top
需要注意的是这个错误日志依然存在,但不影响运行了:
ERROR: Failed to make thread real time: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dio_2derror_2dquark.Code1: Could not map tid: Process ids could not be found: 20
/app/webkit/Source/WTF/wtf/linux/RealTimeThreads.cpp(224) : void WTF::RealTimeThreads::realTimeKitMakeThreadRealTime(uint64_t, uint64_t, uint32_t)
可以了:
想着下GTK的Port试试能不能运行,结果编译问题比较多,猜测是WPEWebKit这个工程根本就不兼容GTK,毕竟不是官方Webkit库,浪费了不少时间,一起编译不过……
那如果想跑JSC呢?按文档肯定是不行的:
$ Tools/Scripts/run-minibrowser --debug --jsc-only
Unsupported platform. at Tools/Scripts/old-run-minibrowser line 46.
这是为什么呢,首先Tools/Scripts/webkitpy/port/factory.py的platform_options()
没有处理--jsc-only
,导致以下逻辑:
#没有平台,默认Mac
# Tools/Scripts/webkitpy/minibrowser/run_webkit_app.py
if not options.platform:
options.platform = "Mac"
# MacPort没有实现,用的Port::run_minibrowser,实JscOnlyPort也没有实现
# Tools/Scripts/webkitpy/port/base.py
def run_minibrowser(self, args):
# FIXME: Migrate to webkitpy based run-minibrowser. https://bugs.webkit.org/show_bug.cgi?id=213464
miniBrowser = self.path_to_script("old-run-minibrowser")
args.append(self._config.flag_for_configuration(self.get_option('configuration')))
args.append("--%s" % self.get_option('platform')
故此走到时了old-run-minibrowser
:
if (isAppleCocoaWebKit()) {
printHelpAndExitForRunAndDebugWebKitAppIfNeeded();
exit exitStatus(runMiniBrowser());
} else {
die "Unsupported platform."
}
为什么调用WPE时还要传个-- --platform=wl
,由两处脚本都可窥见
# Tools/Scripts/webkitpy/minibrowser/run_webkit_app.py
def main(argv):
option_parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
usage="%(prog)s [options] [url] [-- [minibrowser_options]]",
epilog="MiniBrowser options: Pass them after two dashes.\n Example:"
"{spaces}run-minibrowser --wpe -- --platform=drm http://url.com".format(spaces=" " * 14))
groups = [("Platform options", platform_options()), ("Configuration options", configuration_options())]
# Tools/Scripts/webkitpy/port/wpe.py
def run_minibrowser(self, args):
miniBrowser = None
if self.browser_name() == "cog":
miniBrowser = self.cog_path_to('launcher', 'cog')
if not self._filesystem.isfile(miniBrowser):
_log.warning("Cog not found 😢. If you wish to enable it, rebuild with `-DENABLE_COG=ON`. Falling back to good old MiniBrowser")
miniBrowser = None
else:
print("Using Cog as MiniBrowser")
has_platform_arg = any((a == "-P" or a.startswith("--platform=") for a in args)) or "COG_PLATFORM_NAME" in os.environ
if not has_platform_arg:
args.insert(0, "--platform=gtk4") # 注意里
即使修正了也无法解决,看来要运行jsc按文档不不通的:
$ldd WebKitBuild/WPE/Debug/bin/jsc| grep not
libicudata.so.73 => not found
libicui18n.so.73 => not found
libicuuc.so.73 => not found
$ find . -iname "libicudata*"
./WebKitBuild/UserFlatpak/runtime/org.webkit.Platform/x86_64/23.08/e60e56a804768009bfde900c006a10c5c1cd00d8625cb5f64bd828671110c596/files/lib/x86_64-linux-gnu/libicudata.so.73
./WebKitBuild/UserFlatpak/runtime/org.webkit.Platform/x86_64/23.08/e60e56a804768009bfde900c006a10c5c1cd00d8625cb5f64bd828671110c596/files/lib/x86_64-linux-gnu/libicudata.so.73.2
./WebKitBuild/UserFlatpak/runtime/org.webkit.Sdk/x86_64/23.08/231a3d32baa6acd540820ba80965cc524a32911d0bce73f067d5d76ccb0f26dd/files/lib/x86_64-linux-gnu/libicudata.so.73
./WebKitBuild/UserFlatpak/runtime/org.webkit.Sdk/x86_64/23.08/231a3d32baa6acd540820ba80965cc524a32911d0bce73f067d5d76ccb0f26dd/files/lib/x86_64-linux-gnu/libicudata.so.73.2
./WebKitBuild/UserFlatpak/runtime/org.webkit.Sdk/x86_64/23.08/231a3d32baa6acd540820ba80965cc524a32911d0bce73f067d5d76ccb0f26dd/files/lib/x86_64-linux-gnu/libicudata.so
# 但设置LD_LIBRARY_PATH后,运行直接在load so时就Crash了....
# 感觉正确的做法应该是实现JscPort,在flatpak中启动...
实现如下:
class JscOnlyPort(GLibPort):
port_name = "jsc-only"
def __init__(self, *args, **kwargs):
super(JscOnlyPort, self).__init__(*args, **kwargs)
def run_minibrowser(self, args):
# get error path: app/webkit/WebKitBuild/JSCOnly/Debug/bin/jsc
# jsc = self._build_path('bin', 'jsc')
# so,wirte (right) static path:
jsc = "/app/webkit/WebKitBuild/WPE/Debug/bin/jsc"
if not self._filesystem.isfile(jsc):
print("error")
command = [jsc]
env, pass_fds = self.setup_sysprof_for_minibrowser()
if self._should_use_jhbuild():
command = self._jhbuild_wrapper + command
return self._executive.run_command(command + args, cwd=self.webkit_base(), stdout=None, return_stderr=False, decode_output=False, env=env, pass_fds=pass_fds)
成功了(没有了直接运行的Crash……):
$ Tools/Scripts/run-minibrowser --debug --jsc-only
>>>
总结
之前祼编,运行时一直卡在wayland,用cog启动确实没有这些问题了。但比较坑的是文档和脚本完全对不上,如果不具体了解细节,即使编译成功了也很难启动