如何使用 qemu 编译和构建 aarch64 的 python 包?

2024-01-07

我正在尝试为一个包构建 python 轮子(lap https://github.com/gatagat/lap) 为了aarch64建筑学。我的主机环境是 WSL2 和 Ubuntu 20.04docker。目标是BuildrootGNU/Linux。因此目标上没有可用的编译器。我的目标是建立一个交叉构建环境aarch64 using qemu。如中所述通过模拟在 x86 上运行 AArch64 本机容器 https://github.com/ARM-software/developer/blob/master/projects/python-wheels/multi-platform.md#run-a-aarch64-native-container-on-x86-with-emulation我们可以使用容器化环境可在 AArch64 上运行,以构建符合当前规范的轮子 https://quay.io/repository/pypa/manylinux2014_aarch64 with QEMU模拟器 https://github.com/multiarch/qemu-user-static。我正在做的步骤:

  1. 在 WSL2 中安装 qemu 包sudo apt-get install qemu binfmt-support qemu-user-static
  2. 注册脚本:docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  3. 测试仿真环境docker run --rm -t arm64v8/ubuntu uname -m它返回aarch64所以,我相信安装是成功的,模拟正在工作。还,qemu-aarch64-static可用于/usr/bin/
  4. 现在我克隆该项目lap https://github.com/gatagat/lap (in WSL2) and cd lap/它包含setup.py但是当我执行下面的命令来构建轮子时
    docker run --rm -v `pwd`:/io quay.io/pypa/manylinux2014_aarch64 bash -c '/opt/python/cp38-cp38/bin/python ./setup.py bdist_wheel'
    

我收到以下错误

```
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64/v4) and no specific platform was requested
/opt/python/cp38-cp38/bin/python: can't open file './setup.py': [Errno 2] No such file or directory
```

现在我不知道如何通过qemu-aarch64-static到上面docker命令?

谁能告诉我如何解决这个问题并使用 QEMU 构建 python 轮子?

提前致谢。

P.S:如果缺少任何信息,请告诉我。


一切似乎都工作正常,但最后一步您没有访问实际文件。

因为我对docker不太了解。首先,我启动 aarch64 shell。

docker run -it quay.io/pypa/manylinux2014_aarch64 bash

[root@637db2c1af5e /]# uname -m
aarch64

然后从容器内部,我就像平常一样构建程序。

git clone https://github.com/gatagat/lap

然后安装一些依赖项。

python3.8 -m pip install numpy cython

然后我就可以造轮子了。

python3.8 setup.py bdist_wheel

然后我有一个“dist”文件夹。

-rw-r--r--。 1 root root 1.7M 8月22日11:59 lap-0.5.dev0-cp38-cp38-linux_aarch64.whl

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 qemu 编译和构建 aarch64 的 python 包? 的相关文章

随机推荐