From 8aacce90b4b6bc997f4840c84809876ac3d6251d Mon Sep 17 00:00:00 2001 From: Rawan Khalid <145160003+Rawan10101@users.noreply.github.com> Date: Wed, 11 Mar 2026 21:05:46 +0200 Subject: [PATCH] fix(cmake): linker flags, doc generation for cross-compilation #38215 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Cross-compilation issues encountered when building Neovim for WASM. When cross-compiling, three issues occur: 1. `-Wl,--no-undefined` — not supported by `wasm-ld` 2. `-lutil` — not available in the Emscripten sysroot 3. Doc generation fails because CMake tries to execute `$` on the host machine, which fails because the binary is not native to the host. It fails with `/bin/sh: nvim.js: Permission denied` Solution: The fix includes skipping `-Wl,--no-undefined` and `-lutil` with `NOT CMAKE_CROSSCOMPILING` and adding `NVIM_HOST_PRG` variable to `runtime/CMakeLists.txt` so when cross-compiling, it uses a host native nvim binary for doc generation instead of using the cross-compiled target. --- runtime/CMakeLists.txt | 7 +++++-- src/nvim/CMakeLists.txt | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index fdd846561e..f5f5527d27 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -5,6 +5,9 @@ set(GENERATED_PACKAGE_DIR ${GENERATED_RUNTIME_DIR}/pack/dist/opt) set(GENERATED_SYN_VIM ${GENERATED_RUNTIME_DIR}/syntax/vim/generated.vim) set(SYN_VIM_GENERATOR ${PROJECT_SOURCE_DIR}/src/gen/gen_vimvim.lua) +if(NOT NVIM_HOST_PRG) + set(NVIM_HOST_PRG $) +endif() file(MAKE_DIRECTORY ${GENERATED_RUNTIME_DIR}/syntax/vim) get_directory_property(LUA_GEN DIRECTORY ${PROJECT_SOURCE_DIR}/src/nvim DEFINITION LUA_GEN) @@ -38,7 +41,7 @@ foreach(PACKAGE ${PACKAGES}) add_custom_command(OUTPUT "${GENERATED_PACKAGE_DIR}/${PACKNAME}/doc/tags" COMMAND ${CMAKE_COMMAND} -E copy_directory ${PACKAGE} ${GENERATED_PACKAGE_DIR}/${PACKNAME} - COMMAND $ + COMMAND ${NVIM_HOST_PRG} -u NONE -i NONE -e --headless -c "helptags doc" -c quit DEPENDS nvim_bin @@ -70,7 +73,7 @@ add_custom_command(OUTPUT ${GENERATED_HELP_TAGS} COMMAND ${CMAKE_COMMAND} -E remove_directory doc COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/runtime/doc doc - COMMAND $ + COMMAND ${NVIM_HOST_PRG} -u NONE -i NONE -e --headless -c "helptags ++t doc" -c quit DEPENDS nvim_bin diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 0b5f2e0d62..15aa28c6ba 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -143,7 +143,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") endif() # workaround for clang-11 on macOS, supported on later versions - if(NOT APPLE) + if(NOT APPLE AND NOT CMAKE_CROSSCOMPILING) target_link_libraries(nvim_bin PRIVATE -Wl,--no-undefined) endif() endif() @@ -154,7 +154,7 @@ if(UNIX) if (CMAKE_SYSTEM_NAME STREQUAL "Haiku") target_link_libraries(main_lib INTERFACE bsd) target_link_libraries(nvim_bin PRIVATE -lnetwork) - elseif (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS") + elseif (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND NOT CMAKE_CROSSCOMPILING) target_link_libraries(main_lib INTERFACE util) endif() endif()