September 21, 2024 —
Andres H
Hmm. It had been a while from my last post, but I received not too much time ago a riscv SBC. I was pretty excited, to just check it out but after testing out spacemiT bianbuOS I was dissapointed about the performance.
I decided to try and install terminal based code editor such as neovim/helix, but after apt-get returned no results for the architecture, I was pretty surprised but I thought (meh it has to be that at this moment that is not the focus). So I just decided "why not experiment building from source some fun stuff", so I tried to compile helix-editor as Rust was available for riscv, then when trying to compile hit a wall as kernel 6.1.15 had a nasty error and well had to be patched at kernel level, then I had to decide, should I continue? should I wait for a new kernel to be released? I chose the second.
Then while waiting (at the time of this blog post yet we are all waiting for kernel 6.6 to be released for this SBC) I decided to try a different editor, something maybe not that uncommon like and I jump ahead and tried to build Neovim
danaus@bananapif3
-----------------
█ █ █ █ █ █ █ █ █ █ █ OS: Armbian (24.5.0-trunk) riscv64
███████████████████████ Host: spacemit k1-x deb1 board
▄▄██ ██▄▄ Kernel: 6.1.15-legacy-k1
▄▄██ ███████████ ██▄▄ Uptime: 6 mins
▄▄██ ██ ██ ██▄▄ Packages: 1292 (dpkg)
▄▄██ ██ ██ ██▄▄ Shell: bash 5.2.15
▄▄██ ██ ██ ██▄▄ Resolution: 1680x1050
▄▄██ █████████████ ██▄▄ DE: GNOME 45.2
▄▄██ ██ ██ ██▄▄ WM: Mutter
▄▄██ ██ ██ ██▄▄ WM Theme: Adwaita
▄▄██ ██ ██ ██▄▄ Theme: Flat-Remix-GTK-Light-Solid [GTK2/3]
▄▄██ ██▄▄ Icons: Flat-Remix-Green-Light [GTK2/3]
███████████████████████ Terminal: x-terminal-emul
█ █ █ █ █ █ █ █ █ █ █ CPU: Spacemit X60 (8) @ 1.600GHz
Memory: 652MiB / 3805MiB
And as I stated before, I let the output of an attempt to install neovim from repository.
danaus@bananapif3:~$ sudo apt-get install neovim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package neovim is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'neovim' has no installation candidate
I went ahead to neovim's repo and selected 0.10 release and read the docs about building it.
First tried quick install so lets build prerequisites as the docs suggested:
sudo apt-get install ninja-build gettext cmake unzip curl build-essential
Then quickly continue on clonning the repo and try to make the installation.
git clone https://github.com/neovim/neovim
cd neovim
git switch release-0.10
make CMAKE_BUILD_TYPE=RelWithDebInfo
But it was not able to complete. Here is the summary:
FAILED: build/src/luajit-stamp/luajit-install /home/danaus/neovim/.deps/build/src/luajit-stamp/luajit-install
cd /home/danaus/neovim/.deps/build/src/luajit && /usr/bin/gmake -j CFLAGS=-fPIC CFLAGS+=-DLUA_USE_APICHECK CFLAGS+=-funwind-tables CCDEBUG+=-g Q= CC=/usr/bin/cc PREFIX=/home/danaus/neovim/.deps/usr install && /usr/bin/cmake -E touch /home/danaus/neovim/.deps/build/src/luajit-stamp/luajit-install
gmake[1]: Entering directory '/home/danaus/neovim/.deps/build/src/luajit'
==== Building LuaJIT 2.1 ====
/usr/bin/gmake -C src
gmake[2]: Entering directory '/home/danaus/neovim/.deps/build/src/luajit/src'
lj_arch.h:69:2: error: #error "Architecture not supported (in this version), see: https://luajit.org/status.html#architectures"
69 | #error "Architecture not supported (in this version), see: https://luajit.org/status.html#architectures"
| ^~~~~
lj_arch.h:443:2: error: #error "No target architecture defined"
443 | #error "No target architecture defined"
| ^~~~~
Makefile:270: *** Unsupported target architecture. Stop.
gmake[2]: Leaving directory '/home/danaus/neovim/.deps/build/src/luajit/src'
gmake[1]: *** [Makefile:125: src/luajit] Error 2
gmake[1]: Leaving directory '/home/danaus/neovim/.deps/build/src/luajit'
[56/120] Performing configure step for 'treesitter_query'
-- The C compiler identification is GNU 13.2.0
........
ninja: build stopped: subcommand failed.
make: *** [Makefile:87: deps] Error 1
Quick inspection, and Eureka I needed some deps and use the manual installation with external dependencies (easy piece, right?). For Neovim version 0.10 I will need to install:
libuv libluv libvterm luajit lua-lpeg lua-mpack msgpack-c tree-sitter tree-sitter-c tree-sitter-lua tree-sitter-markdown tree-sitter-query tree-sitter-vim tree-sitter-vimdoc unibilium
Let's go ahead. And try to install most of things.
sudo apt-get install lua5.1
sudo apt-get install lua-luv lua-luv-dev
No issues, next install LuaJit
danaus@bananapif3:~/neovim$ sudo apt-get install luajit
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package luajit is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'luajit' has no installation candidate
So as stated before it seems that there is no native riscv64 LuaJit then I cannot continue. Hmm pretty annoying. Checking the source of LuaJit yet riscv64 is not supported. I decided to search for a port of the library. And I was very very lucky that already there is one available here, just not easy to find.
git clone https://github.com/plctlab/LuaJIT.git
cd LuaJIT/
danaus@bananapif3:~/LuaJIT$ git branch
* riscv64-v2.1-branch
sudo make install
Waiting a while gave me the following:
ln -sf luajit-2.1.1725179068 /usr/local/bin/luajit
==== Successfully installed LuaJIT 2.1.1725179068 to /usr/local ====
Then to check if my deps were helping me to progress in the build process I decided to try a compile on neovim again
danaus@bananapif3:~/neovim$ cmake -S cmake.deps -B .deps -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_BUNDLED=OFF -DUSE_BUNDLED_LIBVTERM=ON -DUSE_BUNDLED_LUAJIT=OFF
-- Found GNU Make at /usr/bin/gmake
-- CMAKE_BUILD_TYPE=RelWithDebInfo
-- Found Luajit: /usr/local/lib/libluajit-5.1.so
-- Could NOT find Lua (missing: LUA_LIBRARIES LUA_INCLUDE_DIR) (Required is exact version "5.1")
-- Configuring done (1.5s)
-- Generating done (0.2s)
-- Build files have been written to: /home/danaus/neovim/.deps
Pretty rookie mistake Lua was missing but I am pretty sure I had installed, I soon realize that I had installed runtime instead of dev files.
sudo apt-get install liblua5.1-0-dev
Another try.
danaus@bananapif3:~/neovim$ cmake -S cmake.deps -B .deps -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_BUNDLED=OFF -DUSE_BUNDLED_LIBVTERM=ON -DUSE_BUNDLED_LUAJIT=OFF
-- Found GNU Make at /usr/bin/gmake
-- CMAKE_BUILD_TYPE=RelWithDebInfo
-- Found Lua: /usr/lib/riscv64-linux-gnu/liblua5.1.so;/usr/lib/riscv64-linux-gnu/libm.so (found suitable exact version "5.1.5")
-- Configuring done (1.4s)
-- Generating done (0.1s)
-- Build files have been written to: /home/danaus/neovim/.deps
danaus@bananapif3:~/neovim$ cmake --build .deps
....
[28/28] Completed 'treesitter'
Yeah, dependencies completed. I crossed my fingers and then attemped the final build.
cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
And just for fun
sudo make install
....
[0/2] Re-checking globbed directories...
[2/3] Install the project...
-- Install configuration: "Debug"
-- Set runtime path of "/usr/local/bin/nvim" to ""
Even lua worked
Success!
Tags: tech