feat(libcairo): build Cairo and pixman from source (#19098) #19141

Merged
BSchneppe merged 2 commits from upstream-pr/19141 into main 2026-11-13 20:55:16 +00:00
BSchneppe commented 2026-11-12 21:30:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BSchneppe on 2026-11-12T21:30:21Z.


What

First part of #19098: libcairo now builds Cairo and pixman from source, and the ten cairo_matrix_* and six cairo_region_* exports run on them instead of the hand-written code. Nothing draws yet; surfaces, contexts and paths follow in the next pull request.

  • Cairo 1.18.0 and pixman 0.42.2 are new submodules (3rdparty/cairo, 3rdparty/pixman), built by cmake/Cairo.cmake and cmake/Pixman.cmake like cmake/LibPsl.cmake, with the image backend only. Their licence files are installed verbatim and shipped in release archives.
  • Versions: Sony publishes the console's Cairo at https://www.playstation.com/en-us/oss/ps5/cairo/. The archive for system software 9.00 and later contains Cairo 1.18.0 plus three Sony patches, which are not applied (see docs/dev/debt/libcairo.md). Sony publishes no pixman, so 0.42.2 was chosen: it was the newest pixman when Cairo 1.18.0 came out.
  • The forwarding code (Matrix.cpp, Region.cpp) is in its own files. The other hand-written exports keep Cairo's public names in the same library, so Cairo is compiled with its public functions renamed to aps5_cairo_*, and none of Cairo's or pixman's symbols are exported.
  • Native Cairo disagrees with three assertions of the old tests, checked against Homebrew Cairo 1.18.6, whose code for these cases is unchanged from 1.18.0. The tests now expect Cairo's results:
    • cairo_matrix_invert of {1, 1, 0, inf, 1, 1} returns 0 and leaves {nan, -0, -0, 0, nan, 0}, not CAIRO_STATUS_INVALID_MATRIX.
    • cairo_region_union_rectangle with {INT32_MAX, 0, 2, 2} returns 0 and ignores the rectangle, not CAIRO_STATUS_INVALID_SIZE. A box wider than INT32_MAX overflows inside Cairo, so the test no longer checks it.
    • The hand-written context functions call the matrix exports, so they now accept a matrix with an infinite entry, as Cairo's own cairo_set_matrix does.

Tested

  • macOS 26 (x86-64 under Rosetta, AppleClang): all 12 guest_cairo_* tests and the public_headers tests pass. tools/tests/test_package_release.py passes. libcairo.prx exports the 161 cairo_* names and no pixman_* or aps5_* symbol.
  • Windows 11 (WinLibs GCC 15.2.0 r7): all 12 guest_cairo_* tests pass, and the export table is the same.
  • Linux (Ubuntu 24.04 container, GCC 13): all 12 guest_cairo_* tests pass, and the dynamic symbol table has no backend symbols.
  • No title was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5285534143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19141). Originally posted by [BSchneppe](https://github.com/BSchneppe) on 2026-11-12T21:30:21Z. --- ### What First part of #19098: libcairo now builds Cairo and pixman from source, and the ten `cairo_matrix_*` and six `cairo_region_*` exports run on them instead of the hand-written code. Nothing draws yet; surfaces, contexts and paths follow in the next pull request. - Cairo 1.18.0 and pixman 0.42.2 are new submodules (`3rdparty/cairo`, `3rdparty/pixman`), built by `cmake/Cairo.cmake` and `cmake/Pixman.cmake` like `cmake/LibPsl.cmake`, with the image backend only. Their licence files are installed verbatim and shipped in release archives. - Versions: Sony publishes the console's Cairo at https://www.playstation.com/en-us/oss/ps5/cairo/. The archive for system software 9.00 and later contains Cairo 1.18.0 plus three Sony patches, which are not applied (see `docs/dev/debt/libcairo.md`). Sony publishes no pixman, so 0.42.2 was chosen: it was the newest pixman when Cairo 1.18.0 came out. - The forwarding code (`Matrix.cpp`, `Region.cpp`) is in its own files. The other hand-written exports keep Cairo's public names in the same library, so Cairo is compiled with its public functions renamed to `aps5_cairo_*`, and none of Cairo's or pixman's symbols are exported. - Native Cairo disagrees with three assertions of the old tests, checked against Homebrew Cairo 1.18.6, whose code for these cases is unchanged from 1.18.0. The tests now expect Cairo's results: - `cairo_matrix_invert` of `{1, 1, 0, inf, 1, 1}` returns 0 and leaves `{nan, -0, -0, 0, nan, 0}`, not `CAIRO_STATUS_INVALID_MATRIX`. - `cairo_region_union_rectangle` with `{INT32_MAX, 0, 2, 2}` returns 0 and ignores the rectangle, not `CAIRO_STATUS_INVALID_SIZE`. A box wider than `INT32_MAX` overflows inside Cairo, so the test no longer checks it. - The hand-written context functions call the matrix exports, so they now accept a matrix with an infinite entry, as Cairo's own `cairo_set_matrix` does. ### Tested - macOS 26 (x86-64 under Rosetta, AppleClang): all 12 `guest_cairo_*` tests and the `public_headers` tests pass. `tools/tests/test_package_release.py` passes. `libcairo.prx` exports the 161 `cairo_*` names and no `pixman_*` or `aps5_*` symbol. - Windows 11 (WinLibs GCC 15.2.0 r7): all 12 `guest_cairo_*` tests pass, and the export table is the same. - Linux (Ubuntu 24.04 container, GCC 13): all 12 `guest_cairo_*` tests pass, and the dynamic symbol table has no backend symbols. - No title was run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-12 21:31:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T21:31:53Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 95f7f88cba:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: CMakeLists.txt failed to build.
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    CMake Error at cmake/Cairo.cmake:28 (file):
      file STRINGS file "3rdparty/cairo/src/cairo.h"
      cannot be read.
    Call Stack (most recent call first):
      cmake/Cairo.cmake:89 (add_bundled_cairo)
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    -- Configuring incomplete, errors occurred!
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5882333850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19141#pullrequestreview-5882333850). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T21:31:53Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `95f7f88cba`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `CMakeLists.txt` failed to build. ``` core/libs/prx/libcairo/CMakeLists.txt:4 (include) CMake Error at cmake/Cairo.cmake:28 (file): file STRINGS file "3rdparty/cairo/src/cairo.h" cannot be read. Call Stack (most recent call first): cmake/Cairo.cmake:89 (add_bundled_cairo) core/libs/prx/libcairo/CMakeLists.txt:4 (include) -- Configuring incomplete, errors occurred! ``` - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-12 21:39:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T21:39:31Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 95f7f88cba:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: CMakeLists.txt failed to build.
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    CMake Error at cmake/Cairo.cmake:28 (file):
      file STRINGS file "3rdparty/cairo/src/cairo.h"
      cannot be read.
    Call Stack (most recent call first):
      cmake/Cairo.cmake:89 (add_bundled_cairo)
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    -- Configuring incomplete, errors occurred!
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5882438369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19141#pullrequestreview-5882438369). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T21:39:31Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `95f7f88cba`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `CMakeLists.txt` failed to build. ``` core/libs/prx/libcairo/CMakeLists.txt:4 (include) CMake Error at cmake/Cairo.cmake:28 (file): file STRINGS file "3rdparty/cairo/src/cairo.h" cannot be read. Call Stack (most recent call first): cmake/Cairo.cmake:89 (add_bundled_cairo) core/libs/prx/libcairo/CMakeLists.txt:4 (include) -- Configuring incomplete, errors occurred! ``` - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-12 22:11:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T22:11:34Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 95f7f88cba:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: CMakeLists.txt failed to build.
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    CMake Error at cmake/Cairo.cmake:28 (file):
      file STRINGS file "3rdparty/cairo/src/cairo.h"
      cannot be read.
    Call Stack (most recent call first):
      cmake/Cairo.cmake:89 (add_bundled_cairo)
      core/libs/prx/libcairo/CMakeLists.txt:4 (include)
    
    
    -- Configuring incomplete, errors occurred!
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5882806311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19141#pullrequestreview-5882806311). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T22:11:34Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `95f7f88cba`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `CMakeLists.txt` failed to build. ``` core/libs/prx/libcairo/CMakeLists.txt:4 (include) CMake Error at cmake/Cairo.cmake:28 (file): file STRINGS file "3rdparty/cairo/src/cairo.h" cannot be read. Call Stack (most recent call first): cmake/Cairo.cmake:89 (add_bundled_cairo) core/libs/prx/libcairo/CMakeLists.txt:4 (include) -- Configuring incomplete, errors occurred! ``` - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-13 19:43:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:43:40Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 95f7f88cba:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_cairo_matrix_tests, guest_cairo_regions_tests built cleanly.
  • CTest (guest_cairo_matrix, guest_cairo_regions):
    1/2 Test #4399: guest_cairo_matrix ...............   Passed    0.04 sec
    2/2 Test #4404: guest_cairo_regions ..............   Passed    0.07 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libcairo/Matrix.cpp, core/libs/prx/libcairo/Region.cpp, core/libs/prx/libcairo/include/InventoryExports.hpp, core/libs/prx/libcairo/libcairo.hpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #4404: guest_cairo_regions ..............Subprocess aborted***Exception:   0.41 sec
    2/2 Test #4399: guest_cairo_matrix ...............Subprocess aborted***Exception:   0.48 sec
    0% tests passed, 2 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libcairo/Matrix.cpp: Verified memory layout and struct field alignment between CairoMatrix and cairo_matrix_t using sizeof and offsetof static assertions, ensuring value conversions via std::bit_cast across all 10 cairo_matrix_* exports preserve PS5 guest ABI and prevent multiplication aliasing defects.
    • core/libs/prx/libcairo/Region.cpp: Verified null pointer validation and bounds checking in cairo_region_union_rectangle (returning CAIRO_STATUS_NULL_POINTER on null region or rectangle), cairo_region_get_rectangle (zeroing output and exiting safely when region is null or nth is out of bounds), cairo_region_num_rectangles (returning 0 on null region), and null-safety in reference and destroy.
    • cmake/Cairo.cmake & cmake/Pixman.cmake: Verified LP64 (SIZEOF_LONG=8) vs LLP64 (SIZEOF_LONG=4) configuration, C++11 atomic refcounting, SSE2/SSSE3 compilation flags, static library symbol hiding via C_VISIBILITY_PRESET hidden and --exclude-libs,ALL, and macro redirection to aps5_cairo_* avoiding symbol collisions with guest exports.
    • tools/package_release.py & tools/tests/test_package_release.py: Verified packaging of Cairo (COPYING, COPYING-LGPL-2.1, COPYING-MPL-1.1) and pixman (COPYING) licenses into release archives with dedicated test coverage in test_cairo_and_pixman_licenses_in_archives.
    • docs/dev/debt/libcairo.md & AGENTS.md: Verified adherence to repository conventions including submodule additions in .gitmodules, technical debt recording for unapplied Sony patches and pixman arithmetic edge cases, and zero disallowed comments in code.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5897020239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19141#pullrequestreview-5897020239). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T19:43:40Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `95f7f88cba`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_cairo_matrix_tests`, `guest_cairo_regions_tests` built cleanly. - **CTest** (`guest_cairo_matrix`, `guest_cairo_regions`): ``` 1/2 Test #4399: guest_cairo_matrix ............... Passed 0.04 sec 2/2 Test #4404: guest_cairo_regions .............. Passed 0.07 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libcairo/Matrix.cpp`, `core/libs/prx/libcairo/Region.cpp`, `core/libs/prx/libcairo/include/InventoryExports.hpp`, `core/libs/prx/libcairo/libcairo.hpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #4404: guest_cairo_regions ..............Subprocess aborted***Exception: 0.41 sec 2/2 Test #4399: guest_cairo_matrix ...............Subprocess aborted***Exception: 0.48 sec 0% tests passed, 2 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libcairo/Matrix.cpp: Verified memory layout and struct field alignment between CairoMatrix and cairo_matrix_t using sizeof and offsetof static assertions, ensuring value conversions via std::bit_cast across all 10 cairo_matrix_* exports preserve PS5 guest ABI and prevent multiplication aliasing defects. - core/libs/prx/libcairo/Region.cpp: Verified null pointer validation and bounds checking in cairo_region_union_rectangle (returning CAIRO_STATUS_NULL_POINTER on null region or rectangle), cairo_region_get_rectangle (zeroing output and exiting safely when region is null or nth is out of bounds), cairo_region_num_rectangles (returning 0 on null region), and null-safety in reference and destroy. - cmake/Cairo.cmake & cmake/Pixman.cmake: Verified LP64 (SIZEOF_LONG=8) vs LLP64 (SIZEOF_LONG=4) configuration, C++11 atomic refcounting, SSE2/SSSE3 compilation flags, static library symbol hiding via C_VISIBILITY_PRESET hidden and --exclude-libs,ALL, and macro redirection to aps5_cairo_* avoiding symbol collisions with guest exports. - tools/package_release.py & tools/tests/test_package_release.py: Verified packaging of Cairo (COPYING, COPYING-LGPL-2.1, COPYING-MPL-1.1) and pixman (COPYING) licenses into release archives with dedicated test coverage in test_cairo_and_pixman_licenses_in_archives. - docs/dev/debt/libcairo.md & AGENTS.md: Verified adherence to repository conventions including submodule additions in .gitmodules, technical debt recording for unapplied Sony patches and pixman arithmetic edge cases, and zero disallowed comments in code. - Note: the AI-assisted checkbox can stay. Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19141
No description provided.