Skip to content

Commit f2a8e18

Browse files
authored
msys2: Recommend correct cmake package (#59001)
msys2 ships 2 different cmake packages, one built natively (with mingw prefix in the package name) and one built against the posix emulation environment. The posix emulation one does not work because it will detect unix-style paths, which it then writes into files that native tools process. Unlike during command invocation (where the msys2 runtime library does path translation), when paths are written to files, they are written verbatim. The practical result of this is that e.g. the LLVM build will fail with a mysterious libz link failure (as e.g. reported in #54981). This is our fault, because our built instructions tell the user to install the wrong one. Fix all that by 1. Correcting the build instructions to install the correct cmake 2. Detecting if the wrong cmake is installed and advising the correct one 3. Fixing an issue where the native CMake did not like our CMAKE_C_COMPILER setting. With all this, CMake runs correctly under msys2 with USE_BINARYBUILDER_LLVM=0.
1 parent 7a8d0e4 commit f2a8e18

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Make.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,10 @@ export PKG_CONFIG_PATH = $(JULIAHOME)/usr/lib/pkgconfig
431431
export PKG_CONFIG_LIBDIR = $(JULIAHOME)/usr/lib/pkgconfig
432432

433433
# Figure out OS and architecture
434-
BUILD_OS := $(shell uname)
434+
RAW_BUILD_OS = $(shell uname)
435+
BUILD_OS := $(RAW_BUILD_OS)
435436

436-
ifneq (,$(findstring CYGWIN,$(BUILD_OS)))
437+
ifneq (,$(findstring CYGWIN,$(RAW_BUILD_OS)))
437438
XC_HOST ?= $(shell uname -m)-w64-mingw32
438439
endif
439440

deps/tools/common.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ CMAKE_CC := "$$(which $(shell echo $(CC_ARG) | cut -d' ' -f1))"
3838
CMAKE_CXX := "$$(which $(shell echo $(CXX_ARG) | cut -d' ' -f1))"
3939
CMAKE_CC_ARG := $(shell echo $(CC_ARG) | cut -s -d' ' -f2-)
4040
CMAKE_CXX_ARG := $(shell echo $(CXX_ARG) | cut -s -d' ' -f2-)
41+
else ifneq (,$(findstring MINGW,$(RAW_BUILD_OS)))
42+
# `cmake` is mingw-native and needs `cygpath -w`, rather than `cygpath -m`, which is the msys2 conversion default
43+
CMAKE_CC := "$(shell echo $(call cygpath_w, $(shell which $(CC_BASE))))"
44+
CMAKE_CXX := "$(shell echo $(call cygpath_w, $(shell which $(CXX_BASE))))"
45+
CMAKE_CC_ARG := $(CC_ARG)
46+
CMAKE_CXX_ARG := $(CXX_ARG)
4147
else
4248
CMAKE_CC := "$$(which $(CC_BASE))"
4349
CMAKE_CXX := "$$(which $(CXX_BASE))"
@@ -68,6 +74,14 @@ else
6874
$(error Unknown CMake generator '$(CMAKE_GENERATOR)'. Options are 'Ninja' and 'make')
6975
endif
7076

77+
# Detect MSYS2 with cygwin CMake rather than MinGW cmake - the former fails to
78+
# properly drive MinGW tools
79+
ifneq (,$(findstring MINGW,$(RAW_BUILD_OS)))
80+
ifneq (,$(shell ldd $(shell which cmake) | grep msys-2.0.dll))
81+
override CMAKE := echo "ERROR: CMake is Cygwin CMake, not MinGW CMake. Build will fail. Use 'pacman -S mingw-w64-{i686,x86_64}-cmake'."; exit 1; $(CMAKE)
82+
endif
83+
endif
84+
7185
# If the top-level Makefile is called with environment variables,
7286
# they will override the values passed above to ./configure
7387
MAKE_COMMON := DESTDIR="" prefix=$(build_prefix) bindir=$(build_depsbindir) libdir=$(build_libdir) shlibdir=$(build_shlibdir) libexecdir=$(build_libexecdir) datarootdir=$(build_datarootdir) includedir=$(build_includedir) sysconfdir=$(build_sysconfdir) O=

doc/src/devdocs/build/windows.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,19 @@ Note: MSYS2 requires **64 bit** Windows 7 or newer.
141141
4. Then install tools required to build julia:
142142

143143
```
144-
pacman -S cmake diffutils git m4 make patch tar p7zip curl python
144+
pacman -S diffutils git m4 make patch tar p7zip curl python
145145
```
146146

147147
For 64 bit Julia, install the x86_64 version:
148148

149149
```
150-
pacman -S mingw-w64-x86_64-gcc
150+
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake
151151
```
152152

153153
For 32 bit Julia, install the i686 version:
154154

155155
```
156-
pacman -S mingw-w64-i686-gcc
156+
pacman -S mingw-w64-i686-gcc mingw-w64-i686-cmake
157157
```
158158

159159
5. Configuration of MSYS2 is complete. Now `exit` the MSYS2 shell.

0 commit comments

Comments
 (0)