llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.53k stars 11.79k forks source link

[windows] Cmake llvm build of MinGW under Cygwin fails: Posix filesystem calls. #19764

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 19390
Version trunk
OS Windows 2000
Reporter LLVM Bugzilla Contributor
CC @dommldomml,@sebpop

Extended Description

A CMake build using MinGW under CYGWIN fails in FileSystem.h. This is due to the LLVM source code using Posix filesystem calls when LLVM_ON_UNIX is true.

Since MinGW can be used on both Cygwin/Unix, and Windows there is a conflict. LLVM assumes that LLVM_ON_UNIX means that all posix filesystem calls are present.

Since Mingw doesn't support posix filesystem calls, the build breaks early in:

include/llvm/Support/FileSystem.h

The information to identify this case is in CMakeCCompiler.cmake.

The final definition of the flags is in LLVMConfig.cmake

set(LLVM_ON_UNIX 1)
set(LLVM_ON_WIN32 0)

For MinGW, LLVM_ON_UNIX must be false and LLVM_ON_WIN32 must be true.

Linux or Windows is not quite correct for this case. A new HAVE_POSIX, segragating the filesystem headers and api's would be more correct. This is a bit more extensive involving source code, cmake build, and autoconf build.

Since mingw current builds with LLVM_ON_WIN32 set this way, the trivial change should work.

The Host and Compiler information regarding Cygwin and MinGW are all present in CMakeCCompiler.cmake for a starting point.

The variables needed by the build are set in LLVMConfig.cmake.

a5fec13e-39c8-49b2-b3dd-e7d891b4dfc7 commented 4 years ago

According to my experiments, this problem arises from the fact that the build tools are compiled with the native cygwin compiler as the build tools like tblgen must understand cygwin paths.

This would not be a problem in itself, but the native c++ is called with -std=c++14 which disables all posix functions. Using -std=gnu++14 cures this behavior.

For my compilation, I compiled all failed files manually with -std=gnu++14, then the build proceeded much further - running into new problems later.

carlo-bramini commented 3 months ago

Nowadays, it seems that LLVM can be successfully built with MinGW under CYGWIN. I'm using this toolchain file:

SET(CMAKE_SYSTEM_NAME Windows)
SET(TOOLCHAIN_PREFIX "x86_64-w64-mingw32")
SET(COMPILER_PREFIX ${TOOLCHAIN_PREFIX}/sys-root/mingw)
SET(PKG_CONFIG_EXECUTABLE ${TOOLCHAIN_PREFIX}-pkg-config)
FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${TOOLCHAIN_PREFIX}-gcc)
FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${TOOLCHAIN_PREFIX}-g++)
FIND_PROGRAM(CMAKE_RC_COMPILER NAMES ${TOOLCHAIN_PREFIX}-windres)
SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_SYSTEM_PROCESSOR x64)

This is the command used in bash:

$ cmake ../llvm-project/llvm -G Ninja -DCMAKE_BUILD_TYPE=Release -Wno-dev -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=mingw64.cmake

The build process completed successfully, by mixing some CYGWIN building for POSIX and native building from MinGW:

[304/3617] Configuring NATIVE LLVM...
[304/3617] Building native llvm-min-tblgen...
[187/187] Linking CXX executable bin/llvm-min-tblgen.exe
[330/3617] Building native llvm-config...
[18/18] Linking CXX executable bin/llvm-config.exe
[3617/3617] Linking CXX executable bin/obj2yaml.exe

CYGWIN version: CYGWIN_NT-10.0-19045 GCC: gcc version 11.4.0 (GCC) MinGW x86_64: gcc version 11.4.0 (GCC)

Tested with current version 19.0.0git at the time of writing. In my opinion, this issue could be closed since it is resolved to me.