Previously I talked about my excitement for RISC-V, with one of my goals to see if I can get a decentralised stack running on top of it. My first project was to get IPFS running on RISC-V.

Checking source for incompatibilities

IPFS is written in Go. The Golang team have done a lot of hard work getting the compilers and runtime working on different architectures, with RISC-V being one of them. I encountered one bug in a deep dependency of Go on RISC-V, involving procfs and an undefined: parseCPUInfo compile error.

...
go build  "-asmflags=all='-trimpath='" "-gcflags=all='-trimpath='" -ldflags="-X "github.com/ipfs/go-ipfs".CurrentCommit=79a55305e" -o "cmd/ipfs/ipfs" "github.com/ipfs/go-ipfs/cmd/ipfs"
# github.com/prometheus/procfs
../../go/pkg/mod/github.com/prometheus/[email protected]/cpuinfo.go:71:9: undefined: parseCPUInfo
make: *** [cmd/ipfs/Rules.mk:22: cmd/ipfs/ipfs] Error 2

It involved some digging to get to the root cause and find a way to resolve, but luckily there is a PR available to fix it https://github.com/prometheus/procfs/pull/325

After applying the patch, I was able to successfully build IPFS on my emulated IPFS environment, as well as pin & host my blog on the IPFS network.

Tracking RISC-V support: I have submitted a new issue on the go-ipfs repo to track the support of RISC-V https://github.com/ipfs/go-ipfs/issues/7781

IPFS + RISC-V

Build process

These steps assume you have running version of Debian on RISC-V.
See my previous post Emulating RISC-V Debian on WSL2.

Then it is a matter of mostly following the standard IPFS build instructions

# Install build tools
apt update
apt install golang git make

# Clone IPFS repo
git clone https://github.com/ipfs/go-ipfs.git
cd go-ipfs

# Apply temporary patch to fix a broken dependency https://github.com/prometheus/procfs/pull/325
# Maybe try building first before applying the patch in case this has been resolved.
go mod edit -replace=github.com/prometheus/procfs=github.com/prometheus/procfs@910e685

# Build!
# Will output to ./cmd/ipfs/ipfs
make build

# Can optionally install
make install

From here you’ll be able to use the standard IPFS commands https://docs.ipfs.io/how-to/command-line-quick-start/

IPFS running on RISC-V