2025-02-22

久しぶりに Firefox のビルドに挑戦してみた

なんでしょう、一度は挫折しているのにまた同じことを繰り返してしまうのは。

きっけかは

Linux Mint 版の Firefox(deb)は -O3 でコンパイルされているので純正よりも動作がキビキビしているのです。

が、さらに自分でビルドして -march=native を付け足してさらにキビキビさせてみたいんです。



懲りずにやってみた

以前にも試したことがあったのですが、その時は Debian 12 に配布されている rustc のバージョンが古くてあきらめたようなのですが、普通は rustup で最新バージョンを導入するみたいですね。

https://rustup.rs/

ということで、今回は Rust は 1.85 が用意できました。 

$ rustc --version
rustc 1.85.0 (4d91de4e4 2025-02-17)

$ cargo --version
cargo 1.85.0 (d73d2caf9 2024-12-31)

そしてソースコードの準備も整ったので、いざコンパイルというかビルドです。

$ CFLAGS="-O3 -march=native" CXXFLAGS="${CFLAGS}" ./mach build

どうだ。

0:07.52 W Adding make options from /mnt/DATA/myfox/mozilla-unified/mozconfig
    MOZ_PARALLEL_BUILD=6
    MOZ_OBJDIR=/mnt/DATA/myfox/mozilla-unified/obj-x86_64-pc-linux-gnu
    OBJDIR=/mnt/DATA/myfox/mozilla-unified/obj-x86_64-pc-linux-gnu
    FOUND_MOZCONFIG=/mnt/DATA/myfox/mozilla-unified/mozconfig
    export FOUND_MOZCONFIG
 0:07.52 /usr/bin/gmake -f client.mk -j6 -s
 0:08.10 Ignoring exception unpickling cache file /home/xxxxxxxx/.mozbuild/package-frontend/artifact_url-cache.pickle: FileNotFoundError(2, 'No such file or directory')
 0:17.06 git: 'cinnabar' is not a git command. See 'git --help'.
 0:17.09 git: 'cinnabar' is not a git command. See 'git --help'.
 0:17.09 Error running mach:
 0:17.09     mach --log-no-times artifact install --no-tests
 0:17.09 The error occurred in code that was called by the mach command. This is either
 0:17.09 a bug in the called code itself or in the way that mach is calling it.
 0:17.09 You can invoke ``./mach busted`` to check if this issue is already on file. If it
 0:17.09 isn't, please use ``./mach busted file artifact`` to report it. If ``./mach busted`` is
 0:17.09 misbehaving, you can also inspect the dependencies of bug 1543241.
 0:17.09 If filing a bug, please include the full output of mach, including this error
 0:17.09 message.
 0:17.09 The details of the failure are as follows:
 0:17.16 subprocess.CalledProcessError: Command '['/usr/bin/git', 'cinnabar', 'git2hg', 'd353d87d81d

はい、エラー。

う〜ん、git cinnabar が使えないのが原因ですかね?

bootstrap.py のログを見返してみると、なんか手動で PATH 設定が必要だったようです。

To add git-cinnabar to the PATH, edit your shell initialization script, which
may be called ~/.bash_profile or ~/.profile, and add the following
lines:

    export PATH="/home/xxxxxxxx/.mozbuild/git-cinnabar:$PATH"

Then restart your shell.

「ええ〜、それくらい自動で設定してよぉ」と思いながらも指示に従って PATH 設定を追加してみます。 

さて、準備が整ったのでもう一度ビルドを試してみます。

 0:44.98 W 0 compiler warnings present.
 0:45.00 W Overall system resources - Wall time: 44s; CPU: 13%; Read bytes: 69632; Write bytes: 74825728; Read time: 4; Write time: 1890
To view a profile of the build, run |mach resource-usage|.
 0:45.00 Your build was successful!
To take your build for a test drive, run: |mach run|
For more information on what to do now, see https://firefox-source-docs.mozilla.org/setup/contributing_code.html

Artifact Mode を選択したからか、1 分もかからずに終わってしまいました。これだと -O3 とか -march=native がほとんど効いてないですよね。

でもまあ、ひとまずできあがった Firefox を起動してみます。

Firefox Nightly 137.0a1 ができあがりました

試しに Speedometor 3 で計測してみたところ、普段使っている安定版より若干だけ数値が低かったのですが、操作感はこちらの Nightly の方がスムーズな感じもします。安定版が 135 で、Nightly が 137 というバージョンの違いなのかもしれません。

Artifact Mode でないソースコードで再コンパイルするとだいぶ時間がかかるだろうし、日々の運用としてこれを続けていく自身はないですねぇ。

 

 

と、前回と同じような結論になったのにどうしてまた挑戦したんですかね、自分。

これだったら PPA を追加して公式が用意した Firefox Nightly を使う方が楽チンなのではと思い始めました。