Setting up a PDS on RISC-V

@engielolz.ritsuko.akizuki.best

Setting up a PDS on RISC-V

This is a RISC-V endeavor, if you know what I mean :)

Because the Docker image doesn't support RISC-V, we'll need to do this Docker-less. This guide only covers the PDS itself; for the reverse proxy, I recommend @benharri.org's guide as that's what I used and it works very well.

This guide assumes at least some familiarity with the Linux command line and some basic problem solving skills. It doesn't require knowledge of Node.js (lol)

If you don't have a RISC-V machine, you can still follow along by setting up a RISC-V Ubuntu Server 24.04 VM with this guide. Be aware however that the PDS won't be able to connect to the Bluesky network (unless you know QEMU networking).

Setup

I'm using a StarFive VisionFive 2, equipped with 4GB of RAM and a 1TB NVMe SSD loaded with Ubuntu Server 24.04. If you actually want to use this as a PDS, you shouldn't run it off a microSD Card unless you don't care about your data or identity.

Disclaimer

I have no idea what I'm doing when it comes to Node.js. I'm just doing what I think is right given the less-than-ideal circumstances, which it probably isn't.

Additionally, this guide assumes you're using Ubuntu 24.04. If you're using a different distro or version of Ubuntu, you'll need to adapt these instructions.

Set up Node.js

Node.js is not available for RISC-V officially, so we need to use an unofficial build. I used v20.18.1, which is the newest 20.x version as of writing (the Bluesky PDS Docker image uses v20.11.0)

For the sake of simplicity, we're going to install to /usr/local so we don't have to mess with our path.

Download and install Node.js: curl -L https://unofficial-builds.nodejs.org/download/release/v20.18.1/node-v20.18.1-linux-riscv64.tar.gz | sudo tar -xz -C /usr/local --strip-components=1

Now try to run node. In my case I needed to install libatomic1 first: sudo apt install libatomic1

It worked if you get a prompt. Type .exit to leave.

PDS Setup, Part One

I already had git installed but you will need to install it if you don't have it: sudo apt install git

git clone the PDS repository: git clone https://github.com/bluesky-social/pds

This needs pnpm so we will need to install it: npm install -g pnpm@latest

A few dependencies require building from source. I wouldn't recommend installing build tools on a server (makes it less secure) but in this case we have no choice: sudo apt install build-essential You can always remove the build tools later.

If you're getting errors about the lockfile you may need to install an earlier version of pnpm with something like: npm install -g pnpm@latest-9

The fun part, pulling in the dependencies: pnpm install --production --frozen-lockfile

As we're compiling from source, this will take some time (10 minutes on the VisionFive 2), so sit back and relax, maybe get yourself some coffee (or in Metric units, tea)

libvips and sharp

If you try to run the PDS as is, it will fail because sharp is missing libvips. You see, there is no RISC-V libvips binary, nor does it try to compile one. Now Ubuntu 24.04 ships with its own libvips, but it's too old (8.15.1 when we need at least 8.15.3). Therefore we have to build libvips from source, and then build sharp from source so it'll use it.

build libvips

libvips has many dependencies for building, and the easiest way to get them (on Ubuntu 24.04) is to install libvips-dev to pull in the dependencies and then remove libvips (called libvips42t64 on Ubuntu 24.04). Make sure you don't run sudo apt autoremove before you're done building or you'll have to do it again. And double check to make sure the native libvips package isn't installed or vips will report as 8.15.1.

The official build instructions for libvips are here.

Compling libvips is easy enough so I won't go over it here; just follow the official build instructions. Set the prefix to /usr/local as we will be using it on this machine.

build sharp

The version of sharp you build must match what the PDS is using.

Create a new folder somewhere and run npm install --save node-addon-api node-gyp to install build dependencies. Now run SHARP_FORCE_GLOBAL_LIBVIPS=1 npm install --build-from-source sharp. For some reason it didn't work with just the --build-from-source flag, but the environment variable worked for me.

After it's done, check for the existence of the node_modules/sharp/src/build/Release folder, there should be a binary in there. If there isn't, something probably failed or it didn't actually compile.

Getting sharp working

This is the part where the TypeScript people will start crying because of what we're gonna have to do to make everything work.

Actually, we only need to do one thing. You might have guessed, but we need to copy the sharp we built to the sharp that the PDS is using. Double check the sharp versions match.

cp -r /sharp-build-path/node_modules/sharp/src/build /pds-path/service/node_modules/.pnpm/sharp@0.33.5/node_modules/sharp/src

Actual PDS configuration

For here on, you can just follow @benharri.org's guide. However, I recommend you add PDS_BLOB_UPLOAD_LIMIT=52428800 to your env file, otherwise you may experience issues with video and other blob uploads.

Updating

Unsupported configurations like this might break with updates, so express caution when doing so. Things are certain to break if sharp is updated though. To fix sharp you will need to build the newer version of sharp that the PDS requires. You may also need to build a newer version of libvips if it depends on it.

Closing remarks

  • I performed some testing, and while everything appears to work fine, given how we're in several layers of "not officially supported", I wouldn't recommend this for production use.
  • I'd like to see official RISC-V support in sharp. Having to build libvips and sharp from source is a major hurdle that shouldn't be there.
  • Following that, I'd also like to see official RISC-V support from Node.js. I'm sure this will happen eventually though.
engielolz.ritsuko.akizuki.best
RicchanStan765

@engielolz.ritsuko.akizuki.best

I'm someone who likes (retro)computing, gaming, atproto and THE iDOLM@STER, especially Ritsuko Akizuki.
(he/him)

Other socials and stuff on my website: engielolz.ritsuko.akizuki.best/index.htm

Post reaction in Bluesky

*To be shown as a reaction, include article link in the post or add link card

Reactions from everyone (0)