Skip to content

Commit c55046f

Browse files
add qt5 package (#55)
Qt 5.15.18-lts-lgpl (QtBase + QtCharts) built from source as shared libraries. Provides headers, shared libs, and tools (moc, rcc, uic) for building cabana in openpilot without system Qt5 packages. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a78417e commit c55046f

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"libyuv",
1414
"nanosvg",
1515
"ncurses",
16+
"qt5",
1617
"raylib",
1718
"zeromq",
1819
"zstd",

qt5/build.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
QT_VERSION="5.15.18"
8+
QT_TAG="v${QT_VERSION}-lts-lgpl"
9+
INSTALL_DIR="$DIR/qt5/install"
10+
NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)"
11+
12+
# Install build dependencies
13+
if [[ "$(uname)" == "Linux" ]]; then
14+
if command -v dnf &>/dev/null; then
15+
dnf install -y \
16+
mesa-libGL-devel \
17+
fontconfig-devel \
18+
freetype-devel \
19+
libxcb-devel \
20+
xcb-util-devel \
21+
xcb-util-image-devel \
22+
xcb-util-keysyms-devel \
23+
xcb-util-renderutil-devel \
24+
xcb-util-wm-devel \
25+
libxkbcommon-devel \
26+
libxkbcommon-x11-devel \
27+
libX11-devel \
28+
perl-IPC-Cmd
29+
elif command -v apt-get &>/dev/null; then
30+
if [ "$(id -u)" -eq 0 ]; then
31+
apt-get update && apt-get install -y \
32+
libgl-dev \
33+
libfontconfig1-dev libfreetype-dev \
34+
libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev \
35+
libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev \
36+
libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev \
37+
libxcb-randr0-dev libxcb-render-util0-dev \
38+
libxcb-xinerama0-dev libxcb-xkb-dev \
39+
libxkbcommon-dev libxkbcommon-x11-dev \
40+
libx11-xcb-dev
41+
else
42+
sudo apt-get update && sudo apt-get install -y \
43+
libgl-dev \
44+
libfontconfig1-dev libfreetype-dev \
45+
libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev \
46+
libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev \
47+
libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev \
48+
libxcb-randr0-dev libxcb-render-util0-dev \
49+
libxcb-xinerama0-dev libxcb-xkb-dev \
50+
libxkbcommon-dev libxkbcommon-x11-dev \
51+
libx11-xcb-dev
52+
fi
53+
fi
54+
fi
55+
56+
# Clone/update qtbase
57+
if [ ! -d "qtbase-src/.git" ]; then
58+
rm -rf qtbase-src
59+
git clone --depth 1 https://code.qt.io/qt/qtbase.git qtbase-src
60+
fi
61+
git -C qtbase-src fetch --depth 1 origin "$QT_TAG"
62+
git -C qtbase-src checkout --force FETCH_HEAD
63+
64+
# Build qtbase
65+
cd qtbase-src
66+
./configure \
67+
-release \
68+
-prefix "$INSTALL_DIR" \
69+
-opensource -confirm-license \
70+
-nomake examples \
71+
-nomake tests \
72+
-no-dbus \
73+
-no-icu \
74+
-opengl desktop
75+
make -j"$NJOBS"
76+
make install
77+
cd "$DIR"
78+
79+
# Clone/update qtcharts
80+
if [ ! -d "qtcharts-src/.git" ]; then
81+
rm -rf qtcharts-src
82+
git clone --depth 1 https://code.qt.io/qt/qtcharts.git qtcharts-src
83+
fi
84+
git -C qtcharts-src fetch --depth 1 origin "$QT_TAG"
85+
git -C qtcharts-src checkout --force FETCH_HEAD
86+
87+
# Build qtcharts
88+
cd qtcharts-src
89+
"$INSTALL_DIR/bin/qmake"
90+
make -j"$NJOBS"
91+
make install
92+
cd "$DIR"
93+
94+
# Replace symlinks with copies for wheel compatibility
95+
find "$INSTALL_DIR" -type l | while read -r link; do
96+
target="$(readlink -f "$link")"
97+
if [ -f "$target" ]; then
98+
rm "$link"
99+
cp "$target" "$link"
100+
elif [ -d "$target" ]; then
101+
rm "$link"
102+
cp -r "$target" "$link"
103+
fi
104+
done
105+
106+
# Strip binaries and libraries
107+
find "$INSTALL_DIR" -type f -name '*.so*' -exec strip --strip-unneeded {} + 2>/dev/null || true
108+
find "$INSTALL_DIR" -type f -name '*.dylib' -exec strip -x {} + 2>/dev/null || true
109+
strip "$INSTALL_DIR/bin/moc" "$INSTALL_DIR/bin/rcc" "$INSTALL_DIR/bin/uic" 2>/dev/null || true
110+
111+
# Remove unnecessary files to reduce wheel size
112+
rm -rf "$INSTALL_DIR/doc" "$INSTALL_DIR/mkspecs" "$INSTALL_DIR/lib/cmake" "$INSTALL_DIR/lib/pkgconfig"
113+
find "$INSTALL_DIR/lib" -name '*.prl' -delete 2>/dev/null || true
114+
find "$INSTALL_DIR/lib" -name '*.la' -delete 2>/dev/null || true
115+
116+
echo "Installed Qt5 to $INSTALL_DIR"
117+
du -sh "$INSTALL_DIR"

qt5/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "qt5"
7+
version = "5.15.18"
8+
description = "Qt 5.15 (QtBase + QtCharts)"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["qt5*"]
13+
14+
[tool.setuptools.package-data]
15+
qt5 = ["install/**/*"]

qt5/qt5/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
DIR = os.path.join(os.path.dirname(__file__), "install")
4+
BIN_DIR = os.path.join(DIR, "bin")
5+
LIB_DIR = os.path.join(DIR, "lib")
6+
INCLUDE_DIR = os.path.join(DIR, "include")
7+
8+
9+
def smoketest():
10+
assert os.path.isfile(os.path.join(BIN_DIR, "moc")), "moc not found"
11+
assert os.path.isfile(os.path.join(BIN_DIR, "rcc")), "rcc not found"
12+
import glob
13+
import platform
14+
if platform.system() == "Darwin":
15+
assert os.path.isdir(os.path.join(LIB_DIR, "QtCore.framework")), "QtCore.framework not found"
16+
assert os.path.isdir(os.path.join(LIB_DIR, "QtCharts.framework")), "QtCharts.framework not found"
17+
else:
18+
assert glob.glob(os.path.join(LIB_DIR, "libQt5Core.so*")), "libQt5Core.so not found"
19+
assert glob.glob(os.path.join(LIB_DIR, "libQt5Charts.so*")), "libQt5Charts.so not found"

qt5/setup.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from setuptools.command.build_py import build_py
6+
7+
try:
8+
from wheel.bdist_wheel import bdist_wheel
9+
except ImportError:
10+
bdist_wheel = None
11+
12+
13+
class BuildQt5(build_py):
14+
"""Run build.sh to compile Qt5 before collecting package data."""
15+
16+
def run(self):
17+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
18+
build_script = os.path.join(pkg_dir, "build.sh")
19+
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
20+
21+
super().run()
22+
23+
24+
cmdclass = {"build_py": BuildQt5}
25+
26+
if bdist_wheel is not None:
27+
28+
class PlatformWheel(bdist_wheel):
29+
"""Produce a platform-specific, Python-version-agnostic wheel."""
30+
31+
def finalize_options(self):
32+
super().finalize_options()
33+
self.root_is_pure = False
34+
35+
def get_tag(self):
36+
system = platform.system()
37+
machine = platform.machine()
38+
39+
if system == "Linux":
40+
plat = f"linux_{machine}"
41+
elif system == "Darwin":
42+
plat = "macosx_11_0_arm64"
43+
else:
44+
plat = f"{system.lower()}_{machine}"
45+
46+
return "py3", "none", plat
47+
48+
cmdclass["bdist_wheel"] = PlatformWheel
49+
50+
51+
def setup():
52+
from setuptools import setup as _setup
53+
54+
_setup(cmdclass=cmdclass)
55+
56+
57+
if __name__ == "__main__":
58+
setup()

0 commit comments

Comments
 (0)