Search code examples
dockerembedded-linuxqemupypibuildroot

how to compile and build a python package for aarch64 using qemu?


I am trying to build python wheels for a package (lap) for the aarch64 architecture. My host environment is WSL2 with Ubuntu 20.04 and docker. Target is Buildroot GNU/Linux. So no compiler is available on the target. My goal is to setup a cross-build environment for aarch64 using qemu. As described in Run a AArch64 native container on x86 with emulation we can use a containerized environment available to run on AArch64 to build wheels to the current specification with QEMU emulator. Steps I am doing:

  1. installing qemu packages in WSL2 sudo apt-get install qemu binfmt-support qemu-user-static
  2. registering scripts: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  3. Testing the emulation environment docker run --rm -t arm64v8/ubuntu uname -m and it returns aarch64 so, I believe the installation was successful, the emulation is working. Also, qemu-aarch64-static is available in /usr/bin/
  4. Now I clone the project lap (in WSL2) and cd lap/ and it contains setup.py but when I execute below command to build the wheels
    docker run --rm -v `pwd`:/io quay.io/pypa/manylinux2014_aarch64 bash -c '/opt/python/cp38-cp38/bin/python ./setup.py bdist_wheel'
    

I get below error

```
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
```

Now I am not sure how to pass qemu-aarch64-static to above docker command?

Can any one please let me know how to resolve this and build python wheels using QEMU?

Thanks in advance.

P.S: Please let me know if any info is missing.


Solution

  • All seem to be working fine, but the last step you're not accessing the actual file.

    Since I don't know docker so well. First I start a aarch64 shell.

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

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

    Then from inside of the container, I just build the program like I would normally.

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

    Then install some dependencies.

    python3.8 -m pip install numpy cython
    

    Then I can build the wheel.

    python3.8 setup.py bdist_wheel
    

    Then I have a "dist" folder with.

    -rw-r--r--. 1 root root 1.7M Aug 22 11:59 lap-0.5.dev0-cp38-cp38-linux_aarch64.whl