From 69da692b0adbd9168d002eaffb02bd59c64044b2 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 01/28] build/msvc: Fix preprocessor parsing Preprocessor directives on the first line of the file were not being parsed. --- src/nvim/generators/gen_declarations.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua index 065c043557..c40c37bb3e 100755 --- a/src/nvim/generators/gen_declarations.lua +++ b/src/nvim/generators/gen_declarations.lua @@ -224,23 +224,15 @@ local static = header local filepattern = '^#%a* (%d+) "([^"]-)/?([^"/]+)"' local curfile -local init = 0 +local init = 1 local curfile = nil local neededfile = fname:match('[^/]+$') local declline = 0 local declendpos = 0 local curdir = nil local is_needed_file = false +local init_is_nl = true while init ~= nil do - init = text:find('[\n;}]', init) - if init == nil then - break - end - local init_is_nl = text:sub(init, init) == '\n' - init = init + 1 - if init_is_nl and is_needed_file then - declline = declline + 1 - end if init_is_nl and text:sub(init, init) == '#' then local line, dir, file = text:match(filepattern, init) if file ~= nil then @@ -293,6 +285,15 @@ while init ~= nil do declendpos = e end end + init = text:find('[\n;}]', init) + if init == nil then + break + end + init_is_nl = text:sub(init, init) == '\n' + init = init + 1 + if init_is_nl and is_needed_file then + declline = declline + 1 + end end non_static = non_static .. footer From d520e2590af5e8d22416e6acbcd161ba1601a532 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 02/28] build/msvc: Add mode_t typedef to win_defs.h --- src/nvim/os/win_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 8fd2e51f8b..48607845cc 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -60,6 +60,7 @@ #ifdef _MSC_VER typedef SSIZE_T ssize_t; +typedef int mode_t; #endif #ifndef SSIZE_MAX From d99f8feea3cf74b76352b7fbdcb32ec7a53fdc39 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 03/28] build/msvc: Fix name of import library --- cmake/FindMsgpack.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindMsgpack.cmake b/cmake/FindMsgpack.cmake index 6716289a98..cca0a00c20 100644 --- a/cmake/FindMsgpack.cmake +++ b/cmake/FindMsgpack.cmake @@ -44,7 +44,7 @@ endif() if(MSVC) # The import library for the msgpack DLL has a different name - list(APPEND MSGPACK_NAMES msgpack_import) + list(APPEND MSGPACK_NAMES msgpackc_import) else() list(APPEND MSGPACK_NAMES msgpackc msgpack) endif() From f04b53aa24f7b6f1f4cdcdf08fcdd600472b0bab Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 04/28] build/msvc: Move include into unix_defs.h --- src/nvim/os/os_defs.h | 1 - src/nvim/os/unix_defs.h | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 87f8d214bd..923a362b41 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 5c9daca476..27e64f20cf 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,9 +1,10 @@ #ifndef NVIM_OS_UNIX_DEFS_H #define NVIM_OS_UNIX_DEFS_H -// Windows doesn't have unistd.h, so we include it here to avoid numerous -// instances of `#ifdef WIN32'. +// Windows doesn't have the following headers, +// so we include them here to avoid numerous instances of `#ifdef WIN32'. #include +#include // POSIX.1-2008 says that NAME_MAX should be in here #include From 2c414fbbb1a869a4d9d3dd1076d198945ee74a7e Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 05/28] build/msvc: Fix missing restrict keyword MSVC has the __restrict keyword and a marco is defined for it in `win_defs.h`. --- src/nvim/lib/kvec.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index ee1b890cb9..ad56c9237b 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -41,6 +41,7 @@ #include #include "nvim/memory.h" +#include "nvim/os/os_defs.h" #define kv_roundup32(x) \ ((--(x)), \ From 60a341a05f2d2a351a172b36e7f01e579e49ab02 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 06/28] build/msvc: Fix standard IO file number definitions With MSVC, STDOUT_FILENO and STDERR_FILENO are defined as function calls instead of constants, meaning they can't be assigned to enum values. The enum was only used in one file, so it has been removed. A definition for STDIN_FILENO has been added that is consistent with the other two definitions. --- src/nvim/main.c | 8 ++++---- src/nvim/os/os_defs.h | 7 ------- src/nvim/os/win_defs.h | 3 +++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/nvim/main.c b/src/nvim/main.c index 4fd55f1491..25fb0f14d8 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -795,7 +795,7 @@ static void command_line_scan(mparm_T *parmp) mch_exit(0); } else if (STRICMP(argv[0] + argv_idx, "api-info") == 0) { FileDescriptor fp; - const int fof_ret = file_open_fd(&fp, OS_STDOUT_FILENO, true); + const int fof_ret = file_open_fd(&fp, STDOUT_FILENO, true); msgpack_packer *p = msgpack_packer_new(&fp, msgpack_file_write); if (fof_ret != 0) { @@ -1256,10 +1256,10 @@ static void check_and_set_isatty(mparm_T *paramp) paramp->err_isatty = os_isatty(fileno(stderr)); #ifndef WIN32 int tty_fd = paramp->input_isatty - ? OS_STDIN_FILENO + ? STDIN_FILENO : (paramp->output_isatty - ? OS_STDOUT_FILENO - : (paramp->err_isatty ? OS_STDERR_FILENO : -1)); + ? STDOUT_FILENO + : (paramp->err_isatty ? STDERR_FILENO : -1)); pty_process_save_termios(tty_fd); #endif TIME_MSG("window checked"); diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 923a362b41..f81785675e 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -13,13 +13,6 @@ # include "nvim/os/unix_defs.h" #endif -/// File descriptor number used for standard IO streams -enum { - OS_STDIN_FILENO = STDIN_FILENO, - OS_STDOUT_FILENO = STDOUT_FILENO, - OS_STDERR_FILENO = STDERR_FILENO, -}; - #define BASENAMELEN (NAME_MAX - 5) // Use the system path length if it makes sense. diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 48607845cc..faee06304c 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -45,6 +45,9 @@ # ifndef restrict # define restrict __restrict # endif +# ifndef STDIN_FILENO +# define STDIN_FILENO _fileno(stdin) +# endif # ifndef STDOUT_FILENO # define STDOUT_FILENO _fileno(stdout) # endif From 8f39e96d21d72c103727378ffd8902bed20a2896 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 07/28] build/msvc: Remove unnecessary header include --- src/nvim/spellfile.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index df066e7ad3..f5d5d408a1 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -228,7 +228,6 @@ #include #include #include -#include #include "nvim/vim.h" #include "nvim/spell_defs.h" From 9aec64c34e76f149509be9eb63b4d89250259db3 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 08/28] build/msvc: Allow building Unibilium on Windows --- third-party/CMakeLists.txt | 9 +++- third-party/cmake/BuildUnibilium.cmake | 60 +++++++++++++++++--------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index ceebb4cf1d..21cb2f0c3c 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -103,8 +103,13 @@ set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333) set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v2.4.3.tar.gz) set(LUAROCKS_SHA256 ea1881d6954f2a98c34f93674571c8f0cbdbc28dedb3fa3cb56b6a91886d1a99) -set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) -set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) +if(WIN32) + set(UNIBILIUM_URL https://github.com/b-r-o-c-k/unibilium/archive/v2.0.0.tar.gz) + set(UNIBILIUM_SHA256 37a81954f78a27a024b805b330f0b1c082d6c1e9aeed32509a00272c1695cdac) +else() + set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) + set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) +endif() if(WIN32) set(LIBTERMKEY_URL https://github.com/equalsraf/libtermkey/archive/tb-windows.zip) diff --git a/third-party/cmake/BuildUnibilium.cmake b/third-party/cmake/BuildUnibilium.cmake index a5ec6c01eb..d3aa91f11e 100644 --- a/third-party/cmake/BuildUnibilium.cmake +++ b/third-party/cmake/BuildUnibilium.cmake @@ -1,25 +1,43 @@ if(WIN32) - message(STATUS "Building Unibilium in Windows is not supported (skipping)") - return() + ExternalProject_Add(unibilium + PREFIX ${DEPS_BUILD_DIR} + URL ${UNIBILIUM_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/unibilium + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/unibilium + -DURL=${UNIBILIUM_URL} + -DEXPECTED_SHA256=${UNIBILIUM_SHA256} + -DTARGET=unibilium + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/unibilium + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + # Pass toolchain + -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) +else() + ExternalProject_Add(unibilium + PREFIX ${DEPS_BUILD_DIR} + URL ${UNIBILIUM_URL} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/unibilium + DOWNLOAD_COMMAND ${CMAKE_COMMAND} + -DPREFIX=${DEPS_BUILD_DIR} + -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/unibilium + -DURL=${UNIBILIUM_URL} + -DEXPECTED_SHA256=${UNIBILIUM_SHA256} + -DTARGET=unibilium + -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + CONFIGURE_COMMAND "" + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER} + PREFIX=${DEPS_INSTALL_DIR} + CFLAGS=-fPIC + INSTALL_COMMAND ${MAKE_PRG} PREFIX=${DEPS_INSTALL_DIR} install) endif() -ExternalProject_Add(unibilium - PREFIX ${DEPS_BUILD_DIR} - URL ${UNIBILIUM_URL} - DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/unibilium - DOWNLOAD_COMMAND ${CMAKE_COMMAND} - -DPREFIX=${DEPS_BUILD_DIR} - -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/unibilium - -DURL=${UNIBILIUM_URL} - -DEXPECTED_SHA256=${UNIBILIUM_SHA256} - -DTARGET=unibilium - -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} - -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake - CONFIGURE_COMMAND "" - BUILD_IN_SOURCE 1 - BUILD_COMMAND ${MAKE_PRG} CC=${DEPS_C_COMPILER} - PREFIX=${DEPS_INSTALL_DIR} - CFLAGS=-fPIC - INSTALL_COMMAND ${MAKE_PRG} PREFIX=${DEPS_INSTALL_DIR} install) - list(APPEND THIRD_PARTY_DEPS unibilium) From 0169872fd33feb0d9b2978b183fa6dfec3d4f086 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 09/28] build/msvc: Fix linking for luajit and luv --- third-party/cmake/BuildLuajit.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/third-party/cmake/BuildLuajit.cmake b/third-party/cmake/BuildLuajit.cmake index c8eee282bf..e65a81bba5 100644 --- a/third-party/cmake/BuildLuajit.cmake +++ b/third-party/cmake/BuildLuajit.cmake @@ -101,7 +101,10 @@ elseif(MSVC) COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/luajit.exe ${DEPS_INSTALL_DIR}/bin COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.dll ${DEPS_INSTALL_DIR}/bin COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/lib - COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_INSTALL_DIR}/lib + # Luarocks searches for lua51.lib + COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_INSTALL_DIR}/lib/lua51.lib + # Luv searches for luajit.lib + COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_BUILD_DIR}/src/luajit/src/lua51.lib ${DEPS_INSTALL_DIR}/lib/luajit.lib COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/include/luajit-2.0 COMMAND ${CMAKE_COMMAND} -DFROM_GLOB=${DEPS_BUILD_DIR}/src/luajit/src/*.h -DTO=${DEPS_INSTALL_DIR}/include/luajit-2.0 -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFilesGlob.cmake) From 3a6ee8819eecf45b108dde7b992c119710711ecc Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 10/28] build/msvc: Remove unnecessary copy command for msgpack DLL --- third-party/cmake/BuildMsgpack.cmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/third-party/cmake/BuildMsgpack.cmake b/third-party/cmake/BuildMsgpack.cmake index 779cb1ebfe..616b6e5f83 100644 --- a/third-party/cmake/BuildMsgpack.cmake +++ b/third-party/cmake/BuildMsgpack.cmake @@ -70,9 +70,6 @@ elseif(MSVC) # Make sure we use the same generator, otherwise we may # accidentaly end up using different MSVC runtimes -DCMAKE_GENERATOR=${CMAKE_GENERATOR}) - # Place the DLL in the bin folder - set(MSGPACK_INSTALL_COMMAND ${MSGPACK_INSTALL_COMMAND} - COMMAND ${CMAKE_COMMAND} -E copy ${DEPS_INSTALL_DIR}/lib/msgpack.dll ${DEPS_INSTALL_DIR}/bin) endif() BuildMsgpack(CONFIGURE_COMMAND ${MSGPACK_CONFIGURE_COMMAND} From cb245a71cabbd73e8fbaba45b604fbda84e9d2de Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 11/28] build/msvc: Add MSVC compiler flag when building LuaRocks --- third-party/cmake/BuildLuarocks.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index 2a59ad3b46..356ef94318 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -70,7 +70,9 @@ if(UNIX OR (MINGW AND CMAKE_CROSSCOMPILING)) elseif(MSVC OR MINGW) if(MINGW) - set(MINGW_FLAG /MW) + set(COMPILER_FLAG /MW) + elseif(MSVC) + set(COMPILER_FLAG /MSVC) endif() # Ignore USE_BUNDLED_LUAJIT - always ON for native Win32 @@ -82,7 +84,7 @@ elseif(MSVC OR MINGW) /P ${DEPS_INSTALL_DIR}/${LUAROCKS_VERSION} /TREE ${DEPS_INSTALL_DIR} /SCRIPTS ${DEPS_BIN_DIR} /CMOD ${DEPS_BIN_DIR} - ${MINGW_FLAG} + ${COMPILER_FLAG} /LUAMOD ${DEPS_BIN_DIR}/lua) set(LUAROCKS_BINARY ${DEPS_INSTALL_DIR}/${LUAROCKS_VERSION}/luarocks.bat) From f2b6145d749adc17a0fcd57d54f3f60149494850 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 28 Feb 2018 19:14:27 -0600 Subject: [PATCH 12/28] build/msvc: Use patched libvterm for MSVC --- third-party/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 21cb2f0c3c..4fe896e497 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -119,8 +119,13 @@ set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.20.tar set(LIBTERMKEY_SHA256 6c0d87c94ab9915e76ecd313baec08dedf3bd56de83743d9aa923a081935d2f5) endif() +if(MSVC) +set(LIBVTERM_URL https://github.com/b-r-o-c-k/libvterm/archive/eb386b1d82f7d07363c9133b7aa06902ccd555fe.tar.gz) +set(LIBVTERM_SHA256 be65c79611d306003440e651a3c52f603fc18b46e4117fe5957235ce7dd98233) +else() set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/a9c7c6fd20fa35e0ad3e0e98901ca12dfca9c25c.tar.gz) set(LIBVTERM_SHA256 1a4272be91d9614dc183a503786df83b6584e4afaab7feaaa5409f841afbd796) +endif() set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2) set(JEMALLOC_SHA256 9409d85664b4f135b77518b0b118c549009dc10f6cba14557d170476611f6780) From fa6f8920550571c27fe8c884a282734150d0daea Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Thu, 1 Mar 2018 22:36:30 -0600 Subject: [PATCH 13/28] build/msvc: Add CMakeLists.txt and header for Unibilium A header was added for compatibility with MSVC and CMakeLists.txt was added for building with CMake. --- third-party/CMakeLists.txt | 9 ++------ third-party/cmake/BuildUnibilium.cmake | 18 ++++++++++----- third-party/cmake/UnibiliumCMakeLists.txt | 27 +++++++++++++++++++++++ third-party/msvc-compat/unistd.h | 10 +++++++++ 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 third-party/cmake/UnibiliumCMakeLists.txt create mode 100644 third-party/msvc-compat/unistd.h diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 4fe896e497..53ec81669b 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -103,13 +103,8 @@ set(LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333) set(LUAROCKS_URL https://github.com/luarocks/luarocks/archive/v2.4.3.tar.gz) set(LUAROCKS_SHA256 ea1881d6954f2a98c34f93674571c8f0cbdbc28dedb3fa3cb56b6a91886d1a99) -if(WIN32) - set(UNIBILIUM_URL https://github.com/b-r-o-c-k/unibilium/archive/v2.0.0.tar.gz) - set(UNIBILIUM_SHA256 37a81954f78a27a024b805b330f0b1c082d6c1e9aeed32509a00272c1695cdac) -else() - set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) - set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) -endif() +set(UNIBILIUM_URL https://github.com/mauke/unibilium/archive/v2.0.0.tar.gz) +set(UNIBILIUM_SHA256 78997d38d4c8177c60d3d0c1aa8c53fd0806eb21825b7b335b1768d7116bc1c1) if(WIN32) set(LIBTERMKEY_URL https://github.com/equalsraf/libtermkey/archive/tb-windows.zip) diff --git a/third-party/cmake/BuildUnibilium.cmake b/third-party/cmake/BuildUnibilium.cmake index d3aa91f11e..f5342e3d34 100644 --- a/third-party/cmake/BuildUnibilium.cmake +++ b/third-party/cmake/BuildUnibilium.cmake @@ -11,12 +11,18 @@ if(WIN32) -DTARGET=unibilium -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake - CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/unibilium - -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} - # Pass toolchain - -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UnibiliumCMakeLists.txt + ${DEPS_BUILD_DIR}/src/unibilium/CMakeLists.txt + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/msvc-compat/unistd.h + ${DEPS_BUILD_DIR}/src/unibilium/msvc-compat/unistd.h + COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/unibilium + -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR} + # Pass toolchain + -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) else() diff --git a/third-party/cmake/UnibiliumCMakeLists.txt b/third-party/cmake/UnibiliumCMakeLists.txt new file mode 100644 index 0000000000..3c419654c4 --- /dev/null +++ b/third-party/cmake/UnibiliumCMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 2.8.7) +project(unibilium LANGUAGES C) + +file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.c) +add_library(unibilium ${SRC_FILES}) +set_target_properties(unibilium PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/unibilium.h + VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") + +if(NOT WIN32) + execute_process(COMMAND "shell ncursesw6-config --terminfo-dirs 2>/dev/null || \ + ncurses6-config --terminfo-dirs 2>/dev/null || \ + ncursesw5-config --terminfo-dirs 2>/dev/null || \ + ncurses5-config --terminfo-dirs 2>/dev/null || \ + echo '/etc/terminfo:/lib/terminfo:/usr/share/terminfo:/usr/lib/terminfo:/usr/local/share/terminfo:/usr/local/lib/terminfo'" + OUTPUT_VARIABLE TERMINFO_DIRS) +endif() +target_compile_definitions(unibilium PUBLIC TERMINFO_DIRS ${TERMINFO_DIRS}) + +if(MSVC) + target_include_directories(unibilium PUBLIC ${PROJECT_SOURCE_DIR}/msvc-compat) +endif() + +include(GNUInstallDirs) +install(TARGETS unibilium + PUBLIC_HEADER + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/third-party/msvc-compat/unistd.h b/third-party/msvc-compat/unistd.h new file mode 100644 index 0000000000..d9ee57b54b --- /dev/null +++ b/third-party/msvc-compat/unistd.h @@ -0,0 +1,10 @@ +#ifndef GUARD_UNIBILIUM_UNISTD_H_ +#define GUARD_UNIBILIUM_UNISTD_H_ + +#ifdef _WIN64 +typedef unsigned __int64 ssize_t; +#else +typedef _W64 unsigned int ssize_t; +#endif + +#endif From 305673e92312f81178e10e7426bcf0fb793e96ea Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Thu, 1 Mar 2018 22:39:35 -0600 Subject: [PATCH 14/28] build/msvc: Add patch for libvterm The patch removes VLAs because MSVC does not support them. --- third-party/CMakeLists.txt | 5 -- third-party/cmake/BuildLibvterm.cmake | 13 +++-- .../libvterm-Remove-VLAs-for-MSVC.patch | 50 +++++++++++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 third-party/patches/libvterm-Remove-VLAs-for-MSVC.patch diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 53ec81669b..ceebb4cf1d 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -114,13 +114,8 @@ set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.20.tar set(LIBTERMKEY_SHA256 6c0d87c94ab9915e76ecd313baec08dedf3bd56de83743d9aa923a081935d2f5) endif() -if(MSVC) -set(LIBVTERM_URL https://github.com/b-r-o-c-k/libvterm/archive/eb386b1d82f7d07363c9133b7aa06902ccd555fe.tar.gz) -set(LIBVTERM_SHA256 be65c79611d306003440e651a3c52f603fc18b46e4117fe5957235ce7dd98233) -else() set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/a9c7c6fd20fa35e0ad3e0e98901ca12dfca9c25c.tar.gz) set(LIBVTERM_SHA256 1a4272be91d9614dc183a503786df83b6584e4afaab7feaaa5409f841afbd796) -endif() set(JEMALLOC_URL https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2) set(JEMALLOC_SHA256 9409d85664b4f135b77518b0b118c549009dc10f6cba14557d170476611f6780) diff --git a/third-party/cmake/BuildLibvterm.cmake b/third-party/cmake/BuildLibvterm.cmake index 5ea8314da5..1b95007cf2 100644 --- a/third-party/cmake/BuildLibvterm.cmake +++ b/third-party/cmake/BuildLibvterm.cmake @@ -6,7 +6,7 @@ function(BuildLibvterm) cmake_parse_arguments(_libvterm "" "" - "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" + "PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" ${ARGN}) if(NOT _libvterm_CONFIGURE_COMMAND AND NOT _libvterm_BUILD_COMMAND @@ -26,6 +26,7 @@ function(BuildLibvterm) -DTARGET=libvterm -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + PATCH_COMMAND "${_libvterm_PATCH_COMMAND}" CONFIGURE_COMMAND "" BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "${_libvterm_CONFIGURE_COMMAND}" @@ -34,7 +35,12 @@ function(BuildLibvterm) endfunction() if(WIN32) - # MinGW + if(MSVC) + set(LIBVTERM_PATCH_COMMAND + git -C ${DEPS_BUILD_DIR}/src/libvterm init + COMMAND git -C ${DEPS_BUILD_DIR}/src/libvterm apply + ${CMAKE_CURRENT_SOURCE_DIR}/patches/libvterm-Remove-VLAs-for-MSVC.patch) + endif() set(LIBVTERM_CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/LibvtermCMakeLists.txt ${DEPS_BUILD_DIR}/src/libvterm/CMakeLists.txt @@ -52,7 +58,8 @@ else() install) endif() -BuildLibvterm(CONFIGURE_COMMAND ${LIBVTERM_CONFIGURE_COMMAND} +BuildLibvterm(PATCH_COMMAND ${LIBVTERM_PATCH_COMMAND} + CONFIGURE_COMMAND ${LIBVTERM_CONFIGURE_COMMAND} BUILD_COMMAND ${LIBVTERM_BUILD_COMMAND} INSTALL_COMMAND ${LIBVTERM_INSTALL_COMMAND}) diff --git a/third-party/patches/libvterm-Remove-VLAs-for-MSVC.patch b/third-party/patches/libvterm-Remove-VLAs-for-MSVC.patch new file mode 100644 index 0000000000..3fb18351be --- /dev/null +++ b/third-party/patches/libvterm-Remove-VLAs-for-MSVC.patch @@ -0,0 +1,50 @@ +From eb386b1d82f7d07363c9133b7aa06902ccd555fe Mon Sep 17 00:00:00 2001 +Date: Tue, 27 Feb 2018 17:54:20 -0600 +Subject: [PATCH] Remove VLAs for MSVC + +VLAs are replaced with calls to _alloca() because MSVC does not support them. +--- + src/state.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/src/state.c b/src/state.c +index 84299df..f9aabb3 100644 +--- a/src/state.c ++++ b/src/state.c +@@ -1,5 +1,6 @@ + #include "vterm_internal.h" + ++#include + #include + #include + +@@ -236,7 +237,7 @@ static int on_text(const char bytes[], size_t len, void *user) + VTermPos oldpos = state->pos; + + // We'll have at most len codepoints +- uint32_t codepoints[len]; ++ uint32_t* codepoints = _alloca(len); + int npoints = 0; + size_t eaten = 0; + +@@ -313,7 +314,7 @@ static int on_text(const char bytes[], size_t len, void *user) + + int width = 0; + +- uint32_t chars[glyph_ends - glyph_starts + 1]; ++ uint32_t* chars = _alloca(glyph_ends - glyph_starts + 1); + + for( ; i < glyph_ends; i++) { + chars[i - glyph_starts] = codepoints[i]; +@@ -512,7 +513,7 @@ static int settermprop_int(VTermState *state, VTermProp prop, int v) + + static int settermprop_string(VTermState *state, VTermProp prop, const char *str, size_t len) + { +- char strvalue[len+1]; ++ char* strvalue = _alloca(len+1); + strncpy(strvalue, str, len); + strvalue[len] = 0; + +-- +2.16.1.windows.4 + From b3d0241416407450056a18b2c603bdd48b7ceb9f Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Thu, 1 Mar 2018 22:44:31 -0600 Subject: [PATCH 15/28] build/msvc: Add patch for LuaRocks LuaRocks bundles an outdated wget.exe for downloading packages on Windows. It is too old to support GitHub's TLS, so this patch will replace it with curl. --- third-party/cmake/BuildLuarocks.cmake | 17 +++++++++++-- ...ks-Change-default-downloader-to-curl.patch | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 third-party/patches/luarocks-Change-default-downloader-to-curl.patch diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index 356ef94318..297fedb888 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -12,7 +12,7 @@ function(BuildLuarocks) cmake_parse_arguments(_luarocks "" "" - "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" + "PATCH_COMMAND;CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND" ${ARGN}) if(NOT _luarocks_CONFIGURE_COMMAND AND NOT _luarocks_BUILD_COMMAND @@ -32,6 +32,7 @@ function(BuildLuarocks) -DTARGET=luarocks -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake + PATCH_COMMAND "${_luarocks_PATCH_COMMAND}" BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "${_luarocks_CONFIGURE_COMMAND}" BUILD_COMMAND "${_luarocks_BUILD_COMMAND}" @@ -50,6 +51,11 @@ if(NOT MSVC) # version already knows, and passing them here breaks the build set(LUAROCKS_BUILDARGS CC=${HOSTDEPS_C_COMPILER} LD=${HOSTDEPS_C_COMPILER}) endif() +if(WIN32) + # Use our bundled curl.exe for downloading packages + set(LUAROCKS_BUILDARGS ${LUAROCKS_BUILDARGS} CURL=${DEPS_BIN_DIR}/curl.exe) +endif() + if(UNIX OR (MINGW AND CMAKE_CROSSCOMPILING)) @@ -76,7 +82,12 @@ elseif(MSVC OR MINGW) endif() # Ignore USE_BUNDLED_LUAJIT - always ON for native Win32 - BuildLuarocks(INSTALL_COMMAND install.bat /FORCECONFIG /NOREG /NOADMIN /Q /F + BuildLuarocks( + PATCH_COMMAND + git -C ${DEPS_BUILD_DIR}/src/luarocks init + COMMAND git -C ${DEPS_BUILD_DIR}/src/luarocks apply + ${CMAKE_CURRENT_SOURCE_DIR}/patches/luarocks-Change-default-downloader-to-curl.patch + INSTALL_COMMAND install.bat /FORCECONFIG /NOREG /NOADMIN /Q /F /LUA ${DEPS_INSTALL_DIR} /LIB ${DEPS_LIB_DIR} /BIN ${DEPS_BIN_DIR} @@ -88,6 +99,8 @@ elseif(MSVC OR MINGW) /LUAMOD ${DEPS_BIN_DIR}/lua) set(LUAROCKS_BINARY ${DEPS_INSTALL_DIR}/${LUAROCKS_VERSION}/luarocks.bat) + add_dependencies(luarocks wintools) + else() message(FATAL_ERROR "Trying to build luarocks in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}") endif() diff --git a/third-party/patches/luarocks-Change-default-downloader-to-curl.patch b/third-party/patches/luarocks-Change-default-downloader-to-curl.patch new file mode 100644 index 0000000000..b7109a3b53 --- /dev/null +++ b/third-party/patches/luarocks-Change-default-downloader-to-curl.patch @@ -0,0 +1,24 @@ +From 69313032fad04743c96bc8f2a029b691857488f9 Mon Sep 17 00:00:00 2001 +Date: Thu, 1 Mar 2018 21:41:29 -0600 +Subject: [PATCH] Change default downloader to curl + +--- + install.bat | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/install.bat b/install.bat +index 09cf9aa..76e4059 100644 +--- a/install.bat ++++ b/install.bat +@@ -1037,7 +1037,7 @@ f:write(S[=[ + site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] + site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]] + site_config.LUAROCKS_PREFIX=[[$PREFIX]] +-site_config.LUAROCKS_DOWNLOADER=[[wget]] ++site_config.LUAROCKS_DOWNLOADER=[[curl]] + site_config.LUAROCKS_MD5CHECKER=[[md5sum]] + ]=]) + if FORCE_CONFIG then +-- +2.16.1.windows.4 + From adfad73d8eb868b7b4691319c1f586f601f6815f Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Thu, 1 Mar 2018 22:46:37 -0600 Subject: [PATCH 16/28] build/msvc: Make libtermkey depend on Unibilium --- third-party/cmake/BuildLibtermkey.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/third-party/cmake/BuildLibtermkey.cmake b/third-party/cmake/BuildLibtermkey.cmake index 4b581c2a01..9081e5e988 100644 --- a/third-party/cmake/BuildLibtermkey.cmake +++ b/third-party/cmake/BuildLibtermkey.cmake @@ -47,7 +47,4 @@ ExternalProject_Add(libtermkey endif() list(APPEND THIRD_PARTY_DEPS libtermkey) -if(NOT WIN32) - # There is no unibilium build recipe for Windows yet - add_dependencies(libtermkey unibilium) -endif() +add_dependencies(libtermkey unibilium) From 8e30598115f49df27fa9f20544dbfc5a8ade4e26 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 17/28] build/msvc: Remove pkgconfig dependency on Windows --- third-party/cmake/BuildLibtermkey.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third-party/cmake/BuildLibtermkey.cmake b/third-party/cmake/BuildLibtermkey.cmake index 6692f16f13..b5cd0c4ca6 100644 --- a/third-party/cmake/BuildLibtermkey.cmake +++ b/third-party/cmake/BuildLibtermkey.cmake @@ -1,5 +1,3 @@ -find_package(PkgConfig REQUIRED) - if(WIN32) ExternalProject_Add(libtermkey PREFIX ${DEPS_BUILD_DIR} @@ -24,6 +22,8 @@ ExternalProject_Add(libtermkey BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}) else() +find_package(PkgConfig REQUIRED) + ExternalProject_Add(libtermkey PREFIX ${DEPS_BUILD_DIR} URL ${LIBTERMKEY_URL} From 01fc02beeee2a4c5ba66e6f93d9fb0d1fd6a4548 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 18/28] build/msvc: Add missing WIN32 macro MSVC predefines `_WIN32`, but not `WIN32`. Also, some unnecessary includes have been removed. --- CMakeLists.txt | 4 ++++ src/nvim/main.c | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4ff4d5ac3..8147afb14f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,6 +204,7 @@ int main(void) if(MSVC) # XXX: /W4 gives too many warnings. #3241 add_definitions(/W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) + add_definitions(-DWIN32) else() add_definitions(-Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99) @@ -223,6 +224,9 @@ endif() if(MINGW) # Use POSIX compatible stdio in Mingw add_definitions(-D__USE_MINGW_ANSI_STDIO) +endif() +if(WIN32) + # Windows Vista is the minimum supported version add_definitions(-D_WIN32_WINNT=0x0600) endif() diff --git a/src/nvim/main.c b/src/nvim/main.c index 25fb0f14d8..4288d7f9d7 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -7,11 +7,6 @@ #include #include -#ifdef WIN32 -# include -# include -#endif - #include #include "nvim/ascii.h" From 773f23e00d5a4af836a854702ffb9e69fcaf61ff Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 19/28] build/msvc: Make shell-test work MSVC doesn't have unistd.h or usleep() so it was replaced with the Sleep() WinAPI function. --- test/functional/fixtures/shell-test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c index 38695ce76b..cc447d903f 100644 --- a/test/functional/fixtures/shell-test.c +++ b/test/functional/fixtures/shell-test.c @@ -4,7 +4,12 @@ #include #include #include +#ifdef WIN32 +#include +#define usleep(usecs) Sleep(usecs/1000) +#else #include +#endif static void wait(void) { From d7ee3233264626de93e0466e0abecbc9dc6bc6ba Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 20/28] build/msvc: Fix errors caused by compiler intrinsics --- src/nvim/eval.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 923b4527c2..d69acf4eef 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5936,6 +5936,14 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) } #ifdef INCLUDE_GENERATED_DECLARATIONS + +#ifdef _MSC_VER +// This prevents MSVC from replacing the functions with intrinsics, +// and causing errors when trying to get their addresses in funcs.generated.h +#pragma function (ceil) +#pragma function (floor) +#endif + # include "funcs.generated.h" #endif From 353ca83f73dba0c7661a061215cc8508051a1be9 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 21/28] build/msvc: Workaround for compiler optimization bug --- src/nvim/option.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nvim/option.c b/src/nvim/option.c index eff436eb4d..d6903c8db7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2436,6 +2436,11 @@ static bool valid_filetype(char_u *val) return true; } +#ifdef _MSC_VER +// MSVC optimizations are disabled for this function because it +// incorrectly generates an empty string for SHM_ALL. +#pragma optimize("", off) +#endif /* * Handle string options that need some action to perform when changed. * Returns NULL for success, or an error message for an error. @@ -3305,6 +3310,9 @@ did_set_string_option ( return errmsg; } +#ifdef _MSC_VER +#pragma optimize("", on) +#endif /* * Simple int comparison function for use with qsort() From cfb713b5c6a3cde25e12ffba87b488105d82c76a Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 22/28] build/msvc: Add Appveyor CI for MSVC --- appveyor.yml | 3 ++ ci/build.bat | 50 +++++++++++++++++------------- third-party/cmake/BuildLibuv.cmake | 12 ++++--- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 30b7947da0..608998faf1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,10 @@ version: '{build}' environment: APPVEYOR_CACHE_ENTRY_ZIP_ARGS: "-t7z -m0=lzma -mx=9" +image: Visual Studio 2017 configuration: +- MSVC_64 +- MSVC_32 - MINGW_64 - MINGW_32 - MINGW_64-gcov diff --git a/ci/build.bat b/ci/build.bat index 5c7f14ad0a..60bd152192 100644 --- a/ci/build.bat +++ b/ci/build.bat @@ -1,27 +1,33 @@ -:: These are native MinGW builds, but they use the toolchain inside -:: MSYS2, this allows using all the dependencies and tools available -:: in MSYS2, but we cannot build inside the MSYS2 shell. echo on if "%CONFIGURATION%" == "MINGW_32" ( set ARCH=i686 set BITS=32 -) else ( +) else if "%CONFIGURATION%" == "MINGW_64" ( set ARCH=x86_64 set BITS=64 -) -if "%CONFIGURATION%" == "MINGW_64-gcov" ( +) else if "%CONFIGURATION%" == "MINGW_64-gcov" ( set USE_GCOV="-DUSE_GCOV=ON" +) else if "%CONFIGURATION%" == "MSVC_32" ( + set CMAKE_GENERATOR="Visual Studio 15 2017" +) else if "%CONFIGURATION%" == "MSVC_64" ( + set CMAKE_GENERATOR="Visual Studio 15 2017 Win64" ) -:: We cannot have sh.exe in the PATH (MinGW) -set PATH=%PATH:C:\Program Files\Git\usr\bin;=% -set PATH=C:\msys64\mingw%BITS%\bin;C:\Windows\System32;C:\Windows;%PATH% -:: The default cpack in the PATH is not CMake -set PATH=C:\Program Files (x86)\CMake\bin\cpack.exe;%PATH% - -:: Build third-party dependencies -C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm -Su" || goto :error -C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S mingw-w64-%ARCH%-cmake mingw-w64-%ARCH%-perl mingw-w64-%ARCH%-diffutils mingw-w64-%ARCH%-unibilium gperf" || goto :error +if "%CONFIGURATION:~0,5%" == "MINGW" ( + :: These are native MinGW builds, but they use the toolchain inside + :: MSYS2, this allows using all the dependencies and tools available + :: in MSYS2, but we cannot build inside the MSYS2 shell. + set CMAKE_GENERATOR="MinGW Makefiles" + set CMAKE_GENERATOR_ARGS=VERBOSE=1 + :: Add MinGW to the PATH and remove the Git directory because it + :: has a conflicting sh.exe + set "PATH=C:\msys64\mingw%BITS%\bin;C:\Windows\System32;C:\Windows;%PATH:C:\Program Files\Git\usr\bin;=%" + :: Build third-party dependencies + C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm -Su" || goto :error + C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S mingw-w64-%ARCH%-cmake mingw-w64-%ARCH%-perl mingw-w64-%ARCH%-diffutils mingw-w64-%ARCH%-unibilium gperf" || goto :error +) else if "%CONFIGURATION:~0,4%" == "MSVC" ( + set CMAKE_GENERATOR_ARGS=/verbosity:detailed +) :: Setup python (use AppVeyor system python) C:\Python27\python.exe -m pip install neovim || goto :error @@ -42,19 +48,19 @@ where.exe neovim-node-host.cmd || goto :error mkdir .deps cd .deps -cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..\third-party\ || goto :error -mingw32-make VERBOSE=1 || goto :error +cmake -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=RelWithDebInfo ..\third-party\ || goto :error +cmake --build . -- %CMAKE_GENERATOR_ARGS% || goto :error cd .. :: Build Neovim mkdir build cd build -cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUSTED_OUTPUT_TYPE=nvim %USE_GCOV% -DGPERF_PRG="C:\msys64\usr\bin\gperf.exe" .. || goto :error -mingw32-make VERBOSE=1 || goto :error +cmake -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUSTED_OUTPUT_TYPE=nvim %USE_GCOV% -DGPERF_PRG="C:\msys64\usr\bin\gperf.exe" .. || goto :error +cmake --build . --config RelWithDebInfo -- %CMAKE_GENERATOR_ARGS% || goto :error bin\nvim --version || goto :error :: Functional tests -mingw32-make functionaltest VERBOSE=1 || goto :error +cmake --build . --config RelWithDebInfo --target functionaltest -- %CMAKE_GENERATOR_ARGS% || goto :error if defined USE_GCOV ( C:\msys64\usr\bin\bash -lc "cd /c/projects/neovim; bash <(curl -s https://codecov.io/bash) -c -F functionaltest || echo 'codecov upload failed.'" @@ -63,13 +69,15 @@ if defined USE_GCOV ( :: Old tests setlocal set PATH=%PATH%;C:\msys64\usr\bin -mingw32-make -C "%~dp0\..\src\nvim\testdir" VERBOSE=1 +cmake --build "%~dp0\..\src\nvim\testdir" -- %CMAKE_GENERATOR_ARGS% endlocal if defined USE_GCOV ( C:\msys64\usr\bin\bash -lc "cd /c/projects/neovim; bash <(curl -s https://codecov.io/bash) -c -F oldtest || echo 'codecov upload failed.'" ) +:: The default cpack in the PATH is not CMake +set PATH=C:\Program Files (x86)\CMake\bin\cpack.exe;%PATH% :: Build artifacts cpack -G ZIP -C RelWithDebInfo if defined APPVEYOR_REPO_TAG_NAME cpack -G NSIS -C RelWithDebInfo diff --git a/third-party/cmake/BuildLibuv.cmake b/third-party/cmake/BuildLibuv.cmake index 06b527e5a2..a1c7e7f986 100644 --- a/third-party/cmake/BuildLibuv.cmake +++ b/third-party/cmake/BuildLibuv.cmake @@ -76,15 +76,19 @@ elseif(WIN32 AND MSVC) endif() include(TargetArch) - if("${TARGET_ARCH}" STREQUAL "X86_64") + if(TARGET_ARCH STREQUAL "X86_64") set(TARGET_ARCH x64) elseif(TARGET_ARCH STREQUAL "X86") set(TARGET_ARCH x86) endif() - string(TOLOWER ${CMAKE_BUILD_TYPE} LOWERCASE_BUILD_TYPE) - set(UV_OUTPUT_DIR ${DEPS_BUILD_DIR}/src/libuv/${CMAKE_BUILD_TYPE}) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(TARGET_CONFIG debug) + else() + set(TARGET_CONFIG release) + endif() + set(UV_OUTPUT_DIR ${DEPS_BUILD_DIR}/src/libuv/${TARGET_CONFIG}) BuildLibUv( - BUILD_COMMAND set PYTHON=${PYTHON_EXECUTABLE} COMMAND ${DEPS_BUILD_DIR}/src/libuv/vcbuild.bat shared ${LOWERCASE_BUILD_TYPE} ${TARGET_ARCH} + BUILD_COMMAND set PYTHON=${PYTHON_EXECUTABLE} COMMAND ${DEPS_BUILD_DIR}/src/libuv/vcbuild.bat shared ${TARGET_CONFIG} ${TARGET_ARCH} INSTALL_COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/lib COMMAND ${CMAKE_COMMAND} -E make_directory ${DEPS_INSTALL_DIR}/bin COMMAND ${CMAKE_COMMAND} -E copy ${UV_OUTPUT_DIR}/libuv.lib ${DEPS_INSTALL_DIR}/lib From fb3667cd16adfb1564ccbe36973f8874afc1524f Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: [PATCH 23/28] build/msvc: Remove confusing comment --- src/nvim/os/unix_defs.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 27e64f20cf..60a2dfa882 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,8 +1,6 @@ #ifndef NVIM_OS_UNIX_DEFS_H #define NVIM_OS_UNIX_DEFS_H -// Windows doesn't have the following headers, -// so we include them here to avoid numerous instances of `#ifdef WIN32'. #include #include From 7612ba5ad9f358722638e78fec8f45cb82545dca Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Mon, 5 Mar 2018 11:00:01 -0600 Subject: [PATCH 24/28] build/msvc: Change MSBuild verbosity to normal --- ci/build.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build.bat b/ci/build.bat index 60bd152192..7bedc19195 100644 --- a/ci/build.bat +++ b/ci/build.bat @@ -26,7 +26,7 @@ if "%CONFIGURATION:~0,5%" == "MINGW" ( C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm -Su" || goto :error C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S mingw-w64-%ARCH%-cmake mingw-w64-%ARCH%-perl mingw-w64-%ARCH%-diffutils mingw-w64-%ARCH%-unibilium gperf" || goto :error ) else if "%CONFIGURATION:~0,4%" == "MSVC" ( - set CMAKE_GENERATOR_ARGS=/verbosity:detailed + set CMAKE_GENERATOR_ARGS=/verbosity:normal ) :: Setup python (use AppVeyor system python) From e0d55f2871784d882d30e7b0d9ffccf9c4dadc3b Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Mon, 5 Mar 2018 11:01:47 -0600 Subject: [PATCH 25/28] build/msvc: Allow MSVC AppVeyor builds to fail --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 608998faf1..8c2c89560c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ configuration: - MINGW_64-gcov matrix: allow_failures: + - configuration: MSVC_64 + - configuration: MSVC_32 - configuration: MINGW_64-gcov install: [] before_build: From c29a82c45f7be0f7ea46311e16a46a94f2173b98 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Tue, 6 Mar 2018 20:38:10 -0600 Subject: [PATCH 26/28] build/msvc: Make shell-test fix only apply to MSCV --- test/functional/fixtures/shell-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/fixtures/shell-test.c b/test/functional/fixtures/shell-test.c index cc447d903f..a744d5df46 100644 --- a/test/functional/fixtures/shell-test.c +++ b/test/functional/fixtures/shell-test.c @@ -4,7 +4,7 @@ #include #include #include -#ifdef WIN32 +#ifdef _MSC_VER #include #define usleep(usecs) Sleep(usecs/1000) #else From 8ba8d7244fae5783fbda9aac35bc03a035bf1479 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Tue, 6 Mar 2018 20:38:10 -0600 Subject: [PATCH 27/28] build/msvc: Add Git as a requirement for Windows patches --- third-party/CMakeLists.txt | 7 +++++++ third-party/cmake/BuildLibvterm.cmake | 4 ++-- third-party/cmake/BuildLuarocks.cmake | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index c523ecea00..7c95bbb91d 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -50,6 +50,13 @@ endif() option(USE_EXISTING_SRC_DIR "Skip download of deps sources in case of existing source directory." OFF) +if(WIN32) + find_package(Git) + if(NOT Git_FOUND) + message(FATAL_ERROR "Git is required to apply patches for Windows.") + endif() +endif() + if(UNIX) find_program(MAKE_PRG NAMES gmake make) if(MAKE_PRG) diff --git a/third-party/cmake/BuildLibvterm.cmake b/third-party/cmake/BuildLibvterm.cmake index 5fb077e972..73e2990654 100644 --- a/third-party/cmake/BuildLibvterm.cmake +++ b/third-party/cmake/BuildLibvterm.cmake @@ -37,8 +37,8 @@ endfunction() if(WIN32) if(MSVC) set(LIBVTERM_PATCH_COMMAND - git -C ${DEPS_BUILD_DIR}/src/libvterm init - COMMAND git -C ${DEPS_BUILD_DIR}/src/libvterm apply + ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/libvterm init + COMMAND ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/libvterm apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/libvterm-Remove-VLAs-for-MSVC.patch) endif() set(LIBVTERM_CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index 297fedb888..47c6412d86 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -84,8 +84,8 @@ elseif(MSVC OR MINGW) # Ignore USE_BUNDLED_LUAJIT - always ON for native Win32 BuildLuarocks( PATCH_COMMAND - git -C ${DEPS_BUILD_DIR}/src/luarocks init - COMMAND git -C ${DEPS_BUILD_DIR}/src/luarocks apply + ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/luarocks init + COMMAND ${GIT_EXECUTABLE} -C ${DEPS_BUILD_DIR}/src/luarocks apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/luarocks-Change-default-downloader-to-curl.patch INSTALL_COMMAND install.bat /FORCECONFIG /NOREG /NOADMIN /Q /F /LUA ${DEPS_INSTALL_DIR} From 0adf950ccf9a0057c552a349d79a716ff7be6f8f Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Wed, 7 Mar 2018 11:07:07 -0600 Subject: [PATCH 28/28] build/msvc: Fix AppVeyor build script for 'MINGW_64-gcov' configuration --- ci/build.bat | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ci/build.bat b/ci/build.bat index 7bedc19195..3fa185f646 100644 --- a/ci/build.bat +++ b/ci/build.bat @@ -2,11 +2,12 @@ echo on if "%CONFIGURATION%" == "MINGW_32" ( set ARCH=i686 set BITS=32 -) else if "%CONFIGURATION%" == "MINGW_64" ( +) else if "%CONFIGURATION:~0,8%" == "MINGW_64" ( set ARCH=x86_64 set BITS=64 -) else if "%CONFIGURATION%" == "MINGW_64-gcov" ( - set USE_GCOV="-DUSE_GCOV=ON" + if "%CONFIGURATION%" == "MINGW_64-gcov" ( + set USE_GCOV="-DUSE_GCOV=ON" + ) ) else if "%CONFIGURATION%" == "MSVC_32" ( set CMAKE_GENERATOR="Visual Studio 15 2017" ) else if "%CONFIGURATION%" == "MSVC_64" (