neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 3711a0387a96d6531f3ae07a9b18fb8e2afc2e41
parent 435dee74bb3593b778328138dac054f26e2d7396
Author: bfredl <bjorn.linse@gmail.com>
Date:   Sat, 27 Apr 2024 09:21:46 +0200

refactor(build): make all generated c files headers

There's no "rule" or bad practice or whatever that says we cannot
generate c files. it is is just that we have ~20 generated headers
and ~2 generated sources and there is nothing in these two generated
source files which sets them aparts. Lua bindings are not different from
rpc bindings, and pathdef is not different from versiondef.

So to simplify build logic and ease the future port to build.zig,
streamline the build to only have generated headers, no direct generated
.c files.

Also "nlua_add_api_functions" had its prototype duplicated twice which
defeated the point of having mandatory prototypes (one source of truth).

Diffstat:
Mcmake.config/CMakeLists.txt | 4++--
Dcmake.config/pathdef.c.in | 4----
Acmake.config/pathdef.h.in | 3+++
Msrc/nvim/CMakeLists.txt | 14++------------
Msrc/nvim/generators/gen_api_dispatch.lua | 19-------------------
Asrc/nvim/lua/api_wrappers.c | 18++++++++++++++++++
Msrc/nvim/lua/executor.h | 2+-
Msrc/nvim/os/env.c | 1+
8 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/cmake.config/CMakeLists.txt b/cmake.config/CMakeLists.txt @@ -194,6 +194,6 @@ file(GENERATE INPUT "${PROJECT_BINARY_DIR}/cmake.config/auto/versiondef.h.gen") configure_file ( - "${PROJECT_SOURCE_DIR}/cmake.config/pathdef.c.in" - "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.c" + "${PROJECT_SOURCE_DIR}/cmake.config/pathdef.h.in" + "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.h" ESCAPE_QUOTES) diff --git a/cmake.config/pathdef.c.in b/cmake.config/pathdef.c.in @@ -1,4 +0,0 @@ -#include "${PROJECT_SOURCE_DIR}/src/nvim/vim_defs.h" -char *default_vim_dir = "${CMAKE_INSTALL_FULL_DATAROOTDIR}/nvim"; -char *default_vimruntime_dir = ""; -char *default_lib_dir = "${CMAKE_INSTALL_FULL_LIBDIR}/nvim"; diff --git a/cmake.config/pathdef.h.in b/cmake.config/pathdef.h.in @@ -0,0 +1,3 @@ +char *default_vim_dir = "${CMAKE_INSTALL_FULL_DATAROOTDIR}/nvim"; +char *default_vimruntime_dir = ""; +char *default_lib_dir = "${CMAKE_INSTALL_FULL_LIBDIR}/nvim"; diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt @@ -327,7 +327,7 @@ set(GENERATED_UI_EVENTS_CALL ${GENERATED_DIR}/ui_events_call.generated.h) set(GENERATED_UI_EVENTS_CLIENT ${GENERATED_DIR}/ui_events_client.generated.h) set(GENERATED_UI_EVENTS_REMOTE ${GENERATED_DIR}/ui_events_remote.generated.h) set(GENERATED_UNICODE_TABLES ${GENERATED_DIR}/unicode_tables.generated.h) -set(LUA_API_C_BINDINGS ${GENERATED_DIR}/lua_api_c_bindings.generated.c) +set(LUA_API_C_BINDINGS ${GENERATED_DIR}/lua_api_c_bindings.generated.h) set(VIM_MODULE_FILE ${GENERATED_DIR}/lua/vim_module.generated.h) # NVIM_RUNTIME_DIR @@ -505,7 +505,6 @@ set(LUA_GEN_DEPS ${GENERATOR_PRELOAD} $<TARGET_FILE:nlua0>) # NVIM_GENERATED_FOR_HEADERS: generated headers to be included in headers # NVIM_GENERATED_FOR_SOURCES: generated headers to be included in sources -# NVIM_GENERATED_SOURCES: generated source files # These lists must be mutually exclusive. foreach(sfile ${NVIM_SOURCES} ${GENERATED_API_DISPATCH} @@ -620,10 +619,6 @@ add_custom_command( VERBATIM ) -list(APPEND NVIM_GENERATED_SOURCES - "${LUA_API_C_BINDINGS}" -) - add_custom_command( OUTPUT ${GENERATED_UI_EVENTS_CALL} ${GENERATED_UI_EVENTS_REMOTE} @@ -657,10 +652,7 @@ list(APPEND NVIM_GENERATED_FOR_SOURCES "${GENERATED_OPTIONS_MAP}" "${GENERATED_UNICODE_TABLES}" "${VIM_MODULE_FILE}" -) - -list(APPEND NVIM_GENERATED_SOURCES - "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.c" + "${PROJECT_BINARY_DIR}/cmake.config/auto/pathdef.h" ) add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS} @@ -709,7 +701,6 @@ endif() target_sources(main_lib INTERFACE ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS} - ${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS} ${EXTERNAL_SOURCES} @@ -909,7 +900,6 @@ add_subdirectory(po) add_custom_target(generated-sources DEPENDS ${NVIM_GENERATED_FOR_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} - ${NVIM_GENERATED_SOURCES} ) file(GLOB API_SOURCES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/nvim/api/*.c) diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua @@ -716,23 +716,6 @@ end -- start building lua output output = assert(io.open(lua_c_bindings_outputf, 'wb')) -output:write([[ -#include <lua.h> -#include <lualib.h> -#include <lauxlib.h> - -#include "nvim/ex_docmd.h" -#include "nvim/ex_getln.h" -#include "nvim/func_attr.h" -#include "nvim/globals.h" -#include "nvim/api/private/defs.h" -#include "nvim/api/private/helpers.h" -#include "nvim/api/private/dispatch.h" -#include "nvim/lua/converter.h" -#include "nvim/lua/executor.h" -#include "nvim/memory.h" - -]]) include_headers(output, headers) output:write('\n') @@ -975,8 +958,6 @@ end output:write(string.format( [[ void nlua_add_api_functions(lua_State *lstate) - REAL_FATTR_NONNULL_ALL; -void nlua_add_api_functions(lua_State *lstate) { lua_createtable(lstate, 0, %u); ]], diff --git a/src/nvim/lua/api_wrappers.c b/src/nvim/lua/api_wrappers.c @@ -0,0 +1,18 @@ +#include <lauxlib.h> +#include <lua.h> +#include <lualib.h> + +#include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" +#include "nvim/api/private/helpers.h" +#include "nvim/ex_docmd.h" +#include "nvim/ex_getln.h" +#include "nvim/func_attr.h" +#include "nvim/globals.h" +#include "nvim/lua/converter.h" +#include "nvim/lua/executor.h" +#include "nvim/memory.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "lua_api_c_bindings.generated.h" +#endif diff --git a/src/nvim/lua/executor.h b/src/nvim/lua/executor.h @@ -12,7 +12,7 @@ #include "nvim/types_defs.h" #include "nvim/usercmd.h" // IWYU pragma: keep -// Generated by msgpack-gen.lua +// Generated by generators/gen_api_dispatch.lua void nlua_add_api_functions(lua_State *lstate) REAL_FATTR_NONNULL_ALL; typedef struct { diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c @@ -49,6 +49,7 @@ #endif #ifdef INCLUDE_GENERATED_DECLARATIONS +# include "auto/pathdef.h" # include "os/env.c.generated.h" #endif