mirror of
https://github.com/neovim/neovim
synced 2025-07-15 16:51:49 +00:00
build: support static build #34728
This commit is contained in:
23
BUILD.md
23
BUILD.md
@ -259,6 +259,29 @@ cmake --build build
|
|||||||
- Using `ninja` is strongly recommended.
|
- Using `ninja` is strongly recommended.
|
||||||
4. If treesitter parsers are not bundled, they need to be available in a `parser/` runtime directory (e.g. `/usr/share/nvim/runtime/parser/`).
|
4. If treesitter parsers are not bundled, they need to be available in a `parser/` runtime directory (e.g. `/usr/share/nvim/runtime/parser/`).
|
||||||
|
|
||||||
|
### How to build static binary (on Linux)
|
||||||
|
|
||||||
|
1. Use a linux distribution which uses musl C. We will use Alpine Linux but any distro with musl should work. (glibc does not support static linking)
|
||||||
|
2. Run make passing the `STATIC_BUILD` variable: `make CMAKE_EXTRA_FLAGS="-DSTATIC_BUILD=1"`
|
||||||
|
|
||||||
|
In case you are not using Alpine Linux you can use a container to do the build the binary:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
podman run \
|
||||||
|
--rm \
|
||||||
|
-it \
|
||||||
|
-v "$PWD:/workdir" \
|
||||||
|
-w /workdir \
|
||||||
|
alpine:latest \
|
||||||
|
bash -c 'apk add build-base cmake coreutils curl gettext-tiny-dev && make CMAKE_EXTRA_FLAGS="-DSTATIC_BUILD=1"'
|
||||||
|
```
|
||||||
|
|
||||||
|
The resulting binary in `build/bin/nvim` will have all the dependencies statically linked:
|
||||||
|
|
||||||
|
```
|
||||||
|
build/bin/nvim: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=b93fa8e678d508ac0a76a2e3da20b119105f1b2d, with debug_info, not stripped
|
||||||
|
```
|
||||||
|
|
||||||
#### Debian 10 (Buster) example:
|
#### Debian 10 (Buster) example:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -748,7 +748,11 @@ endif()
|
|||||||
|
|
||||||
target_sources(nlua0 PUBLIC ${NLUA0_SOURCES})
|
target_sources(nlua0 PUBLIC ${NLUA0_SOURCES})
|
||||||
|
|
||||||
|
if(STATIC_BUILD)
|
||||||
|
target_link_options(nvim_bin PRIVATE -static-libgcc -static-libstdc++ -static)
|
||||||
|
endif()
|
||||||
target_link_libraries(nvim_bin PRIVATE main_lib PUBLIC libuv)
|
target_link_libraries(nvim_bin PRIVATE main_lib PUBLIC libuv)
|
||||||
|
|
||||||
install_helper(TARGETS nvim_bin)
|
install_helper(TARGETS nvim_bin)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
install(FILES $<TARGET_PDB_FILE:nvim_bin> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
|
install(FILES $<TARGET_PDB_FILE:nvim_bin> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
|
||||||
|
Reference in New Issue
Block a user