mirror of
https://github.com/neovim/neovim.git
synced 2026-03-29 11:52:04 +00:00
fix(cmake): linker flags, doc generation for cross-compilation #38215
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 `$<TARGET_FILE:nvim_bin>` 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.
This commit is contained in:
@@ -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 $<TARGET_FILE:nvim_bin>)
|
||||
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 $<TARGET_FILE:nvim_bin>
|
||||
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 $<TARGET_FILE:nvim_bin>
|
||||
COMMAND ${NVIM_HOST_PRG}
|
||||
-u NONE -i NONE -e --headless -c "helptags ++t doc" -c quit
|
||||
DEPENDS
|
||||
nvim_bin
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user