主要介绍本地如何编译、运行 servo

环境

  1. win 10 64 位
  2. 版本号 21H1
  3. 操作系统内部版本19043.1348

    教训

  4. 不要和自己过不去,servo 一定要和 .cargo 在同一个盘符

  5. 多看看 python/servo/build_commands.py
  6. 实在搞不定,重启试试,环境变量可能没生效
  7. 删了重新编译

    准备工作

  8. rustup 1.8+

  9. python 3.9+
    1. pip install virtualenv
  10. MSVC 安装时选择 complete
  1. git
  2. visual studio(二选一)

    1. choco

      1. choco install -y visualstudio2019buildtools --package-parameters="--add Microsoft.VisualStudio.Component.Roslyn.Compiler --add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.CoreBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.VC.CoreBuildTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.ATLMFC --add Microsoft.VisualStudio.Component.TextTemplating --add Microsoft.VisualStudio.Component.VC.CoreIde --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core --add Microsoft.VisualStudio.Workload.VCTools"
    2. visual studio build tolls 2019(Visual Studio Installer (UI))

      1. Desktop development with C++
      2. “MSVC”, “C++-ATL” and “C++-MFC”

        构建

  3. 开发版本

    1. ./mach build --dev
    2. ./mach run tests/html/about-mozilla.html
  4. 发布版本

    1. ./mach build --release
    2. ./mach run --release tests/html/about-mozilla.html
  5. 默认 build 会同时构建 servo 和 libsimpleservo,如果想用稍微快一点,可以试试:

    1. ./mach build -dev -p servo
  6. 构建检查,不进行构建

    1. ./mach check

    加速构建(build 命令会自动下载并配置)

    LLVM更快的链接时间

  7. 下载 LLVM

  8. 添加到环境变量
  9. 添加到 Cargo config(%USERPROFILE%.cargo\config)
    1. [target.x86_64-pc-windows-msvc]
    2. linker = "lld-link.exe"

    运行

    ```bash ./servo [url] [arguments] # if you run with nightly build ./mach run [url] [arguments] # if you run with mach

For example

./mach run https://www.google.com

<a name="TGBrM"></a>
### 命令行参数
```bash
-p INTERVAL turns on the profiler and dumps info to the console every INTERVAL seconds
-s SIZE sets the tile size for painting; defaults to 512
-z disables all graphical output; useful for running JS / layout tests
-Z help displays useful output to debug servo

快捷键

Ctrl+L opens URL prompt (Cmd+L on Mac)
Ctrl+R reloads current page (Cmd+R on Mac)
Ctrl+- zooms out (Cmd+- on Mac)
Ctrl+= zooms in (Cmd+= on Mac)
Alt+left arrow goes backwards in the history (Cmd+left arrow on Mac)
Alt+right arrow goes forwards in the history (Cmd+right arrow on Mac)
Esc or Ctrl+Q exits Servo (Cmd+Q on Mac)

FAQ

  1. No such file or directory: xx\venv\scripts\nt\python.exe
    1. python.exe pythonw.exe python.pdb pythonw.pdb 到指定目录
  2. Exception: Error populating virtualenv.
    1. 需要设置环境变量 PYTHON3=python.exe
  3. ModuleNotFoundError: No module named ‘mozversioncontrol’
    1. cargo 和 servo 不在一个盘符
  4. ERROR: could not find required GStreamer DLL

    # gstreamer 安装不完整,缺少以下依赖
    gst_dlls: avcodec-58.dll avfilter-7.dll avformat-58.dll avutil-56.dll swresample-3.dll
    GSTREAMER_PLUGINS: gstlibav.dll
    # 如下目录也有对应的依赖:
    C:\Users\xxx\servo\.servo\msvc-dependencies\gstreamer-uwp\1.16.0.5\x64\bin
    C:\Users\xxx\servo\.servo\msvc-dependencies\gstreamer-uwp\1.16.0.5\x64\lib\gstreamer-1.0
    
  5. 尽量不要构建两次,实在需要应该过滤重复的库

  6. waiting mozangle(build) for long time, but no response

    1. update mozangle 0.2 to 0.3
      # components/script/Cargo.toml
      mozangle = "0.2"
      # components/servo/Cargo.toml
      mozangle = {version = "0.3.1", features = ["egl"]}
      
  7. WARNING: could not find libEGL.dll and WARNING: could not find libGLESv2.dll

    不影响 build,可以通过修改 package_generated_shared_libraries 返回值忽略

    1. 原因可能是 mozangle-5109cbb033ab3fb1\out\gfx\angle\checkout\src\libEGL and libGLESv2 没有生成对应的 dll 文件
    2. 下载 官方每日构建版本,复制 libEGL.dll 和 libGLESv2.dll 到本地 servo_exe_dir 目录
  8. mach run 报错: assertion failed: (left != right)

    复制 libEGL.dll 和 libGLESv2.dll 到 servo_exe_dir 目录

 assertion failed: `(left != right)`
 left: `0x0`,
 right: `0x0` (thread main, at D:\.cargo\registry\src\github.com-1ecc6299db9ec823\surfman-0.4.1\src\platform\windows\angle\device.rs:206)
  1. build 运行时相关信息 ```bash

    python/servo/build_commands 打印以下信息

    sys.platform: win32

servo.exe 目录

servo_exe_dir: xx\servo\target\debug

build_path: ${servo_exe_dir}\build ```