Before you start
Loongson systems are split between the so-called New World and Old World ecosystems, and software built for one does not work on the other. The Cloudreve build described here is only for the New World side of Loongson.
At the time these steps were put together, the only New World system adapted for the JJW Pie was Buildroot.
The build environment used here is Ubuntu 22.04 LTS amd64. Other Linux distributions should be broadly similar.
Set up Golang
Download the Go archive:
wget https://golang.google.cn/dl/go1.23.3.linux-amd64.tar.gz
Extract it:
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.23.3.linux-amd64.tar.gz
Add Go to the global PATH:
sudo echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
Reload the environment:
source /etc/profile
Install Node.js
If you are building on your own machine or on a server in mainland China, using a mirror can make the Node.js setup much faster.
export NODE_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/
Then install Node.js:
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n | sudo bash -s install lts
Optionally switch npm to a mirror:
npm config set registry https://registry.npmmirror.com
Install Yarn:
sudo npm install -g yarn
Optionally set a Yarn mirror as well:
yarn config set registry https://registry.npmmirror.com
Fetch the Cloudreve source
Install git and zip first if they are not already present:
sudo apt update
sudo apt install -y git zip
Clone the repository together with its submodules:
git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git
Enter the project directory and switch to version 3.8.3, which was the latest release used here:
cd Cloudreve
git checkout 3.8.3
Build Cloudreve for loong64
If your build machine is local or located in mainland China, configuring a Go module proxy is also recommended:
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
Install GoReleaser:
go install github.com/goreleaser/goreleaser@latest
Next, edit .goreleaser.yaml.
Remove windows and darwin from goos, remove all existing architectures from goarch, and add loong64. To shrink the final binary, append -s -w to the end of the ldflags arguments so symbol table and debug information are stripped.
The relevant part should look like this:
此处省略...
ldflags:
- -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion={{.Tag}}' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit={{.ShortCommit}}' -s -w
goos:
- linux
goarch:
- loong64
此处省略...
A direct build will fail because two dependencies are too old. Update them first:
go get modernc.org/[email protected]
go get modernc.org/[email protected]
After that, run the build:
~/go/bin/goreleaser build --clean --snapshot
The compiled executable will be placed in:
dist/Cloudreve_linux_loong64/