Building and using gn with MinGW on Windows
At the time of writing: 2024-04-13 Test environment: Windows 11, intel x86_64 CPU
Requirements
- Install MSYS2
- 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. - 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
Build gn
- To clone
gnsource code, run command:git clone https://gn.googlesource.com/gn - Run command:
cd gn - Run command:
build/gen.py --platform mingw
This configuration generates a static executable that does not depend on MSYS2, and can be run in any development environment.
Use--helpflag to check more configuration options.
Use--allow-warningflag to build with warnings. - Run command:
ninja -C out
Testing
- Run command:
out/gn --version - Run command:
out/gn_unittests
Notes:
For "mingw-w64-clang-x86_64-toolchain" in the clang64 environment, g++ is a copy of clang++.
The toolchain that builds
gndoes not use vendor lock-in compiler command flags, sogncan be built with these clang++, g++.However the build rules in examples/simple_build require GCC-specific compiler macros, and thus only work in the
ucrt64MSYS2 development environment.