安装go 1.19
go version
查看go版本,如果低于1.19的话需要升级到1.19。下面是从源码手动升级到go 1.19的方法:
# https://go.dev/doc/install/source#install
wget https://go.dev/dl/go1.19.3.src.tar.gz
tar xzf go1.19.3.src.tar.gz
mv go ~/.local/
cd ~/.local/go
cd src
./all.bash
echo 'export PATH="~/.local/go/bin:$PATH"' >> ~/.bashrc
下载最新版clash
wget https://github.com/Dreamacro/clash/archive/refs/tags/v1.12.0.tar.gz
tar xzf v1.12.0.tar.gz
cd clash-1.12.0/
升级依赖中的bbolt
依赖中的bbolt版本太老了,不支持loong64,go build
的时候会报这个错:
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/db.go:133:13: undeclared name maxMapSize for array length
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/db.go:422:12: undefined: maxMapSize
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/db.go:440:10: undefined: maxMapSize
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/db.go:441:8: undefined: maxMapSize
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/db.go:932:2: pos declared but not used
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/bolt_unix.go:68:15: undeclared name maxMapSize for array length
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/tx.go:532:12: undefined: maxAllocSize
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/tx.go:533:10: undefined: maxAllocSize
../../go/pkg/mod/go.etcd.io/bbolt@v1.3.6/unsafe.go:27:12: undeclared name maxAllocSize for array length
升级到最新版即可:
# https://stackoverflow.com/questions/53682247/how-to-point-go-module-dependency-in-go-mod-to-a-latest-commit-in-a-repo
go get go.etcd.io/bbolt@master
将uio更换为带有loong64支持的版本
uio上游不支持loong64,直接编译会报错:
../../go/pkg/mod/github.com/u-root/uio@v0.0.0-20210528114334-82958018845c/uio/buffer.go:176:19: undefined: ubinary.NativeEndian
武老师已经提交了PR: https://github.com/u-root/uio/pull/6
上游似乎认为加入对loong64的支持会使得对go的版本要求变成至少1.19,这可能会导致一些问题,因此只同意了其中不会提高go版本要求的修改。暂时不清楚这个修改被merge之后能不能使得它在loong64中可以被编译,而且这个PR目前也没有被merge。
我创建了一个带有对loong64的完全支持的fork: https://github.com/seekstar/uio/tree/loong64
把依赖中的uio换成这个fork即可:
# https://stackoverflow.com/questions/72312460/how-to-replace-a-go-module-with-a-major-version-to-a-fork-master
go get -d -u github.com/seekstar/uio@loong64
echo "replace github.com/u-root/uio v0.0.0-20210528114334-82958018845c => github.com/seekstar/uio loong64" >> go.mod
go mod tidy
# replace github.com/u-root/uio v0.0.0-20210528114334-82958018845c => github.com/seekstar/uio v0.0.0-20221126081914-36bb9a6fded0
编译
go build