Skip to content

Instantly share code, notes, and snippets.

@equalsraf
Last active November 10, 2021 09:54
Show Gist options
  • Save equalsraf/6cc26951981fa254b53a80cf73eaf47d to your computer and use it in GitHub Desktop.
Save equalsraf/6cc26951981fa254b53a80cf73eaf47d to your computer and use it in GitHub Desktop.
New instructions for building nvim in Windows

[WIP]

Windows/MSYS2

In Windows we build using the toolchain provided by MSYS2 - the resulting binaries DO NOT link against the MSYS2 runtime.

Start by installing the necessary dependencies

pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-libtool mingw-w64-x86_64-cmake \
mingw-w64-x86_64-make mingw-w64-x86_64-perl mingw-w64-x86_64-python2 \
mingw-w64-x86_64-pkg-config mingw-w64-x86_64-unibilium gperf

Building in cmd.exe

Set your PATH to include the mingw64 tools

set PATH=c:\msys64\mingw64\bin;%PATH%

The following is not always required, but sometimes mingw32-make fails to invoke the correct compiler

set CC=gcc

Build using the MinGW Makefiles generator

mkdir .deps
cd .deps
cmake  -G "MinGW Makefiles" ..\third-party\
mingw32-make
cd ..
mkdir build
cd build
cmake -G "MinGW Makefiles" -DGPERF_PRG="C:\msys64\usr\bin\gperf.exe" ..
mingw32-make

Building inside the MSYS2 MinGW64 shell

To build from inside the MinGW64 shell install mingw64-x86_64-lua51-mpack and use the MSYS Makefiles generator.

mkdir .deps
cd .deps
cmake -G "MSYS Makefiles" -DUSE_BUNDLED_LUAROCKS=NO ../third-party
make
cd ..
mkdir build
cd build
cmake -G "MSYS Makefiles" ..
make

Currently there is no way to run tests and some development tasks inside the MSYS2 shell, because .bat files cannot be executed there, and path conversions do not work well with some of the lua tools.

mingw and python greenlet

see python-greenlet/greenlet#20

@alexeRadu
Copy link

I've tried to build neovim for msys2 with the exact commands but I got this:

$ cmake -G "MSYS Makefiles" ..
-- The C compiler identification is GNU 10.1.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_INSTALL_PREFIX=C:/Program Files (x86)/nvim
-- CMAKE_BUILD_TYPE not specified, default is 'Debug'
-- MIN_LOG_LEVEL not specified, default is 1 (INFO)
-- Replacing -O3 in CMAKE_C_FLAGS_RELEASE with -O2
-- Performing Test HAS_OG_FLAG
-- Performing Test HAS_OG_FLAG - Success
-- Performing Test HAS_ACCEPTABLE_FORTIFY
-- Performing Test HAS_ACCEPTABLE_FORTIFY - Success
-- Performing Test HAVE_EXECINFO_BACKTRACE
-- Performing Test HAVE_EXECINFO_BACKTRACE - Failed
-- Performing Test HAVE_BUILTIN_ADD_OVERFLOW
-- Performing Test HAVE_BUILTIN_ADD_OVERFLOW - Success
-- Performing Test HAS_WIMPLICIT_FALLTHROUGH_FLAG
-- Performing Test HAS_WIMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test HAS_WVLA_FLAG
-- Performing Test HAS_WVLA_FLAG - Success
-- Performing Test HAVE_FNO_COMMON
-- Performing Test HAVE_FNO_COMMON - Success
-- Performing Test HAS_DIAG_COLOR_FLAG
-- Performing Test HAS_DIAG_COLOR_FLAG - Success
-- Found PkgConfig: C:/msys64/mingw64/bin/pkg-config.exe (found version "0.29.2")
-- Looking for dlopen in dl
-- Looking for dlopen in dl - not found
-- Looking for kstat_lookup in kstat
-- Looking for kstat_lookup in kstat - not found
-- Looking for kvm_open in kvm
-- Looking for kvm_open in kvm - not found
-- Looking for gethostbyname in nsl
-- Looking for gethostbyname in nsl - not found
-- Looking for perfstat_cpu in perfstat
-- Looking for perfstat_cpu in perfstat - not found
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Looking for sendfile in sendfile
-- Looking for sendfile in sendfile - not found
-- Found LibUV: C:/msys64/home/radu/neovim/.deps/usr/lib/libuv.a (Required is at least version "1.28.0")
-- Found Msgpack: C:/msys64/home/radu/neovim/.deps/usr/lib/libmsgpackc.a (found suitable version "3.0.0", minimum required is "1.0.0")
-- Found LibLUV: C:/msys64/home/radu/neovim/.deps/usr/lib/libluv.a (Required is at least version "1.30.0")
-- Found LuaJit: C:/msys64/home/radu/neovim/.deps/usr/lib/libluajit.a
-- Performing Test MSGPACK_HAS_FLOAT32
-- Performing Test MSGPACK_HAS_FLOAT32 - Success
-- Found UNIBILIUM 2.1.0
-- Performing Test UNIBI_HAS_VAR_FROM
-- Performing Test UNIBI_HAS_VAR_FROM - Success
-- Found LibTermkey: C:/msys64/home/radu/neovim/.deps/usr/lib/libtermkey.a (Required is at least version "0.18")
CMake Warning at cmake/LibFindMacros.cmake:195 (message):
  The find module for LIBVTERM does not provide version information, so we'll
  just assume that it is OK.  Please fix the module or remove package version
  requirements to get rid of this warning.
Call Stack (most recent call first):
  cmake/FindLIBVTERM.cmake:10 (libfind_process)
  CMakeLists.txt:434 (find_package)


-- Found LIBVTERM
-- Found Winpty: C:/msys64/home/radu/neovim/.deps/usr/lib/winpty.lib (Required is at least version "0.4.3")
-- Found Iconv
-- Performing Test HAVE_WORKING_LIBINTL
-- Performing Test HAVE_WORKING_LIBINTL - Success
-- Looking for _nl_msg_cat_cntr
-- Looking for _nl_msg_cat_cntr - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Checking Lua interpreter: C:/msys64/home/radu/neovim/.deps/usr/bin/luajit.exe
C:/msys64/home/radu/neovim/.deps/usr/bin/luajit.exe: module 'lpeg' not found:
        no field package.preload['lpeg']
        no file '.\lpeg.lua'
        no file 'C:\msys64\home\radu\neovim\.deps\usr\bin\lua\lpeg.lua'
        no file 'C:\msys64\home\radu\neovim\.deps\usr\bin\lua\lpeg\init.lua'
        no file '.\lpeg.dll'
        no file 'C:\msys64\home\radu\neovim\.deps\usr\bin\lpeg.dll'
        no file 'C:\msys64\home\radu\neovim\.deps\usr\bin\loadall.dll'
stack traceback:
        [C]: at 0x66df24d0
        [C]: at 0x00402130
-- [C:/msys64/home/radu/neovim/.deps/usr/bin/luajit.exe] The 'lpeg' lua package is required for building Neovim
-- Checking Lua interpreter: C:/msys64/mingw64/bin/lua5.1.exe
C:/msys64/mingw64/bin/lua5.1.exe: module 'bit' not found:
        no field package.preload['bit']
        no file '.\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.1\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.1\bit\init.lua'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.1\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.1\bit\init.lua'
        no file '.\bit.dll'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.1\bit.dll'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.1\loadall.dll'
stack traceback:
        [C]: ?
        [C]: ?
-- [C:/msys64/mingw64/bin/lua5.1.exe] The 'bit' lua package is required for building Neovim
-- Checking Lua interpreter: C:/msys64/mingw64/bin/lua.exe
C:/msys64/mingw64/bin/lua.exe: module 'bit' not found:
        no field package.preload['bit']
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.3\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.3\bit\init.lua'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.3\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.3\bit\init.lua'
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.3\\bit.lua'
        no file 'C:\msys64\mingw64\bin\..\share\lua\5.3\\bit\init.lua'
        no file '.\bit.lua'
        no file '.\bit\init.lua'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.3\bit.dll'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.3\..\lib\lua\5.3\\bit.dll'
        no file 'C:\msys64\mingw64\bin\..\lib\lua\5.3\loadall.dll'
        no file '.\bit.dll'
stack traceback:
        [C]: in function 'require'
        [C]: in ?
-- [C:/msys64/mingw64/bin/lua.exe] The 'bit' lua package is required for building Neovim
CMake Error at CMakeLists.txt:506 (message):
  Failed to find a Lua 5.1-compatible interpreter


-- Configuring incomplete, errors occurred!
See also "C:/msys64/home/radu/neovim/build/CMakeFiles/CMakeOutput.log".
See also "C:/msys64/home/radu/neovim/build/CMakeFiles/CMakeError.log".

@equalsraf
Copy link
Author

FYI this gist was written years ago.

As for your error - nvim requires an working version of lua with some specific modules installed. In your case it is failing to find

  • lpeg
  • bit (in some systems i think this is called bitop, and it is available in luajit)

@alexeRadu
Copy link

I know that this is old but I tried. Do you know if anybody has built nvim on msys2/mingw? Or if there is any plan for such a build?

@equalsraf
Copy link
Author

Neovim does build for mingw, but the release version builds with MSVC. It has been a while and a lot has changed but this is the script that builds it for the CI - Some dependencies are installed via msys pacman,

https://github.com/neovim/neovim/blob/master/ci/build.ps1#L62

while the others are downloaded and built from source by recipes in the neovim source repo

https://github.com/neovim/neovim/blob/master/ci/build.ps1#L137

The neovim recipe uses msys2 to get a working build environment, but it doesn't really build from inside the msys2 shell.

Last i checked these instructions worked https://github.com/neovim/neovim/wiki/Building-Neovim#windows--msys2

@alexeRadu
Copy link

Thanks for the info. I want to create a neovim package for msys2 so I need it to build inside msys2 shell. There may be more steps involved but the info you gave me is very usefull. Thanks

@equalsraf
Copy link
Author

Thanks for the info. I want to create a neovim package for msys2 so I need it to build inside msys2 shell. There may be more steps involved but the info you gave me is very usefull. Thanks

From what i remember, the reason we did not build inside msys2 was because we ran into issues with luarocks (built in third-party/) and path handling inside msys, so we build third-party from outside. Its been a while but I suspect nvim itself could build with the correct cmake generator.

Things you can do to work around any issues or speed up your port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment