1、系统要求
内存:最低4GB,推荐8GB+。
磁盘空间:至少40GB的可用磁盘空间。
操作系统:Windows10。
2、系统准备
下载安装Visual Studio 2019的构建工具,选择以下项目安装:
选项卡:使用C++进行桌面开发
单个组件:
-
MSVC v143 - VS 2022 C++ x64/x86 构建工具。
-
Windows 10 SDK(至少10.0.19041.0)。
-
用于 v143 构建工具(x86 和 x64)的 C++ ATL。
3、安装MozillaBuild
下载MozillaBuildSetup-Latest后默认安装就可以。
如果后面安装是更低版本的firefox可选择更低的MozillaBuild,具体可以查看MozillaBuild - MozillaWiki
在后面使用时都要在MozillaBuild环境下进行操作,你可以通过运行C:\mozilla-build\start-shell.bat来启动它。
4、下载源码
可以先查看下firefox当前所有的发行版本:
4.1、方法一
运行start-shell.bat,在其命令行环境中运行如下命令:
cd c:/
mkdir mozilla-source
cd mozilla-source
wget https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py
python3 bootstrap.py
bootstrap.py脚本会自动下载源码以及它需要的其他依赖项,这可能会需要一点时间。
更多的可能是会出现网络连接失败、下载依赖出错的情况。
网络连接失败的话需要有你有访问外网的能力,如果网络没问题,你可以重试几次。
如果是依赖出错的话,就要特殊处理了,见7、异常
4.2、方法二
运行start-shell.bat,运行命令如下:
mkdir mozilla-source
cd mozilla-source
hg clone https://hg.mozilla.org/mozilla-central
单纯clone源码,如果你需要其他版本可以使用hg update来切换。
开发版本可以用hg tags来查看
确定好源码后,再检查依赖,这步很关键,要不然后面的编译就会有问题。
./mach bootstrap
构建类型有4种
Firefox for Desktop Artifact Mode
Firefox for Desttop
GeckoView/Firefox for Android Artifact Mode
GeckoView/Firefox for Android
如果你只修改Firefox前端,就选择Artifact Mode。这里我要做Firefox桌面版本前后端修改,选择第二项。
如果都没出错中止,那后面直接编译运行就好了。
5、编译
./mach build
6、运行
./mach run
7、异常
7.1、依赖异常
最常见的就是依赖库找不到,对应的可以上这个页面查找https://firefox-ci-tc.services.mozilla.com/tasks/groups/IAX5qDepSDyGb-wntxG8RQ
然后修改如下两处代码:
taskcluster\taskgraph\util\taskcluster.py
def get_index_url(index_path, use_proxy=False, multiple=False):
index_tmpl = liburls.api(get_root_url(use_proxy), "index", "v1", "task{}/{}")
res = index_tmpl.format("s" if multiple else "", index_path)
if index_path.find('.win64-node-10.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-node-10.latest'
elif index_path.find('.win32-fix-stacks.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win32-fix-stacks.latest'
elif index_path.find('.win32-minidump-stackwalk.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win32-minidump-stackwalk.latest'
elif index_path.find('.win64-clang-cl-11.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-clang-11.latest'
elif index_path.find('.win64-clang-tidy.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-clang-tidy.latest'
elif index_path.find('.win64-cbindgen.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-cbindgen.latest'
elif index_path.find('.win64-nasm.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-nasm.latest'
elif index_path.find('.win64-sccache.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-sccache.latest'
elif index_path.find('.rustc-dist-toolchain.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.rustc-dist-toolchain.latest'
elif index_path.find('.clang-dist-toolchain.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.clang-dist-toolchain.latest'
elif index_path.find('.win64-dump-syms.hash.') > 0 :
res = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-dump-syms.latest'
print('taskcluster/taskgraph/util/taskcluster.py:188====>', res)
return res
python\mozbuild\mozbuild\artifact_commands.py
name = os.path.basename(artifact_name)
artifact_url = get_artifact_url(
task_id,
artifact_name,
use_proxy=not artifact_name.startswith("public/"),
)
if artifact_url.find('node.tar.bz2') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-node-10.latest/artifacts/public/build/node.tar.zst'
name = 'node.tar.zst'
elif artifact_url.find('fix-stacks.tar.bz2') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win32-fix-stacks.latest/artifacts/public/build/fix-stacks.tar.zst'
name = 'fix-stacks.tar.zst'
elif artifact_url.find('minidump_stackwalk.tar.xz') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win32-minidump-stackwalk.latest/artifacts/public%2Fbuild%2Fminidump-stackwalk.tar.zst'
name = 'minidump-stackwalk.tar.zst'
elif artifact_url.find('cbindgen.tar.bz2') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-cbindgen.latest/artifacts/public%2Fbuild%2Fcbindgen.tar.zst'
name = 'cbindgen.tar.zst'
elif artifact_url.find('nasm.tar.bz2') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-nasm.latest/artifacts/public%2Fbuild%2Fnasm.tar.zst'
name = 'nasm.tar.zst'
elif artifact_url.find('sccache.tar.bz2') > 0 :
artifact_url = 'https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.cache.level-3.toolchains.v3.win64-sccache.latest/artifacts/public%2Fbuild%2Fsccache.tar.zst'
name = 'sccache.tar.zst'
super(ArtifactRecord, self).__init__(
artifact_url, name, None, digest, algorithm, unpack=True
)
重新检查依赖就可以了。