Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: write scripts for building a Pi 4 (64-bit) WebView #2216

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions webview/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ target_wrapper.*

# QtCreator CMake
CMakeLists.txt.user*
!docker-compose.yml
4 changes: 2 additions & 2 deletions webview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ When you're done, you can stop and remove the container with the following comma
docker compose -f docker-compose.x86.yml down
```

### Building for Raspberry Pi 5
### Building for Raspberry Pi 4 and Raspberry Pi 5 Devices Running 64-Bit OS

See this [documentation](/webview/docs/build_webview_for_pi5.md) for details
See this [documentation](/webview/docs/build_webview_using_prebuilt_qt.md) for details

## Usage

Expand Down
14 changes: 0 additions & 14 deletions webview/docker-compose.pi5.yml

This file was deleted.

31 changes: 31 additions & 0 deletions webview/docker-compose.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor common attributes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
builder-pi5:
build:
context: .
dockerfile: docker/Dockerfile.pi5
environment:
- GIT_HASH=${GIT_HASH}
- PLATFORM=pi5
tty: true
stdin_open: true
volumes:
- "~/tmp/pi5/build:/build:Z"
- "./examples:/src/examples"
- "./:/webview:ro"
- "./scripts/build_webview.sh:/scripts/build_webview.sh"
profiles: [pi5]
builder-pi4-64:
build:
context: .
dockerfile: docker/Dockerfile.pi4-64
environment:
- GIT_HASH=${GIT_HASH}
- PLATFORM=pi4-64
tty: true
stdin_open: true
volumes:
- "~/tmp/pi4-64/build:/build:Z"
- "./examples:/src/examples"
- "./:/webview:ro"
- "./scripts/build_webview.sh:/scripts/build_webview.sh"
profiles: [pi4-64]
18 changes: 18 additions & 0 deletions webview/docker/Dockerfile.pi4-64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maybe create a script that generates custom Dockerfiles based on the given platform (e.g., pi1, pi2, pi3, pi4, pi4-64, pi5, etc.).

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vim:ft=dockerfile

FROM balenalib/raspberrypi4-64-debian:bookworm

ENV DEBIAN_FRONTEND=noninteractive

# Build dependencies for the Qt 6 app
RUN apt-get -y update && apt-get install -y \
build-essential \
cmake \
qt6-base-dev \
qt6-webengine-dev

RUN mkdir -p /scripts /src

WORKDIR /build

CMD ["bash"]
51 changes: 0 additions & 51 deletions webview/docs/build_webview_for_pi5.md

This file was deleted.

70 changes: 70 additions & 0 deletions webview/docs/build_webview_using_prebuilt_qt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Building WebView via Prebuilt Qt

## Overview

This method only works on the following devices:

- Raspberry Pi 4 (64-bit)
- Raspberry Pi 5 (64-bit)

## Prerequisites

> [!NOTE]
> Cross-compilation is not yet supported.
> You need to have the following installed and set up on your Raspberry Pi 4 or Raspberry Pi 5 device:
> - Docker (arm64)
> - Code editor of your choice (e.g., Visual Studio Code, Neovim, etc.)

## Building the WebView

Clone the repository:

```bash
$ git clone https://github.com/Screenly/Anthias.git
```

Navigate to the `webview` directory:

```bash
$ cd /path/to/Anthias/webview
```

Initialize environment variables:

```bash
$ export GIT_HASH=$(git rev-parse --short HEAD)

$ export COMPOSE_PROFILES=pi5 # For Raspberry Pi 5
$ export COMPOSE_PROFILES=pi4-64 # For Raspberry Pi 4
```

Start the builder container with the following command:

```bash
$ docker compose up -d --build
```

You should now be able to invoke a run executing either of the following commands:

```bash
$ docker compose exec builder-pi5 /webview/build_webview.sh
# or
$ docker compose exec builder-pi4-64 /webview/build_webview.sh
```

```bash
$ docker compose exec builder-pi5 bash
# or
$ docker compose exec builder-pi4-64 bash

# Once you're in the container, run the following command:
$ /scripts/build_webview.sh
```

The resulting files will be placed in `~/tmp/<platform>/build/release`, where `<platform>` is either `pi5` or `pi4-64`.

When you're done, you can stop and remove the container with the following commands:

```bash
$ docker compose down
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ QT_MINOR='4'
QT_PATCH='2'
QT_VERSION="${QT_MAJOR}.${QT_MINOR}.${QT_PATCH}"
CORE_COUNT="$(expr $(nproc) - 2)"
PLATFORM="${PLATFORM:-pi5}"
SUPPORTED_PLATFORMS=("pi4-64" "pi5")

if [[ ! " ${SUPPORTED_PLATFORMS[@]} " =~ " ${PLATFORM} " ]]; then
echo "Unsupported platform: ${PLATFORM}"
exit 1
fi

function create_webview_archive() {
local ARCHIVE_NAME="webview-${QT_VERSION}-${DEBIAN_VERSION}-pi5-$GIT_HASH.tar.gz"
local ARCHIVE_NAME="webview-${QT_VERSION}-${DEBIAN_VERSION}-${PLATFORM}-$GIT_HASH.tar.gz"
local ARCHIVE_DESTINATION="/build/release/${ARCHIVE_NAME}"

mkdir -p /build/release
Expand Down
6 changes: 6 additions & 0 deletions webview/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
#include "mainwindow.h"
#include "view.h"

#include <QGuiApplication>
#include <QScreen>

MainWindow::MainWindow() : QMainWindow()
{
view = new View(this);
view -> settings() -> setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
view -> settings() -> setAttribute(QWebEngineSettings::ShowScrollBars, false);
setCentralWidget(view);

QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
setGeometry(screenGeometry);
showFullScreen();
Comment on lines +17 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make use of macros, which gets resolved before compilation.

}

void MainWindow::loadPage(const QString &uri)
Expand Down