Skip to content

Conversation

justinmk
Copy link
Member

@justinmk justinmk commented Jun 1, 2018

"Always use find_package with REQUIRED."

This is partially a cargo-cult (reference below), but it uncovered at
least one problem: find_package(LibIntl REQUIRED) fails on my vanilla
ubuntu 16.04 system, whereas find_package(Intl REQUIRED) succeeds.

ref: https://schneide.blog/2017/11/06/4-tips-for-better-cmake/


  • let FindLibIntl.cmake handle REQUIRED
  • Windows: download iconv/gettext binaries
  • Windows: enable DYNAMIC_ICONV
  • Added makedeps.bat until build.ps1 can replace it for developers using VS.

I didn't enable any new tests related to iconv, but I tested it locally with:

:edit ++enc=iso-2022-jp foo

Nvim appveyor build log shows iconv/dyn feature is enabled:

Features: -acl +iconv/dyn -jemalloc +tui 

@justinmk justinmk added the build building and installing Neovim using the provided scripts label Jun 1, 2018
@justinmk
Copy link
Member Author

justinmk commented Jun 2, 2018

@jszakmeister gettext is not found on the linux quickbuild env, should it be?

18:50:33,289 WARN  - CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
18:50:33,289 WARN  -   Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE
18:50:33,289 WARN  -   GETTEXT_MSGFMT_EXECUTABLE)
18:50:33,289 WARN  - Call Stack (most recent call first):
18:50:33,289 WARN  -   /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
18:50:33,289 WARN  -   /usr/share/cmake-3.5/Modules/FindGettext.cmake:87 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
18:50:33,289 WARN  -   src/nvim/po/CMakeLists.txt:1 (find_package)
18:50:33,289 WARN  - 
18:50:33,289 WARN  - 
18:50:33,292 INFO  - -- Configuring incomplete, errors occurred!
18:50:33,292 INFO  - See also "/home/quickbuild/buildagent/workspace/root/neovim/pull-requests-automated/build/Release/CMakeFiles/CMakeOutput.log".
18:50:33,292 INFO  - See also "/home/quickbuild/buildagent/workspace/root/neovim/pull-requests-automated/build/Release/CMakeFiles/CMakeError.log".
18:50:33,300 INFO  - Executing post-execute action...
18:50:33,300 ERROR - Step 'master>buildall>build-node?testNode=linux-64>build-and-run-tests>build-and-run-tests-parameterized?buildType=Release>configure-neovim-and-build-nvim' is failed: Failed to run command: mkdir -p build/Release && cd build/Release && cmake -G "Unix Makefiles" -DBUSTED_OUTPUT_TYPE=TAP -DCMAKE_BUILD_TYPE=Release -DTRAVIS_CI_BUILD=ON ../.. && make VERBOSE=1 nvim unittest-prereqs functionaltest-prereqs
Command return code: 1
Command error output: CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE
  GETTEXT_MSGFMT_EXECUTABLE)
Call Stack (most recent call first):
  /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.5/Modules/FindGettext.cmake:87 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  src/nvim/po/CMakeLists.txt:1 (find_package)

CMakeLists.txt Outdated
find_package(LibIntl)
if(LibIntl_FOUND)
if(ENABLE_LIBINTL)
find_package(Intl REQUIRED)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamessan @jszakmeister Is find_package(LibIntl) needed instead of find_package(Intl) for some reason?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because find_package(LibIntl) is actually delegating to our cmake/FindLibIntl.cmake file. If we provide the wrong name, then CMake can't locate it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I'm not sure why find_package(Intl) seems to work and find_package(LibIntl) doesn't. :-/ Maybe it was partially related to gettext missing? But I don't really see how that would happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream's is FindIntl:

[jamessan@freya] 0 % dpkg -S FindLibIntl
dpkg-query: no path found matching pattern *FindLibIntl*
[jamessan@freya] 1 % dpkg -S FindIntl
cmake-data: /usr/share/cmake-3.11/Modules/FindIntl.cmake
cmake-data: /usr/share/cmake-3.11/Help/module/FindIntl.rst

Is there a reason we don't use that or build our own on top of that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and one other thing. The FindIntl.cmake that comes with CMake doesn't do the work of finding it via Homebrew--which is why we don't use the standard one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamessan Yes, it doesn't find it when Homebrew is involved on macOS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way we can instruct FindIntl to consider homebrew's paths too?

@justinmk justinmk force-pushed the cmake-findpkg-required branch from 7fd9b05 to 04e93e7 Compare June 2, 2018 09:43
@jszakmeister
Copy link
Contributor

gettext is not found on the linux quickbuild env, should it be?

@justinmk gettext wasn't installed. I grabbed the build dependencies from here, but I guess it's incomplete. Should gettext be listed in there?

.travis.yml Outdated
@@ -53,7 +53,7 @@ jobs:
compiler: clang
env: >
CLANG_SANITIZER=ASAN_UBSAN
CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUA=ON"
CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUA=OFF"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally using Lua (c.f. 8fec4d5) because we build Lua with ASAN to be able to test our embedded Lua support.

@jamessan
Copy link
Member

jamessan commented Jun 2, 2018

I grabbed the build dependencies from here, but I guess it's incomplete. Should gettext be listed in there?

Hmm, I don't depend on that for Debian's official packaging either and the build works... Ah, because it's pulled in by other packages:

[jamessan@freya] 1 % aptitude why neovim-build-deps gettext 
i   neovim-build-deps Depends debhelper (>= 11)
i A debhelper         Depends po-debconf       
i A po-debconf        Depends gettext (>= 0.16)

I should make that explicit.

@justinmk
Copy link
Member Author

justinmk commented Jun 2, 2018

Updated the wiki.

@justinmk
Copy link
Member Author

justinmk commented Jun 2, 2018

If HAVE_WORKING_LIBINTL is set, why does anything else matter?

@justinmk justinmk force-pushed the cmake-findpkg-required branch from 04e93e7 to dc3124f Compare June 2, 2018 13:58
@justinmk
Copy link
Member Author

justinmk commented Jun 2, 2018

BTW, I'm not sure why find_package(Intl) seems to work and find_package(LibIntl) doesn't

I did some more digging, turns out that was by accident: it only fails if LibIntl_LIBRARY (referenced in src/nvim/CMakeLists.txt) is NOTFOUND. With find_package(Intl) that is silently skipped because Intl_LIBRARY is NOTFOUND, which isn't referenced in our build.

I tried to better encapsulate this stuff in our FindLibIntl.cmake: dc3124f e71b336

@jamessan
Copy link
Member

jamessan commented Jun 2, 2018

Probably need this to fix the ASAN build. Not sure why it worked before.

diff --git i/ci/common/build.sh w/ci/common/build.sh
index a3cf64d47..dfd96051a 100644
--- i/ci/common/build.sh
+++ w/ci/common/build.sh
@@ -23,7 +23,7 @@ build_deps() {
   fi
   if test "${FUNCTIONALTEST}" = "functionaltest-lua" \
      || test "${CLANG_SANITIZER}" = "ASAN_UBSAN" ; then
-    DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON"
+    DEPS_CMAKE_FLAGS="${DEPS_CMAKE_FLAGS} -DUSE_BUNDLED_LUA=ON -DUSE_BUNDLED_LUAJIT=OFF"
   fi
 
   mkdir -p "${DEPS_BUILD_DIR}"

@jamessan
Copy link
Member

jamessan commented Jun 2, 2018

Probably need this to fix the ASAN build.

Although, the main cmake should be preferring Lua even if LuaJIT is present. Why isn't that happening...

Configuring with '-DTRAVIS_CI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nvim-install -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=/home/travis/nvim-deps/usr -DMIN_LOG_LEVEL=3 -DPREFER_LUA=ON -DCLANG_ASAN_UBSAN=ON '.
+cmake -G Ninja -DTRAVIS_CI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nvim-install -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=/home/travis/nvim-deps/usr -DMIN_LOG_LEVEL=3 -DPREFER_LUA=ON -DCLANG_ASAN_UBSAN=ON /home/travis/build/neovim/neovim
...
-- Checking Lua interpreter /home/travis/nvim-deps/usr/bin/luajit
-- Using the Lua interpreter /home/travis/nvim-deps/usr/bin/luajit.

@jszakmeister
Copy link
Contributor

Although, the main cmake should be preferring Lua even if LuaJIT is present. Why isn't that happening...

Configuring with '-DTRAVIS_CI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nvim-install -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=/home/travis/nvim-deps/usr -DMIN_LOG_LEVEL=3 -DPREFER_LUA=ON -DCLANG_ASAN_UBSAN=ON '.
+cmake -G Ninja -DTRAVIS_CI_BUILD=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/nvim-install -DBUSTED_OUTPUT_TYPE=nvim -DDEPS_PREFIX=/home/travis/nvim-deps/usr -DMIN_LOG_LEVEL=3 -DPREFER_LUA=ON -DCLANG_ASAN_UBSAN=ON /home/travis/build/neovim/neovim
...
-- Checking Lua interpreter /home/travis/nvim-deps/usr/bin/luajit
-- Using the Lua interpreter /home/travis/nvim-deps/usr/bin/luajit.

Good question. If you're looking at master, it looks like this:

if(PREFER_LUA)
  find_package(Lua REQUIRED)
  set(LUA_PREFERRED_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
  set(LUA_PREFERRED_LIBRARIES ${LUA_LIBRARIES})
  find_package(LuaJit)
else()
  find_package(LuaJit REQUIRED)
  set(LUA_PREFERRED_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIRS})
  set(LUA_PREFERRED_LIBRARIES ${LUAJIT_LIBRARIES})
endif()

It looks like the find_package(LuaJit) should not be there.

@jszakmeister
Copy link
Contributor

Actually, that looks intentional: 7383274

@jamessan
Copy link
Member

jamessan commented Jun 2, 2018

Yeah, the fallback is intentional since we need a Lua system. The fallbacks should change to only be used if needed, though.

@jszakmeister
Copy link
Contributor

@jamessan I think it's a little more than that reading the comments. It looks like we link nvim with Lua and nvim-test with LuaJit, since it's required (at least according to that commit). So it seems like we need to find both when PREFER_LUA is enabled.

@ZyX-I
Copy link
Contributor

ZyX-I commented Jun 3, 2018

AFAIR the main problem was libnvim-test being built without ASAN, but trying to use library linked with ASAN leading to lots of liker errors. Not sure what were/are the troubles of building luajit, lua and libnvim-test all with ASAN, but the second main problem is that lua does not have ffi. So whether you build lua and libnvim-test with ASAN or not you still have to build luajit, just when you build libnvim-test with ASAN you also need to build luajit with ASAN: I am not sure what ASAN would do when e.g. checking for out-of-bounds array access if said array comes from luajit in this case, but there really are only two options: crash or be useless, and neither option is particularly good.

@justinmk justinmk force-pushed the cmake-findpkg-required branch 3 times, most recently from 1669a5d to 2961bda Compare June 3, 2018 07:26
@justinmk
Copy link
Member Author

justinmk commented Jun 3, 2018

@b-r-o-c-k The MSVC build fails when I add REQUIRED to find_package(Gettext REQUIRED) in src/nvim/po/CMakeLists.txt. Shouldn't #8163 have resolved that?

[00:03:20] CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
[00:03:20]   Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE
[00:03:20]   GETTEXT_MSGFMT_EXECUTABLE)
[00:03:20] Call Stack (most recent call first):
[00:03:20]   C:/Program Files (x86)/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
[00:03:20]   C:/Program Files (x86)/CMake/share/cmake-3.11/Modules/FindGettext.cmake:80 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)

@justinmk justinmk force-pushed the cmake-findpkg-required branch 2 times, most recently from e0d1540 to e71b336 Compare June 3, 2018 17:11
@b-r-o-c-k
Copy link
Contributor

@justinmk The gettext library is split into two parts: runtime (libintl) and tools. #8163 only adds the runtime part to the bundled dependencies. Building the gettext tools requires a lot of dependencies, one of which is libiconv. I will try to add libiconv and a CMake config for the tools to the bundled dependencies.

@justinmk
Copy link
Member Author

justinmk commented Jun 5, 2018

Thanks, let's not bother building the tools then. We can use msys2 gettext tools.

Iconv maybe we can find a binary somewhere.
Edit: attempting to do that now, we can use https://github.com/mlocati/gettext-iconv-windows

@justinmk
Copy link
Member Author

justinmk commented Jun 5, 2018

I see now that our out-of-the-box Visual Studio support depends on the "passive" stuff in master,...

So with the changes in this PR to make those top-level searches REQUIRED, the third-party/CMakeLists.txt never gets a chance to run.

Edit: no, we do find_package(LibUV REQUIRED) and other cases in top-level CMakeLists.txt. And it seems that building deps separately is still required in Visual Studio, I'm not getting consistent out-of-box results if I delete .deps and start over.

@justinmk justinmk force-pushed the cmake-findpkg-required branch from 1705dfa to 3cc1ee5 Compare June 5, 2018 21:28
@janlazo
Copy link
Contributor

janlazo commented Jun 5, 2018

@justinmk What's the use-case for builddeps.bat that cannot be handled by ci/build.ps1?

@justinmk
Copy link
Member Author

justinmk commented Jun 5, 2018

@janlazo will that do the right thing if a developer double-clicks on it or just executes it? If so then we can get rid of builddeps.bat (renamed to makedeps.bat).

@justinmk justinmk force-pushed the cmake-findpkg-required branch from a55550f to 7376ac3 Compare June 5, 2018 22:16
justinmk added 6 commits June 6, 2018 00:58
"Always use `find_package` with `REQUIRED`."

- We make an exception for LuaJit (not REQUIRED): the `nvim-test` target
  is included only if we can find LuaJit.

This is partially a cargo-cult (reference below), but it uncovered at
least one problem: `find_package(LibIntl REQUIRED)` fails on my vanilla
ubuntu 16.04 system.

ref: https://schneide.blog/2017/11/06/4-tips-for-better-cmake/

> optional dependencies is nice, but skipping on REQUIRED is not the way
> you want to do it. In the worst case, some of your features will just
> not work if those packages are not found, with no explanation
> whatsoever. Instead, use explicit feature-toggles (e.g. using option())
> that either skip the find_package call or use it with REQUIRED, so the
> user will know that another lib is needed for this feature.
If check_c_source_compiles() succeeded (HAVE_WORKING_LIBINTL is set)
then the result of find_xxx() doesn't matter. This happens on systems
(linux+glibc) where libintl is available passively.

This allows `find_package(LibIntl REQUIRED)` to work and will still
correctly fail (REQUIRED) on systems lacking libintl.
- We need the gettext tools (msgmerge.exe) because these aren't built
  when we build from source (not trivial).
- We can use the pre-built libiconv-2.dll for DYNAMIC_ICONV_DLL.
ssize_t is already typedef's by libuv:uv-win.h
@justinmk justinmk force-pushed the cmake-findpkg-required branch from 7376ac3 to ec29eee Compare June 5, 2018 23:14
@justinmk justinmk merged commit 36ac80d into neovim:master Jun 5, 2018
@justinmk justinmk deleted the cmake-findpkg-required branch June 5, 2018 23:52
@justinmk
Copy link
Member Author

justinmk commented Jun 6, 2018

on master the MSVC_64 build fails with this mysterious message:

   CMake Error at C:/projects/neovim/cmake/RunXgettext.cmake:13 (message):
    xgettext failed to run correctly:

@janlazo
Copy link
Contributor

janlazo commented Jun 6, 2018

I can't reproduce the error on my machine using #8405

set(GETTEXT_X86_URL https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.19.8.1-v1.15/gettext0.19.8.1-iconv1.15-shared-32.zip)
set(GETTEXT_X86_SHA256 b7d8fe2d038950bc0447d664db614ebfc3100a1ba962a959d78e41bc708a2140)
set(GETTEXT_X86_64_URL https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.19.8.1-v1.15/gettext0.19.8.1-iconv1.15-shared-64.zip)
set(GETTEXT_X86_64_SHA256 c8ed2897438efc0a511892c2b38b623ef0c9092aced2acbd3f3daf2f12ba70b4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used in any builds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes see below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build building and installing Neovim using the provided scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants