Skip to content

Commit 38e90bc

Browse files
build(linux): generate glad sources at compile time
1 parent fc001cd commit 38e90bc

25 files changed

Lines changed: 251 additions & 7267 deletions

File tree

.github/workflows/ci-flatpak.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: Setup Dependencies Linux Flatpak
6666
run: |
67-
python -m pip install ./packaging/linux/flatpak/deps/flatpak-builder-tools/node
67+
python -m pip install ".[flatpak]"
6868
6969
sudo apt-get update -y
7070
sudo apt-get install -y \
@@ -91,6 +91,19 @@ jobs:
9191
- name: Debug generated-sources.json
9292
run: cat generated-sources.json
9393

94+
- name: flatpak pip generator
95+
# generates glad-dependencies.json for PyPI build-time dependencies (e.g. jinja2 for glad)
96+
run: |
97+
python \
98+
./packaging/linux/flatpak/deps/flatpak-builder-tools/pip/flatpak-pip-generator.py \
99+
--runtime="org.freedesktop.Sdk//${PLATFORM_VERSION}" \
100+
--output glad-dependencies \
101+
--build-only \
102+
--requirements-file=./third-party/glad/requirements.txt
103+
104+
# Copy generated pip sources into build dir alongside the manifest
105+
cp glad-dependencies.json build/
106+
94107
- name: Cache Flatpak build
95108
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
96109
with:
@@ -195,6 +208,7 @@ jobs:
195208
run: |
196209
mkdir -p flathub/modules
197210
cp "./build/generated-sources.json" "./flathub/"
211+
cp "./build/glad-dependencies.json" "./flathub/"
198212
cp "./build/package-lock.json" "./flathub/"
199213
cp "./build/${APP_ID}.yml" "./flathub/"
200214
cp "./build/${APP_ID}.metainfo.xml" "./flathub/"

.github/workflows/ci-freebsd.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ jobs:
111111
devel/llvm${{ env.FREEBSD_CLANG_VERSION }} \
112112
devel/ninja \
113113
devel/pkgconf \
114+
devel/py-Jinja2 \
114115
ftp/curl \
115116
graphics/libdrm \
116117
graphics/wayland \
@@ -139,7 +140,7 @@ jobs:
139140
run: |
140141
set -e
141142
# install gcvor
142-
python -m pip install "./scripts[test]"
143+
python -m pip install ".[test]"
143144
144145
# fix git safe.directory issues
145146
git config --global --add safe.directory "*"

.github/workflows/ci-linux.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ jobs:
5858
libxcb-dri3-dev \
5959
libxfixes-dev
6060
61-
- name: Setup python
62-
id: python
63-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
64-
with:
65-
python-version: '3.14'
66-
6761
- name: Build latest libva
6862
env:
6963
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -163,6 +157,34 @@ jobs:
163157
sudo apt-get clean
164158
sudo rm -rf /var/lib/apt/lists/*
165159
160+
- name: Setup python
161+
id: python
162+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
163+
with:
164+
python-version: '3.14'
165+
166+
- name: Print generated glad sources
167+
# Temporary step: format and display the generated glad files so they can be
168+
# compared with the previously committed sources. Remove once verified.
169+
run: |
170+
${{ steps.python.outputs.python-path }} -m pip install ".[lint]"
171+
172+
glad_files=(
173+
"build/gladsources/glad/include/EGL/eglplatform.h"
174+
"build/gladsources/glad/include/KHR/khrplatform.h"
175+
"build/gladsources/glad/include/glad/egl.h"
176+
"build/gladsources/glad/include/glad/gl.h"
177+
"build/gladsources/glad/src/egl.c"
178+
"build/gladsources/glad/src/gl.c"
179+
)
180+
181+
for f in "${glad_files[@]}"; do
182+
echo "::group::${f}"
183+
clang-format --style=file:.clang-format -i "${f}"
184+
cat "${f}"
185+
echo "::endgroup::"
186+
done
187+
166188
- name: Run tests
167189
id: test
168190
working-directory: build/tests
@@ -181,7 +203,7 @@ jobs:
181203
(steps.test.outcome == 'success' || steps.test.outcome == 'failure')
182204
working-directory: build
183205
run: |
184-
${{ steps.python.outputs.python-path }} -m pip install "../scripts[test]"
206+
${{ steps.python.outputs.python-path }} -m pip install "..[test]"
185207
${{ steps.python.outputs.python-path }} -m gcovr --gcov-executable "gcov-${GCC_VERSION}" . -r ../src \
186208
--exclude-noncode-lines \
187209
--exclude-throw-branches \

.github/workflows/ci-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ jobs:
258258
shell: msys2 {0}
259259
working-directory: build
260260
run: |
261-
${{ steps.python-path.outputs.python-path }} -m pip install "../scripts[test]"
261+
${{ steps.python-path.outputs.python-path }} -m pip install "..[test]"
262262
${{ steps.python-path.outputs.python-path }} -m gcovr . -r ../src \
263263
--exclude-noncode-lines \
264264
--exclude-throw-branches \

.github/workflows/localize.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
python-version: '3.14'
3232

3333
- name: Set up Python Dependencies
34-
working-directory: scripts
3534
run: |
3635
python -m pip install --upgrade pip setuptools
3736
python -m pip install ".[locale]"

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
path = third-party/doxyconfig
1515
url = https://github.com/LizardByte/doxyconfig.git
1616
branch = master
17+
[submodule "third-party/glad"]
18+
path = third-party/glad
19+
url = https://github.com/Dav1dde/glad.git
1720
[submodule "third-party/googletest"]
1821
path = third-party/googletest
1922
url = https://github.com/google/googletest.git

cmake/compile_definitions/linux.cmake

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,11 @@ list(APPEND PLATFORM_TARGET_FILES
262262
"${CMAKE_SOURCE_DIR}/src/platform/linux/graphics.cpp"
263263
"${CMAKE_SOURCE_DIR}/src/platform/linux/misc.h"
264264
"${CMAKE_SOURCE_DIR}/src/platform/linux/misc.cpp"
265-
"${CMAKE_SOURCE_DIR}/src/platform/linux/audio.cpp"
266-
"${CMAKE_SOURCE_DIR}/third-party/glad/src/egl.c"
267-
"${CMAKE_SOURCE_DIR}/third-party/glad/src/gl.c"
268-
"${CMAKE_SOURCE_DIR}/third-party/glad/include/EGL/eglplatform.h"
269-
"${CMAKE_SOURCE_DIR}/third-party/glad/include/KHR/khrplatform.h"
270-
"${CMAKE_SOURCE_DIR}/third-party/glad/include/glad/gl.h"
271-
"${CMAKE_SOURCE_DIR}/third-party/glad/include/glad/egl.h")
265+
"${CMAKE_SOURCE_DIR}/src/platform/linux/audio.cpp")
272266

273267
list(APPEND PLATFORM_LIBRARIES
274268
dl
275269
pulse
276270
pulse-simple)
277271

278-
include_directories(
279-
SYSTEM
280-
"${CMAKE_SOURCE_DIR}/third-party/glad/include")
272+
list(APPEND SUNSHINE_EXTERNAL_LIBRARIES glad)

cmake/dependencies/glad.cmake

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#
2+
# Generates the glad OpenGL/EGL loader library using the glad2 generator.
3+
# Sources are generated at build time via the glad submodule's CMake integration.
4+
#
5+
include_guard(GLOBAL)
6+
7+
# The glad2 repo does not have a root-level CMakeLists.txt; its CMake integration
8+
# lives in cmake/CMakeLists.txt which provides the glad_add_library() function.
9+
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/glad/cmake" glad2-cmake)
10+
11+
# glad's generator requires jinja2. Find Python first (same interpreter that glad_add_library()
12+
# will bake into the ninja build command), then check if jinja2 is already importable.
13+
# Only pip-install if it isn't — this transparently handles system packages (python3-jinja2 on
14+
# Debian/Ubuntu/Arch/COPR) as well as bare Python environments.
15+
#
16+
# GLAD_SKIP_PIP_INSTALL is a hard override for sandboxed environments where pip cannot run at
17+
# all (e.g. Flatpak). In all normal cases leave it OFF and let the check below decide.
18+
option(GLAD_SKIP_PIP_INSTALL
19+
"Hard-skip pip install of jinja2 even if it is not importable. \
20+
Only needed in sandboxed build environments (e.g. Flatpak) where pip cannot run." OFF)
21+
22+
if(NOT GLAD_SKIP_PIP_INSTALL)
23+
# glad's generator requires Python >= 3.8 (importlib.metadata) and jinja2.
24+
# Prefer the real system Python over any venv/toolchain Python injected into PATH
25+
# (e.g. GitHub Actions setup-python). STANDARD means FindPython does not give
26+
# special priority to virtual environments.
27+
set(Python_FIND_VIRTUALENV STANDARD) # cmake-lint: disable=C0103
28+
29+
# On Linux, search for a sufficiently new system Python (>= 3.8) explicitly.
30+
# This is important on distros like OpenSUSE Leap where /usr/bin/python3 is 3.6,
31+
# but python3.11 or python3.8 may also be installed. Search newest-first so that
32+
# the best available interpreter is used. The NO_DEFAULT_PATH on the first pass
33+
# restricts the search to /usr/bin to prefer distro packages over venv/toolchain
34+
# Pythons (e.g. GitHub Actions setup-python injects its own python3 first on PATH).
35+
if(UNIX AND NOT APPLE)
36+
foreach(py_candidate python3.13 python3.12 python3.11 python3.10 python3.9 python3.8 python3)
37+
find_program(_system_python3 "${py_candidate}" PATHS /usr/bin /usr/local/bin NO_DEFAULT_PATH)
38+
if(_system_python3)
39+
# Verify this interpreter is >= 3.8
40+
execute_process(
41+
COMMAND "${_system_python3}" -c
42+
"import sys; sys.exit(0 if sys.version_info >= (3,8) else 1)"
43+
RESULT_VARIABLE _py_version_ok
44+
OUTPUT_QUIET ERROR_QUIET
45+
)
46+
if(_py_version_ok EQUAL 0)
47+
message(STATUS "glad: using Python interpreter: ${_system_python3}")
48+
set(Python_EXECUTABLE "${_system_python3}" # cmake-lint: disable=C0103
49+
CACHE FILEPATH "Python interpreter" FORCE)
50+
break()
51+
else()
52+
message(STATUS "glad: skipping ${_system_python3} (< 3.8)")
53+
unset(_system_python3 CACHE)
54+
endif()
55+
endif()
56+
unset(_system_python3 CACHE)
57+
endforeach()
58+
endif()
59+
60+
find_package(Python COMPONENTS Interpreter REQUIRED)
61+
62+
# Check whether jinja2 is already importable by the found interpreter.
63+
execute_process(
64+
COMMAND "${Python_EXECUTABLE}" -c "import jinja2"
65+
RESULT_VARIABLE _jinja2_import_result
66+
OUTPUT_QUIET
67+
ERROR_QUIET
68+
)
69+
70+
if(NOT _jinja2_import_result EQUAL 0)
71+
message(STATUS "glad: jinja2 not found in ${Python_EXECUTABLE}, installing via pip...")
72+
execute_process(
73+
COMMAND "${Python_EXECUTABLE}" -m pip install
74+
--requirement "${CMAKE_SOURCE_DIR}/third-party/glad/requirements.txt"
75+
--quiet
76+
COMMAND_ERROR_IS_FATAL ANY
77+
)
78+
else()
79+
message(STATUS "glad: jinja2 already available in ${Python_EXECUTABLE}, skipping pip install")
80+
endif()
81+
endif()
82+
83+
# Generate the glad library.
84+
# EGL 1.5 --loader --mx
85+
# GL compatibility=4.6 --loader --mx
86+
# EGL_EXT_image_dma_buf_import_modifiers is included to expose eglQueryDmaBufFormatsEXT and
87+
# eglQueryDmaBufModifiersEXT
88+
# REPRODUCIBLE avoids fetching the latest spec XML from Khronos at generation time.
89+
glad_add_library(glad
90+
STATIC
91+
REPRODUCIBLE
92+
LOCATION "${CMAKE_BINARY_DIR}/gladsources/glad"
93+
LOADER
94+
MX
95+
API
96+
"egl=1.5"
97+
"gl:compatibility=4.6"
98+
EXTENSIONS
99+
EGL_EXT_image_dma_buf_import
100+
EGL_EXT_image_dma_buf_import_modifiers
101+
)

cmake/dependencies/linux.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# linux specific dependencies
2+
3+
include("${CMAKE_MODULE_PATH}/dependencies/glad.cmake")

docs/contributing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ any of the following paths are modified.
128128
```
129129
130130
When testing locally, it may be desirable to manually extract, initialize, update, and compile strings. Python is
131-
required for this, along with the python dependencies in the `./scripts/pyproject.toml` file. You can install this with
131+
required for this, along with the python dependencies in the `./pyproject.toml` file. You can install this with
132132
the following command.
133133

134134
```bash
135-
python -m pip install "./scripts[locale]"
135+
python -m pip install ".[locale]"
136136
```
137137

138138
Additionally, [xgettext](https://www.gnu.org/software/gettext) must be installed.

0 commit comments

Comments
 (0)