Olympe 7.7.5 source release fails to build on AArch64 [SOLVED]

Hi,

I open this issue, which reports the same problem as Issues building Olympe 7.5.0 for aarch64 on ubuntu:20.04 and Parrot Olympe SDK on Ubuntu 18.04 aarch64.

I too failed to build Olympe on a raspberry Pi 5 running Debian Bookworm 64bits (hence architecture AArch64). I managed to trace back the origin of the problem and leave the solution here (see bottom of the post for the solution).

Description of the problem

Olympe source releases are delivered with prebuilt dependencies in the folder packages for the supported architectures (aarch64, armv7a and x86_64). When building on a x86_64 computer, no problem occur, but on any aarch64 the build process fails when checking the clang package version, as described in linked issues.

Analysis

The version that aarch64 clang library gives corresponds to a Git commit long hash, whereas pip packaging module expects a semantic version (MAJOR.Minor.patch).
On x86_64, the clang library correctly returns a semantic version.
I assumed the aarch64 clang library packaged with olympe source release was built with wrong options.

Solution

I successfully tested two solutions:

hacky solution to unblock the build easily and quickly.

Try building Olympe a first time, just to generate the out folder.
The hack is then to bypass clang version check by editing the file out/olympe-linux/staging-host/usr/lib/python/site-packages/ctypeslib/codegen/cindex.py:
sed -i '285i\ return packaging.version.parse("11.0.1") out/olympe-linux/staging-host/usr/lib/python/site-packages/ctypeslib/codegen/cindex.py

proper solution

This solution needs more time or an update of the release archive provided on github. I can provide the already built archive.
The goal is to build clang from source on aarch64 with proper options to generate a new aarch64 clang library for Olympe.
First, on any computer, clone the LLVM Project. The clone takes time, but the shallow clone cannot be used in our case since the shallow clone only permits to build the latest version, whereas we need version 11.0.1 (at least for Olympe 7.7.5).

git clone https://github.com/llvm/llvm-project.git
git checkout llvmorg-11.0.1

And build the clang library for aarch64:

cd llvm-project
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS=clang    \
      -DCMAKE_BUILD_TYPE=Release      \
      -DLLVM_TARGETS_TO_BUILD=AArch64 \
      -DLLVM_APPEND_VC_REV=OFF        \
      -G "Unix Makefiles" ../llvm
make -j4

Note the option LLVM_APPEND_VC_REV. This option, when enabled, tells LLVM to use VCS Revision as version (eg the git commit hash).
The build on a raspberry pi5 took approximately 4 hours, but it can be built on a x86_64 PC.
Finally, package the generated clang library and replace the one from Olympe:

mkdir -p aarch64-linux-gnu
cp -P lib/libclang.so* aarch64-linux-gnu/
tar -caf aarch64-linux-gnu.tar.gz aarch64-linux-gnu
mv /root/llvm-project/build/aarch64-linux-gnu.tar.gz /root/olympe/packages/clang/libclang/

Building Olympe will now succeed on aarch64.

I hope this will help.