[tbb-dev] Compiling Firefox with mingw-w64/clang

Georg Koppen gk at torproject.org
Mon Mar 26 11:53:00 UTC 2018


Hi all!

We need to switch away from our mingw-w64/gcc-based toolchain for our
Windows builds in the near future as Mozilla's Rust-based Stylo can't
get compiled with it anymore.[1]

We have time to do this switch during the ESR 60 cycle and I guess this
is needed, too, as I anticipate at least a bunch of reproducibility
issues and probably other bugs we have not found yet/not thought about.

I am not done yet with the Stylo bug but I thought I write up some
instructions for those who want to try out this new toolchain (and I
even know of someone already showing interest :) ).

I've been using https://github.com/mstorsjo/llvm-mingw. `master` should
basically work although I am right now still on commit
48af4af2c3f7aad1b0d58c82fe38c8d44996d912.

1) Building llvm/clang
----------------------

First we need to get all the needed llvm/clang/lld sources:

git clone https://github.com/llvm-mirror/llvm.git
cd llvm
git checkout ea4dd0b9197d95bd52b54f18666bdd8ff60238af
cd tools
git clone https://github.com/llvm-mirror/clang.git
git clone https://github.com/llvm-mirror/lld.git
cd clang
git checkout 09a80cc504e13cd931d86446f194d4a0ddf89e8f
cd ../lld
git checkout 1493087f49cd388f501f0b802ac7c1e1796d2f29
cd ../../../

Now, make sure you skip the arm and aarch64 targets in build-llvm.sh by
patching the script to use

-DLLVM_TARGETS_TO_BUILD="X86"

only. Then doing a /path/to/llvm-mingw/build-llvm.sh
/path/to/your/install/prefix should build all the things and install the
results in the prefix directory.

2) Dealing with the res format
------------------------------

Install the proper $ARCH-w64mingw32-windres binary with your Linux
package management tool and rename it to $ARCH-w64-mingw32-windresreal.
We need that as the tool LLVM provides (llvm-rc) is not mature enough to
deal with the res format. (This step is explained in the README.md)

3) Install the wrappers
-----------------------

Go into the llvm-mingw directory and patch install-wrappers.sh to
install the needed wrappers just for your architecture. E.g. if you are
building on x86_64, do

${ARCHS:=${TOOLCHAIN_ARCHS-x86_64}}

then run

./install-wrappers.sh /path/to/your/install/prefix


4) Build mingw-w64
------------------

First we need to get the mingw-w64 sources:

git clone git://git.code.sf.net/p/mingw-w64/mingw-w64
cd mingw-w64
git checkout 6c676fa4cf13e86127cb350349ced94ce4288497
cd ..

We use the build-mingw-w64.sh script in the llvm-mingw repo to build the
mingw-w64 part. There are two patches needed to this script

a) Again, as in 3) ARCHS need to get adapted.
b) Firefox does not compile using ucrtbase yet. So, we need to remove
'--with-def ault-msvcrt=ucrtbase' and 'FLAGS="$FLAGS
--with-default-msvcrt=ucrtbase"'

Now, again doing a /path/to/llvm-mingw/build-mingw-w64.sh
/path/to/your/install/prefix should build all the things and install the
results in the prefix directory.

5) Build compiler-rt
--------------------

The sources first again:

git clone https://github.com/llvm-mirror/compiler-rt.git
git checkout 97adb78eaae40595d052cfa76514db8256063bea
cd ..

Now, we use the build-compiler-rt.sh script in the llvm-mingw repo to
build the compiler-rt part. There are two patches needed to this script:

a) Again, as in 3) ARCHS need to get adapted.
b) If ARCHS does not include i686 then we can omit a respective symlink
by commenting it out ( #ln -sf i686-w64-mingw32 $PREFIX/i386-w64-mingw32 )

Then, doing a /path/to/llvm-mingw/build-compiler-rt.sh
/path/to/your/install/prefix should build all the things and install the
results in the prefix directory.

6) Building libcxx
------------------

Getting the sources

git clone https://github.com/llvm-mirror/libunwind.git
git clone https://github.com/llvm-mirror/libcxxabi.git
git clone https://github.com/llvm-mirror/libcxx.git
cd libunwind
git checkout 86ab23972978242b6f9e27cebc239f3e8428b1af
cd ../libcxxabi
git checkout 05ba3281482304ae8de31123a594972a495da06d
cd ../libcxx
git checkout a351d793abce1ecaead0fd947fe17f75b0c41ae5
cd ..

Now, we use the build-libcxx.sh script in the llvm-mingw repo to build
the all three pieces. Again, just the ARCHS part in it needs to get
adapted. Afterwards we can do /path/to/llvm-mingw/build-libcxx.sh
/path/to/your/install/prefix and it should build all the things and
install the results in the prefix directory.

That's it!

Now, pick a mozilla-central revision that still allows disabling Stylo
and use the .mozconfig and patches attached to the Mozilla bug[1] to get
the whole piece built.

Note, the above is from memory and looking at the scripts again.
Attached is the patch I have in my llvm-mingw repo. The commits outlined
in this mail are the ones I have used, though, as I needed to work
around some bugs.

The setup should not be too complicated but I am glad to help if anyone
got stuck.

Georg

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1390583
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-mingw.patch
Type: text/x-patch
Size: 3896 bytes
Desc: not available
URL: <http://lists.torproject.org/pipermail/tbb-dev/attachments/20180326/db97c258/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.torproject.org/pipermail/tbb-dev/attachments/20180326/db97c258/attachment.sig>


More information about the tbb-dev mailing list