anlex N | 70844c8 | 2024-04-24 18:49:31 +0800 | [diff] [blame] | 1 | # Building and using `gn` with MinGW on Windows |
| 2 | |
| 3 | At the time of writing: 2024-04-13 |
| 4 | Test environment: Windows 11, intel x86_64 CPU |
| 5 | |
| 6 | ## Requirements |
| 7 | |
| 8 | 1. Install [MSYS2](https://www.msys2.org/) |
| 9 | 1. Start a Terminal windows for MSYS2's MinGW development by opening one of `clang32.exe`, `clang64.exe`, `clangarm64.exe`,`mingw32.exe`, `mingw64.exe`, `ucrt64.exe`. |
| 10 | 1. To download clang toolchain, Ninja and git programs, run command: `pacman -S mingw-w64-clang-x86_64-toolchain mingw-w64-clang-x86_64-ninja git` |
| 11 | |
| 12 | ## Build `gn` |
| 13 | |
| 14 | 1. To clone `gn` source code, run command: `git clone https://gn.googlesource.com/gn` |
| 15 | 1. Run command: `cd gn` |
| 16 | 1. Run command: `build/gen.py --platform mingw` |
| 17 | This configuration generates a static executable that does not depend on MSYS2, and can be run in any development environment. |
| 18 | Use `--help` flag to check more configuration options. |
| 19 | Use `--allow-warning` flag to build with warnings. |
| 20 | 1. Run command: `ninja -C out` |
| 21 | |
| 22 | ## Testing |
| 23 | |
| 24 | 1. Run command: `out/gn --version` |
| 25 | 1. Run command: `out/gn_unittests` |
| 26 | |
| 27 | > Notes: |
| 28 | > |
| 29 | > For "mingw-w64-clang-x86_64-toolchain" in the clang64 environment, g++ is a copy of clang++. |
| 30 | > |
| 31 | > The toolchain that builds `gn` does not use vendor lock-in compiler command flags, |
| 32 | > so `gn` can be built with these clang++, g++. |
| 33 | > |
| 34 | > However the build rules in [examples/simple_build](../examples/simple_build/) require GCC-specific compiler macros, and thus only work in the `ucrt64` MSYS2 development environment. |