Skip to content

build(linux): generate glad sources at compile time#4798

Merged
ReenigneArcher merged 5 commits intomasterfrom
build/linux/generate-glad-sources-at-compile-time
Mar 16, 2026
Merged

build(linux): generate glad sources at compile time#4798
ReenigneArcher merged 5 commits intomasterfrom
build/linux/generate-glad-sources-at-compile-time

Conversation

@ReenigneArcher
Copy link
Member

@ReenigneArcher ReenigneArcher commented Mar 1, 2026

Description

The glad third-party directory was not following good practices, and should be a submodule. For glad this will require an extra generation step in cmake.

Motivation for this is 2 fold.

  1. We should not store external source code in this repo, as it's not a good practice
  2. It was discovered that over 2k sonar issues are coming from glad

TODO:

  • compare generated source files to previous code

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

❌ Patch coverage is 0% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.86%. Comparing base (0bbaa2d) to head (38c33c2).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/graphics.cpp 0.00% 36 Missing and 5 partials ⚠️
src/platform/linux/misc.cpp 0.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4798      +/-   ##
==========================================
- Coverage   17.89%   17.86%   -0.03%     
==========================================
  Files         106      106              
  Lines       21944    21958      +14     
  Branches     9841     9810      -31     
==========================================
- Hits         3926     3923       -3     
- Misses      15734    16128     +394     
+ Partials     2284     1907     -377     
Flag Coverage Δ
Archlinux 12.32% <0.00%> (-0.03%) ⬇️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 14.06% <0.00%> (-0.05%) ⬇️
Homebrew-ubuntu-22.04 14.68% <0.00%> (-0.04%) ⬇️
Linux-AppImage 12.83% <0.00%> (-0.08%) ⬇️
Windows-AMD64 14.98% <ø> (ø)
Windows-ARM64 13.38% <ø> (-0.01%) ⬇️
macOS-arm64 18.60% <ø> (ø)
macOS-x86_64 17.08% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/linux/graphics.h 0.00% <ø> (ø)
src/platform/linux/misc.cpp 15.28% <0.00%> (-0.22%) ⬇️
src/platform/linux/graphics.cpp 2.38% <0.00%> (-0.13%) ⬇️

... and 57 files with indirect coverage changes

@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch 3 times, most recently from 171ecb6 to c6cfc9a Compare March 2, 2026 00:49
@codecov
Copy link

codecov bot commented Mar 2, 2026

Bundle Report

Bundle size has no change ✅

@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch 19 times, most recently from ecdb427 to 3f48d4e Compare March 3, 2026 00:08
@ReenigneArcher
Copy link
Member Author

ReenigneArcher commented Mar 3, 2026

@psyke83, @garnacho, could I request a review from you both?

This PR addresses an issue from #2507 (comment) so would appreciate any feedback. Note: I used AI to help resolve some of the compilation issues that occurred when switching to the generated sources.

I'm pretty confident in the majority of changes in this PR, if I have any doubts they're in the cpp code.

  • src/platform/linux/graphics.cpp
  • src/platform/linux/graphics.h

I'm printing out the generated sources here (https://github.com/LizardByte/Sunshine/actions/runs/22600512276/job/65481219548?pr=4798#step:12:65) as well, for comparison purposes. I did a spot check and things seemed mostly the same, but some differences. Probably due to bumping from glad 2.0.0-beta to glad 2.0.8, as well as any manual edits that were made in the past.

I confirmed some of the changed added in #4417, were generated in the new generated source, but things are slightly different.

third-party/glad/include/glad/egl.h

typedef EGLenum(EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC)(EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
typedef EGLenum(EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC)(EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);

GLAD_API_CALL PFNEGLQUERYDMABUFFORMATSEXTPROC glad_eglQueryDmaBufFormatsEXT;
#define eglQueryDmaBufFormatsEXT glad_eglQueryDmaBufFormatsEXT
GLAD_API_CALL PFNEGLQUERYDMABUFMODIFIERSEXTPROC glad_eglQueryDmaBufModifiersEXT;
#define eglQueryDmaBufModifiersEXT glad_eglQueryDmaBufModifiersEXT

becomes

typedef EGLBoolean(GLAD_API_PTR *PFNEGLQUERYDMABUFFORMATSEXTPROC)(EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
typedef EGLBoolean(GLAD_API_PTR *PFNEGLQUERYDMABUFMODIFIERSEXTPROC)(EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);

// ...
GLAD_API_CALL PFNEGLQUERYDMABUFFORMATSEXTPROC glad_eglQueryDmaBufFormatsEXT;
#define eglQueryDmaBufFormatsEXT glad_eglQueryDmaBufFormatsEXT
GLAD_API_CALL PFNEGLQUERYDMABUFMODIFIERSEXTPROC glad_eglQueryDmaBufModifiersEXT;
#define eglQueryDmaBufModifiersEXT glad_eglQueryDmaBufModifiersEXT

third-party/glad/src/egl.c

PFNEGLQUERYDMABUFFORMATSEXTPROC glad_eglQueryDmaBufFormatsEXT = NULL;
PFNEGLQUERYDMABUFMODIFIERSEXTPROC glad_eglQueryDmaBufModifiersEXT = NULL;
// ...
static void glad_egl_load_EGL_EXT_image_dma_buf_import_modifiers( GLADuserptrloadfunc load, void* userptr) {
    glad_eglQueryDmaBufFormatsEXT = (PFNEGLQUERYDMABUFFORMATSEXTPROC) load(userptr, "eglQueryDmaBufFormatsEXT");
    glad_eglQueryDmaBufModifiersEXT = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC) load(userptr, "eglQueryDmaBufModifiersEXT");
}
// ...
glad_egl_load_EGL_EXT_image_dma_buf_import_modifiers(load, userptr);

if (!glad_egl_find_extensions_egl(display)) return 0;

return version;

becomes

PFNEGLQUERYDMABUFFORMATSEXTPROC glad_eglQueryDmaBufFormatsEXT = NULL;
PFNEGLQUERYDMABUFMODIFIERSEXTPROC glad_eglQueryDmaBufModifiersEXT = NULL;
// ...
static void glad_egl_load_EGL_EXT_image_dma_buf_import_modifiers(GLADuserptrloadfunc load, void *userptr) {
    if (!GLAD_EGL_EXT_image_dma_buf_import_modifiers) {
        return;
    }
    glad_eglQueryDmaBufFormatsEXT = (PFNEGLQUERYDMABUFFORMATSEXTPROC) load(userptr, "eglQueryDmaBufFormatsEXT");
    glad_eglQueryDmaBufModifiersEXT = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC) load(userptr, "eglQueryDmaBufModifiersEXT");
}

// ...
if (!glad_egl_find_extensions_egl(display)) {
    return 0;
}
glad_egl_load_EGL_EXT_image_dma_buf_import_modifiers(load, userptr);
  
return version;

I also don't run Linux, so I have not tested that this actually works. I could setup a Linux machine if needed to test, but it would probably take me a couple weeks as I have some other commitments coming up soon.

@ReenigneArcher ReenigneArcher marked this pull request as ready for review March 3, 2026 01:11
@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch 4 times, most recently from 5e520e2 to bd7ff4d Compare March 3, 2026 03:47
@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch 3 times, most recently from 73f0faf to 1435bb0 Compare March 5, 2026 01:47
@ReenigneArcher

This comment was marked as resolved.

@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch from 1435bb0 to de68304 Compare March 5, 2026 02:10
@ReenigneArcher ReenigneArcher added this to the sonar milestone Mar 6, 2026
@psyke83

This comment was marked as resolved.

@ReenigneArcher

This comment was marked as resolved.

@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch 12 times, most recently from 1680d61 to 597a241 Compare March 13, 2026 17:43
@ReenigneArcher

This comment was marked as resolved.

ReenigneArcher and others added 5 commits March 15, 2026 18:37
GL_OES_EGL_image (glEGLImageTargetTexture2DOES) is GLES-only and must be loaded at runtime via eglGetProcAddress. Replace the previous global pointer with a static internal symbol and an accessor (egl_image_target_texture_2d()) declared in the header, update the typedef to use void* for GLeglImageOES, and load the function with a GLADapiproc cast. Add availability checks and error logging before using the function to avoid null calls, and adjust related call sites. Also remove a now-unnecessary vector reserve in surface_descriptor_to_egl_attribs.
* misc.cpp: phase 1 load (symbols only, defaults to EGL 1.0).
* graphics.cpp: phase 2 load using correct display configuration with
  eglGetPlatformDisplayEXT (initializes proper EGL version dispatch).
* Retain eglGetPlatformDisplay fallback if proprietary drivers need it.
* Add missing/required extensions to GLAD makefile based on existing
  extensions queried & new eglGetPlatformDisplayEXT requirement.
* Remove hardcoded definitions that are part of previously missing
  extensions.
Remove the temporary CI step that printed and diffed generated glad sources against the versions on master. The removed step installed lint deps, ran clang-format on generated files, fetched the master tree, and compared each generated glad file (egl/gl) to its pre-committed counterpart for verification. This cleans up the ci-linux workflow now that the verification is complete and reduces CI noise and runtime.
@ReenigneArcher ReenigneArcher force-pushed the build/linux/generate-glad-sources-at-compile-time branch from e74ea2e to 38c33c2 Compare March 15, 2026 22:38
@sonarqubecloud
Copy link

@ReenigneArcher ReenigneArcher merged commit ea20115 into master Mar 16, 2026
72 of 73 checks passed
@ReenigneArcher ReenigneArcher deleted the build/linux/generate-glad-sources-at-compile-time branch March 16, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants