在Windows系统上编译Thorium浏览器的完整指南

在Windows系统上编译Thorium浏览器的完整指南

thorium Chromium fork named after radioactive element No. 90. Windows and MacOS/Raspi/Android/Special builds are in different repositories, links are towards the top of the README.md. thorium 项目地址: https://gitcode.com/gh_mirrors/th/thorium

前言

Thorium是一款基于Chromium开源项目的高性能浏览器,通过优化编译参数和启用特定指令集,能够提供比标准版Chromium更出色的性能表现。本文将详细介绍在Windows系统上从零开始编译Thorium浏览器的完整流程。

环境准备

1. 安装必要工具

首先需要准备以下工具和环境:

  1. Visual Studio 2019/2022:必须包含"使用C++的桌面开发"工作负载
  2. Windows 10 SDK:版本10.0.20348.0及其调试工具
  3. depot_tools:Google提供的构建工具集合

2. Visual Studio安装配置

使用以下命令安装必要的VS组件(假设VISUAL_STUDIO_INSTALLER是VS安装程序路径):

VISUAL_STUDIO_INSTALLER --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Component.VC.ATLMFC --includeRecommended

3. 安装Windows SDK调试工具

如果通过VS安装程序安装了Windows 10 SDK,还需要单独安装调试工具:

  1. 打开控制面板→程序→程序和功能
  2. 选择"Windows软件开发工具包"
  3. 点击"更改"
  4. 勾选"Windows调试工具"
  5. 完成安装

构建环境配置

1. 设置系统环境变量

  1. C:\src\depot_tools添加到PATH环境变量最前面
  2. 添加DEPOT_TOOLS_WIN_TOOLCHAIN变量并设为0
  3. 添加NINJA_SUMMARIZE_BUILD变量并设为1

2. Git全局配置

执行以下命令配置Git:

git config --global user.name "您的姓名"
git config --global user.email "您的邮箱"
git config --global core.autocrlf false
git config --global core.filemode false
git config --global branch.autosetuprebase always

获取源代码

1. 获取Chromium代码

  1. 创建并进入工作目录:
    mkdir chromium && cd chromium
    
  2. 获取Chromium代码:
    fetch chromium
    

2. 同步代码库

进入v8目录并执行同步:

cd src/v8
git checkout -f origin/main
cd ..
git checkout -f origin/main
git rebase-update
git fetch --tags
gclient sync --with_branch_heads --with_tags -f -R -D
gclient runhooks

Thorium特定配置

1. 获取Thorium源代码

git clone --recursive https://github.com/Alex313031/thorium.git

2. 更新PGO配置文件

PGO(Profile Guided Optimization)是重要的性能优化手段:

python3 tools/update_pgo_profiles.py --target=win64 update --gs-url-base=chromium-optimization-profiles/pgo_profiles

3. 配置构建参数

  1. 编辑win_args.gn文件,更新PGO配置文件路径
  2. 可选:添加API密钥以启用Google同步等功能

4. 覆盖Chromium源代码

将Thorium的以下目录覆盖到Chromium源代码目录:

  • ash, base, build, chrome, components
  • content, extensions, media, net
  • sandbox, third_party, tools, ui, v8
  • BUILD.gn

构建过程

1. 生成构建配置

gn args out\thorium

将编辑好的win_args.gn内容粘贴到打开的编辑器中并保存。

2. 复制Thorium特定资源

需要手动复制以下资源文件:

  • content_shell\thorium-devtools.ico
  • content_shell\thorium-devtools.png
  • pak_src\bin\pak-win目录下的所有文件

3. 开始编译

autoninja -C out\thorium chrome chromedriver thorium_shell setup mini_installer -j8

其中-j8表示使用8个线程编译,应根据CPU核心数调整。

构建变体

1. AVX2版本构建

  1. 获取Thorium-AVX2源代码
  2. 覆盖build目录
  3. 使用win_AVX2_args.gn配置文件

2. 便携版制作

  1. 解压现有的便携版模板
  2. 清空BIN目录
  3. 解压新构建的mini_installer
  4. 将chrome.7z中的内容复制到BIN目录
  5. 更新版本信息和相关脚本

代码更新

1. 更新Chromium代码

cd src/v8
git checkout -f origin/main
cd ..
git checkout -f origin/main
git rebase-update
git fetch --tags
gclient sync --with_branch_heads --with_tags -f -R -D
gclient runhooks

2. 更新Thorium代码

通过git pull或重新下载最新代码包更新Thorium代码。

结语

通过上述步骤,您可以在Windows系统上成功构建Thorium浏览器。构建过程可能需要较长时间和大量系统资源,建议在性能较好的机器上进行。构建完成后,您将获得一个高度优化的浏览器版本,相比标准Chromium能提供更好的性能表现。

thorium Chromium fork named after radioactive element No. 90. Windows and MacOS/Raspi/Android/Special builds are in different repositories, links are towards the top of the README.md. thorium 项目地址: https://gitcode.com/gh_mirrors/th/thorium

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时武鹤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值