diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-04-19 16:04:57 +0100 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2024-08-26 16:44:03 +0200 |
commit | 688b961d13bd54a14836f08c3ded3121d3fb15a0 (patch) | |
tree | b201413b8616abc42283545b146fb1492d56b861 /cmake.deps/cmake | |
parent | 664de5ea971440f24e3e7e3618786d01fbca6025 (diff) | |
download | rneovim-688b961d13bd54a14836f08c3ded3121d3fb15a0.tar.gz rneovim-688b961d13bd54a14836f08c3ded3121d3fb15a0.tar.bz2 rneovim-688b961d13bd54a14836f08c3ded3121d3fb15a0.zip |
feat(treesitter): add support for wasm parsers
Problem: Installing treesitter parser is hard (harder than
climbing to heaven).
Solution: Add optional support for wasm parsers with `wasmtime`.
Notes:
* Needs to be enabled by setting `ENABLE_WASMTIME` for tree-sitter and
Neovim. Build with
`make CMAKE_EXTRA_FLAGS=-DENABLE_WASMTIME=ON
DEPS_CMAKE_FLAGS=-DENABLE_WASMTIME=ON`
* Adds optional Rust (obviously) and C11 dependencies.
* Wasmtime comes with a lot of features that can negatively affect
Neovim performance due to library and symbol table size. Make sure to
build with minimal features and full LTO.
* To reduce re-compilation times, install `sccache` and build with
`RUSTC_WRAPPER=<path/to/sccache> make ...`
Diffstat (limited to 'cmake.deps/cmake')
-rw-r--r-- | cmake.deps/cmake/BuildTreesitter.cmake | 18 | ||||
-rw-r--r-- | cmake.deps/cmake/BuildWasmtime.cmake | 11 | ||||
-rw-r--r-- | cmake.deps/cmake/TreesitterCMakeLists.txt | 2 |
3 files changed, 29 insertions, 2 deletions
diff --git a/cmake.deps/cmake/BuildTreesitter.cmake b/cmake.deps/cmake/BuildTreesitter.cmake index 7eb98163b9..55526b6f1d 100644 --- a/cmake.deps/cmake/BuildTreesitter.cmake +++ b/cmake.deps/cmake/BuildTreesitter.cmake @@ -1,8 +1,24 @@ +if(ENABLE_WASMTIME) + if(USE_BUNDLED_WASMTIME) + set(WASMTIME_CACHE_ARGS "-DCMAKE_C_FLAGS:STRING=-I${DEPS_INSTALL_DIR}/include/wasmtime -I${DEPS_INSTALL_DIR}/include") + else() + find_package(Wasmtime 24.0.0 EXACT REQUIRED) + set(WASMTIME_CACHE_ARGS "-DCMAKE_C_FLAGS:STRING=-I${WASMTIME_INCLUDE_DIR}") + endif() + string(APPEND WASMTIME_CACHE_ARGS " -DTREE_SITTER_FEATURE_WASM") + set(WASMTIME_ARGS -D CMAKE_C_STANDARD=11) +endif() + get_externalproject_options(treesitter ${DEPS_IGNORE_SHA}) ExternalProject_Add(treesitter DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/treesitter PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TreesitterCMakeLists.txt ${DEPS_BUILD_DIR}/src/treesitter/CMakeLists.txt - CMAKE_ARGS ${DEPS_CMAKE_ARGS} + CMAKE_ARGS ${DEPS_CMAKE_ARGS} ${WASMTIME_ARGS} + CMAKE_CACHE_ARGS ${WASMTIME_CACHE_ARGS} ${EXTERNALPROJECT_OPTIONS}) + +if(USE_BUNDLED_WASMTIME) + add_dependencies(treesitter wasmtime) +endif() diff --git a/cmake.deps/cmake/BuildWasmtime.cmake b/cmake.deps/cmake/BuildWasmtime.cmake new file mode 100644 index 0000000000..d3c51ebdc7 --- /dev/null +++ b/cmake.deps/cmake/BuildWasmtime.cmake @@ -0,0 +1,11 @@ +# wasmtime is a chungus -- optimize _extra hard_ to keep nvim svelte +get_externalproject_options(wasmtime ${DEPS_IGNORE_SHA}) +ExternalProject_Add(wasmtime + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/wasmtime + SOURCE_SUBDIR crates/c-api + CMAKE_ARGS ${DEPS_CMAKE_ARGS} + -D WASMTIME_FASTEST_RUNTIME=ON # build with full LTO + -D WASMTIME_DISABLE_ALL_FEATURES=ON # don't need all that crap... + -D WASMTIME_FEATURE_CRANELIFT=ON # ...except this one (compiles wasm to platform code) + USES_TERMINAL_BUILD TRUE + ${EXTERNALPROJECT_OPTIONS}) diff --git a/cmake.deps/cmake/TreesitterCMakeLists.txt b/cmake.deps/cmake/TreesitterCMakeLists.txt index 71174bfe5b..81ebfc4aed 100644 --- a/cmake.deps/cmake/TreesitterCMakeLists.txt +++ b/cmake.deps/cmake/TreesitterCMakeLists.txt @@ -5,7 +5,7 @@ add_compile_options(-w) add_library(tree-sitter lib/src/lib.c) target_include_directories(tree-sitter - PRIVATE lib/src lib/include) + PRIVATE lib/src lib/src/wasm lib/include) install(FILES lib/include/tree_sitter/api.h |