Skip to content

Instantly share code, notes, and snippets.

@equalsraf
Last active January 2, 2020 02:17
Show Gist options
  • Save equalsraf/c52c2261ff3671ccbd32 to your computer and use it in GitHub Desktop.
Save equalsraf/c52c2261ff3671ccbd32 to your computer and use it in GitHub Desktop.
Cross Compile Neovim

Before you start you need a Mingw-w64 toolchain for Linux, try installing the mingw-w64 package (Ubuntu, Suse, Fedora?) or get it from the Mingw-w64 website.

Build dependencies

$ mkdir deps-mingw
$ cd deps-mingw
$ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw32-w64-cross-travis.toolchain.cmake ../third-party/
$ make
$ cd ..

Build Neovim

$ mkdir build-mingw
$ cd build-mingw
$ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw32-w64-cross-travis.toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-DMIN_LOG_LEVEL=0 -pg" -DDEPS_PREFIX=../deps-mingw/usr ..
$ make
$ wine bin/nvim.exe

You may get some errors (like missing dlls) when running, but this depends on your Mingw toolchain. Just copy the missing dll into the bin/ folder.

FYI: the terminal interface IS broken, so there wont be any output - but you can use one of the Neovim GUIs

Debugging

$ wine /usr/i686-w64-mingw32/sys-root/mingw/bin/gdbserver.exe :0 bin/nvim.exe
Process bin/nvim.exe created; pid = 36
Listening on port 47612

or alternatively

$ winedbg --gdb --no-start bin/nvim.exe

And them connect to gdbserver

$ gdb bin/nvim.exe 
GNU gdb (GDB; openSUSE 13.1) 7.6.50.20130731-cvs
(...)
(gdb) target remote localhost:47612
Remote debugging using localhost:47612
warning: Could not load shared library symbols for 12 libraries, e.g. C:\windows\system32\kernel32.dll.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
0x7b862737 in ?? ()

from here on out, it is regular gdb, use continue (not run) to start executing.

TODO

  • Windows system DLL symbols are not available

Known issues

Linking fails, with an error finding -lrt, -ldl, -lnsl - this seems to happen when an existing version of libuv is already installed (and the linking options are picked up from pkg-config). It is not clear why pkg-config is being used for the cross compile though.

@GentleFly
Copy link

Ubuntu (VirtualBox):
Build dependencies - OK
Build Neovim:

gentlefly@gentlefly-VirtualBox:~$ cd nvim/neovim/build-mingw/
gentlefly@gentlefly-VirtualBox:~/nvim/neovim/build-mingw$ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw32-w64-cross-travis.toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-DMIN_LOG_LEVEL=0 -pg" -DDEPS_PREFIX=../deps-mingw/usr ..
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/i686-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/i686-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Performing Test HAS_ACCEPTABLE_FORTIFY
-- Performing Test HAS_ACCEPTABLE_FORTIFY - Success
-- Performing Test HAS_FSTACK_PROTECTOR_STRONG_FLAG
-- Performing Test HAS_FSTACK_PROTECTOR_STRONG_FLAG - Failed
-- Performing Test HAS_FSTACK_PROTECTOR_FLAG
-- Performing Test HAS_FSTACK_PROTECTOR_FLAG - Success
-- Performing Test HAS_DIAG_COLOR_FLAG
-- Performing Test HAS_DIAG_COLOR_FLAG - Failed
-- Performing Test HAS_OG_FLAG
-- Performing Test HAS_OG_FLAG - Success
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26") 
-- 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
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
  Could NOT find LibUV (missing: LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindLibUV.cmake:96 (find_package_handle_standard_args)
  CMakeLists.txt:204 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/gentlefly/nvim/neovim/build-mingw/CMakeFiles/CMakeOutput.log".
See also "/home/gentlefly/nvim/neovim/build-mingw/CMakeFiles/CMakeError.log".

Sorry for my English.

@kiedtl
Copy link

kiedtl commented Jan 2, 2020

@GentleFly (I know, really late to the party, but couldn't help commenting anyway.)

You're missing libuv. You've got to install it first with your package manager.

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