RaspberryPiWithQt6WebEngine: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
m (add setup draft)
(add sysroot draft)
Line 20: Line 20:
In this guide we are going to cross compile Qt 6.5 with WebEngine coming from Qt 6.7
In this guide we are going to cross compile Qt 6.5 with WebEngine coming from Qt 6.7


* Let's create our workspace:
* Let's create our workspace:<syntaxhighlight>
<syntaxhighlight>
mkdir -p ~/workspaces/rpi/host
mkdir -p ~/workspaces/raspberrypi/host
mkdir -p ~/workspaces/rpi/target
mkdir -p ~/workspaces/raspberrypi/target
mkdir -p ~/workspaces/rpi/image
</syntaxhighlight>
</syntaxhighlight>
==Sysroot==
To be able to cross-compile, we need a part of arm64 target sysroot to be present on our build machine. As shown
[[Cross-Compile_Qt_6_for_Raspberry_Pi#Building_Sysroot_from_Device|here]], you could simply start your Rasberry Pi OS on the board and then rsync the required libs and includes to the host machine with SSH connection. However, in this guide we will mount the Raspberry Pi OS image via a loop device, use qemu to install build dependencies and than make a local copy.
{{note|We need actually a local copy of 'libs' and 'headers' from the image, as we want to adjust the symlinks.}}
* Let's now download Raspberry Pi OS:<syntaxhighlight>
cd ~/workspaces/rpi/image
wget https://downloads.raspberrypi.com/raspios_arm64/images/raspios_arm64-2023-12-06/2023-12-05-raspios-bookworm-arm64.img.xz
</syntaxhighlight>
* Let's extract the image:<syntaxhighlight>
unxz --keep 2023-12-05-raspios-bookworm-arm64.img.xz
</syntaxhighlight>
* We need add at least 2G space to the image to be able to fit qt build with debug info [[ResizeRaspberryPiImage| (see here instructions) ]]
* Make loop devices for the image:<syntaxhighlight>
losetup -fP 2023-12-05-raspios-bookworm-arm64.img
losetup -a
/dev/loop0: [66306]:2363198 (~/workspaces/rpi/image/2023-12-05-raspios-bookworm-arm64.img)
</syntaxhighlight>
* Mount the root partition:<syntaxhighlight>
mount /dev/loop0p2 -t ext4 ~/workspaces/rpi/target
mount -t proc /proc ~/workspaces/rpi/target/proc
mount -t sysfs /sys ~/workspaces/rpi/target/sys
mount --bind /dev ~/workspaces/rpi/target/dev
mount --bind /dev/pts ~/workspaces/rpi/target/pts
</syntaxhighlight>
* We need qemu on the image to able to execute command, therefore copy static qemu binary to image.<syntaxhighlight>
cp /usr/bin/qemu-arch64-static /workspace/rpi/target/usr/bin/
</syntaxhighlight>
{{note| Setup of qemu static interpreter is distribution specific. Please refer to your Linux distribution documentation.}}
* Chroot to arm64 target:<syntaxhighlight>
cd ~/workspaces/rpi/target
chroot .
</syntaxhighlight>
* Let's update Qt6 build dependencies:<syntaxhighlight>
vi /etc/apt/sources.list
# uncomment the deb-src line
apt update
apt build-dep qt6-base
exit
</syntaxhighlight>
* rsync the parts that we need:<syntaxhighlight>
cd ~/workspaces/rpi/host
rsync -av ~/workspaces/rpi/target/lib sysroot
rsync -av ~/workspaces/rpi/target/usr/include sysroot/usr
rsync -av ~/workspaces/rpi/target/usr/lib sysroot/usr
</syntaxhighlight>
* Adjust symlinks to be relative:<syntaxhighlight>
wget https://raw.githubusercontent.com/Kukkimonsuta/rpi-buildqt/master/scripts/utils/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot
</syntaxhighlight>
{{note| Command-line tool called [https://linux.die.net/man/8/symlinks symlinks] should not be used instead as it creates dangling links.}}

Revision as of 13:42, 4 January 2024

Introduction

This page describes how to set up self-compiled Qt6 with WebEngine on Raspberry Pi 4 running Raspberry Pi OS.

To see other guides visit:

Setup

To be able to cross compile Qt6 for Raspberry Pi OS, we need three things:

  • Raspberry Pi OS sysroot for arm64 target
  • Cross-Compile toolchain
  • Qt6 host build

Qt6 uses cmake therefore to cross-compile we need to have actually two builds of Qt. One Qt6 host build, which is later used to cross-compile the arm64 Qt build.

In this guide we are going to cross compile Qt 6.5 with WebEngine coming from Qt 6.7

  • Let's create our workspace:
    mkdir -p ~/workspaces/rpi/host
    mkdir -p ~/workspaces/rpi/target
    mkdir -p ~/workspaces/rpi/image
    

Sysroot

To be able to cross-compile, we need a part of arm64 target sysroot to be present on our build machine. As shown here, you could simply start your Rasberry Pi OS on the board and then rsync the required libs and includes to the host machine with SSH connection. However, in this guide we will mount the Raspberry Pi OS image via a loop device, use qemu to install build dependencies and than make a local copy.

  Note: We need actually a local copy of 'libs' and 'headers' from the image, as we want to adjust the symlinks.

  • Let's now download Raspberry Pi OS:
    cd ~/workspaces/rpi/image
    wget https://downloads.raspberrypi.com/raspios_arm64/images/raspios_arm64-2023-12-06/2023-12-05-raspios-bookworm-arm64.img.xz
    
  • Let's extract the image:
    unxz --keep 2023-12-05-raspios-bookworm-arm64.img.xz
    
  • We need add at least 2G space to the image to be able to fit qt build with debug info (see here instructions)
  • Make loop devices for the image:
    losetup -fP 2023-12-05-raspios-bookworm-arm64.img
    losetup -a
    /dev/loop0: [66306]:2363198 (~/workspaces/rpi/image/2023-12-05-raspios-bookworm-arm64.img)
    
  • Mount the root partition:
    mount /dev/loop0p2 -t ext4 ~/workspaces/rpi/target
    mount -t proc /proc ~/workspaces/rpi/target/proc
    mount -t sysfs /sys ~/workspaces/rpi/target/sys
    mount --bind /dev ~/workspaces/rpi/target/dev
    mount --bind /dev/pts ~/workspaces/rpi/target/pts
    
  • We need qemu on the image to able to execute command, therefore copy static qemu binary to image.
    cp /usr/bin/qemu-arch64-static /workspace/rpi/target/usr/bin/
    

  Note: Setup of qemu static interpreter is distribution specific. Please refer to your Linux distribution documentation.

  • Chroot to arm64 target:
    cd ~/workspaces/rpi/target
    chroot .
    
  • Let's update Qt6 build dependencies:
    vi /etc/apt/sources.list
    # uncomment the deb-src line
    apt update
    apt build-dep qt6-base
    exit
    
  • rsync the parts that we need:
    cd ~/workspaces/rpi/host
    rsync -av ~/workspaces/rpi/target/lib sysroot
    rsync -av ~/workspaces/rpi/target/usr/include sysroot/usr
    rsync -av ~/workspaces/rpi/target/usr/lib sysroot/usr
    
  • Adjust symlinks to be relative:
    wget https://raw.githubusercontent.com/Kukkimonsuta/rpi-buildqt/master/scripts/utils/sysroot-relativelinks.py
    chmod +x sysroot-relativelinks.py
    ./sysroot-relativelinks.py sysroot
    

  Note: Command-line tool called symlinks should not be used instead as it creates dangling links.