目录

Gentoo RISC-V Keywording 流程

这篇记录在 Gentoo 上做 RISC-V keywording 的流程:在 amd64 机器上用 QEMU 模拟 RISC-V,跑测试,再把 ~riscv 关键字提交上去。

准备一台 Gentoo amd64 虚拟机,QEMU 用来模拟 RISC-V。桌面应用的测试可以用 LXD 或 Incus,具体参考 Juippis 的测试环境、Incus 跑 Gentoo PR 测试 和 Incus 文档。

需要装的软件:

软件 用途
app-emulation/qemu 在 amd64 下模拟 RISC-V
sys-apps/bubblewrap 非特权沙盒,类似 chroot
www-client/pybugz Bugzilla 命令行客户端

还需要两个账号:

提交要 GPG 签名,先参考 GitHub 的说明 生成并配置 GPG key。

先看 Packages 页面确认关键字情况。截图里拿 terraform 举例,后面的命令换成 app-metrics/prometheus,流程一样。

Gentoo Packages 页面

当时 app-metrics/prometheus 还没有 ~riscv 关键字,就拿它走一遍。

设置 QEMU 的 USE 并安装:

echo "app-emulation/qemu static-user QEMU_USER_TARGETS: riscv32 riscv64" >> /etc/portage/package.use/qemu
emerge -vj app-emulation/qemu --autounmask

创建二进制包:

quickpkg app-emulation/qemu

注册 binfmt:

[ -d /proc/sys/fs/binfmt_misc ] || modprobe binfmt_misc
[ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
echo ':riscv64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-riscv64:' > /proc/sys/fs/binfmt_misc/register

OpenRC 下启动并设为开机自启:

rc-service qemu-binfmt start
rc-update add qemu-binfmt default

systemd 的话,把上面的注册行写进 /etc/binfmt.d/qemu-riscv64.conf,然后:

systemctl enable --now systemd-binfmt

拉 riscv-chroot-env,生成 rootfs 并进去:

git clone https://gitlab.com/cwittlut/riscv-chroot-env
cd riscv-chroot-env
./getLatest.sh
sudo ./createRootFS.sh
sudo ./chroot.sh

进来之后长这样:

进入 QEMU user chroot

先 fork gentoo/gentoo,再克隆自己的仓库:

git clone https://github.com/<your-user>/gentoo
cd gentoo
git config --local user.name "Your Name"
git config --local user.email "[email protected]"
git config --local pull.rebase true
git config --local --unset pull.ff
git config --local push.default simple
git config --local format.signoff yes
git config --local user.signingkey <your-key-id>
git config --local commit.gpgsign 1
git config --local push.gpgsign 0

push.gpgsign 0 是因为 GitHub 当时不支持推送签名。

~/.bugzrc:

[Gentoo]
base = https://bugs.gentoo.org/xmlrpc.cgi
search_statuses = CONFIRMED, IN_PROGRESS, UNCONFIRMED
user = [email protected]
password = your-password

这里存的是明文密码,把 ~/.bugzrc 权限设成 600,别提交到仓库。

bugz post --version unspecified --component "Keywording" \
  --product "Gentoo Linux" \
  --op-sys Linux \
  --platform All \
  --priority Normal \
  --severity normal \
  -t "app-metrics/prometheus: ~riscv keyword request" \
  -d "add ~riscv keyword"

同步 master,拉最新代码,切分支:

git pull
git checkout -b prometheus-riscv

给 ebuild 加关键字:

ekeyword ~riscv app-metrics/prometheus/prometheus-2.36.2.ebuild

也可以让 nattka 按 Bug 号处理:

nattka apply -a riscv --keywordreq 865633

tatt 配置:

arch=riscv
unmaskdir="/etc/portage/package.accept_keywords"
repodir="/var/db/repos/gentoo"
emergeopts="--autounmask-keep-keywords=y --autounmask-use=y --autounmask-continue --autounmask-write"
buildlogdir="./tatt/logs"
usecombis=1
rdeps=0

zbt 在 Leo3418 的 ebuild overlay 里。

生成依赖:

zbt -r gentoo/ ls --tatt app-metrics/prometheus

也可以在 git 仓库里用 nattka:

nattka make-package-list -a riscv app-metrics/prometheus

生成测试脚本并执行:

tatt -f zbt--app-metrics--prometheus
./zbt--app-metrics--prometheus-useflags.sh

另一个例子:

nattka --repo gentoo/ make-package-list -a riscv www-apps/rt

测试结果贴到 Bugzilla:

tatt 测试报告

生成 commit:

nattka commit -a riscv 865633

检查 commit:

pkgcheck scan --commits

推送到 GitHub:

git push

在 GitHub 上开 PR,把链接贴回 Bugzilla。长时间没人处理,可以去 IRC 的 #gentoo-dev 找 maintainer。