Cross Compile Mozilla for Mingw32

It is possible to build Firefox for Windows using Linux as a development platform. Doing so is largely undocumented.  As of FF 61 (early 2018), the historical way of building Firefox with MinGW - using a MinGW-gcc toolchain - stopped working. The only way to build it today is to use a mingw-clang based toolchain, which is not very popular.

Therefore, building other Mozilla projects, such as Thunderbird, is even more experimental, and as of this writing hasn't even been attempted.

MinGW-clang x86 and x64 are currently a supported Tier 2 compilation target for Firefox.

Below are the canonical build scripts. To build Firefox with mingw-clang, you would need to replicate these instructions locally.

The mingw-clang cross-compiler

The MinGW-clang compiler is built using one of the following build scripts (whichever link works): https://searchfox.org/mozilla-central/source/taskcluster/scripts/misc/build-clang-7-mingw.sh or https://searchfox.org/mozilla-central/source/taskcluster/scripts/misc/build-clang-trunk-mingw.sh

You can download the toolchain directly using the following links:

x86: https://index.taskcluster.net/v1/task/gecko.cache.level-3.toolchains.v2.linux64-clang-7-mingw-x86.latest/artifacts/public/build/clangmingw.tar.xz

x64: https://index.taskcluster.net/v1/task/gecko.cache.level-3.toolchains.v2.linux64-clang-7-mingw-x64.latest/artifacts/public/build/clangmingw.tar.xz

Other mingw tools

fxc2 (and wine)

fxc is a shader compilation tool from Microsoft. It has no Linux equivalent, but we can get something working using wine and a command command-line program that wraps a Microsoft dll. You will need wine, which you can install from your normal package manager.

One can build it using either mingw-clang or mingw-gcc. For legacy reasons we build it currently with mingw-gcc; but intend to switch to mingw-clang.

$ git clone https://github.com/mozilla/fxc2.git && cd fxc2
$ make
# cp fxc2.exe /usr/local/bin/
# cp d3dcompiler_47.dll /usr/local/bin/
# cp /usr/local/i686-w64-mingw32/bin/libwinpthread-1.dll /usr/local/bin/

fxc2 version and build script

nsis

nsis version and build script

Configure Mozilla

You can get the source code following the instructions at here. After you have the source, create a .mozconfig file at the top level source directory.

Your mozconfig will need to replicate most of the mingw-clang mozconfig, which is located here for x86 and here for x64.

Build

Build it:

./mach build

The build should succeed - mingw-clang is a Tier 2 supported compilation target for Mozilla. There is a small chance that the build is broken right now (you can ask in #build) but it is more likely you haven't matched the exact versions/checkouts/configure flags. Because MinGW is not a robustly supported build target, deviating from what Mozilla specifies for any of those is risky. Review the build scripts in mozilla-central (linked above) and if you've matched the git checkout version of mingw-w64, compiler/binutils version, and configure flags, ask in #build.

Other troubles

Please ask in the newsgroup mozilla.dev.builds.

Document Tags and Contributors

Last updated by: tomrittervg,