Skip to content

build: compile FileStream, error categories, thread priority and two tests on macOS - #10419

Merged
adriadam10 merged 43 commits into
boykopovar:mainfrom
iamthehimansh:split/macos-build
Oct 25, 2026
Merged

adriadam10 merged 43 commits into
boykopovar:mainfrom
iamthehimansh:split/macos-build

Conversation

@iamthehimansh

@iamthehimansh iamthehimansh commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Part 1 of splitting #8658 into topic PRs, as @adriadam10 asked: the shared-file build fixes that let main compile further on macOS. #4627 (@mugurc) has since landed the Formatting.cpp and ExportMacros.hpp parts, so this PR carries only what is still missing on main. All changes are macOS-only; Linux and Windows compile the same code as before.

  • FileStream.hpp: call feof_unlocked / ferror_unlocked unqualified. The macOS SDK defines them as macros, so ::feof_unlocked does not exist.
  • StandardExceptions.cpp: const_cast the error-category vtable slot before the function-pointer reinterpret_cast, which Apple clang rejects as casting away qualifiers. Without it libc/src/exception/Exports.cpp fails to build since std::system_category landed.
  • ThreadPriority.cpp: macOS has no rtkit or RLIMIT_RTTIME. high asks for the user-interactive QoS class, and rt for a Mach time-constraint policy (period 1 ms, computation 0.5 ms), documented in docs/dev/ENVIRONMENT.md.
  • GuestContentSearch.cpp and GuestNpWebApi2.cpp: include <initializer_list>.

On macOS, main still fails 13 objects with this PR, each in a file another open macOS PR changes: GuestAllocations.cpp (branch), DirectMemory.cpp (#7631), Thread.cpp and Process.cpp (#7804), Exception.cpp and GuestRaiseException.cpp (#4630), and NativeStat.cpp, SharedMemory.cpp, Stdio.cpp, DynamicLoader.cpp, ModuleInfo.cpp and Rtld.cpp (#7201).

With BUILD_TESTING=ON, libSceAgcDriver also fails in Driver/Lifecycle.cpp (MAP_FIXED_NOREPLACE), Execution/src/GuestMemory.cpp (link.h), GuestBufferMemory.cpp (linux/udmabuf.h) and Texture.cpp (is_trivially_copyable on a std::shared_ptr). Those fixes were in #8658 and come in the AGC driver part of the split, since they need the driver memory and dma-buf changes there.

Tested

macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on main at a23f8fc9f. The library build's remaining failures are the 13 objects above. For Linux and Windows, I checked each changed file's view under unifdef -U__APPLE__, with -D__linux__ and with -D_WIN32: it equals main. python3 tools/check_conventions.py --base origin/main passes.

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 (Cana)

…ts on macOS

A macOS build of main failed 49 objects. Most included
libc/include/FileStream.hpp, whose global-namespace ::feof_unlocked and
::ferror_unlocked do not exist there (they are macros in the macOS SDK).
On macOS:

- FileStream.hpp calls feof_unlocked and ferror_unlocked unqualified.
- ExportMacros.hpp adds the leading underscore Mach-O gives C symbols to
  both names in APS5_EXPORT, so the .set alias resolves.
- ThreadPriority.cpp has no rtkit or RLIMIT_RTTIME; "high" asks for the
  user-interactive QoS class and "rt" for a Mach time-constraint policy
  (period 1 ms, computation 0.5 ms), documented in ENVIRONMENT.md.
- Formatting.cpp maps the SysV va_list builtins to va_list, and
  GuestContentSearch.cpp and GuestNpWebApi2.cpp include
  <initializer_list>.

With these, 16 objects still fail on macOS; each is in a file changed by
an open macOS PR. Linux and Windows compile the same code as before.
# Conflicts:
#	core/libs/tests/Formatting.cpp
Apple clang rejects reinterpret_cast from const void* to a function
pointer ("casts away qualifiers") in StandardExceptions.cpp, so
libc/src/exception/Exports.cpp, which includes it, failed to build on
macOS after std::system_category landed. On macOS the vtable slot is
const_cast first. Linux and Windows compile the same code as before.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the current diff and hosted checks. The macOS-only branches address the reported SDK/compiler failures, the Linux/Windows paths remain unchanged, and the author reports a focused Apple Silicon build plus Rosetta x86_64 compile. Hosted conventions, eligibility, intake, labels, register-context, and write-watch checks pass; Linux and Windows product jobs were skipped by the repository path policy. I found no blocking issue.

@iamthehimansh

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thank you for the review and for checking the hosted runs. I'll keep the branch current with main until it lands.

AI-assisted: yes (Cana)

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1896 docs/dev/ENVIRONMENT.md
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/ThreadPriority.cpp
core/libs/prx/libc/include/FileStream.hpp
PR 6924 docs/dev/ENVIRONMENT.md
PR 7201 core/libs/prx/libSceAgcDriver/Execution/src/ThreadPriority.cpp
core/libs/prx/libc/include/FileStream.hpp
PR 7447 core/libs/prx/libc/include/FileStream.hpp
PR 7449 docs/dev/ENVIRONMENT.md
PR 7457 docs/dev/ENVIRONMENT.md
PR 7514 docs/dev/ENVIRONMENT.md
PR 7604 docs/dev/ENVIRONMENT.md
PR 7642 docs/dev/ENVIRONMENT.md
PR 8004 docs/dev/ENVIRONMENT.md
PR 8077 docs/dev/ENVIRONMENT.md
PR 8161 docs/dev/ENVIRONMENT.md
PR 8246 docs/dev/ENVIRONMENT.md
PR 8484 docs/dev/ENVIRONMENT.md
PR 8542 docs/dev/ENVIRONMENT.md
PR 8896 docs/dev/ENVIRONMENT.md
PR 9176 docs/dev/ENVIRONMENT.md
PR 9248 docs/dev/ENVIRONMENT.md
PR 9287 docs/dev/ENVIRONMENT.md
PR 9289 docs/dev/ENVIRONMENT.md
PR 9345 docs/dev/ENVIRONMENT.md
PR 9356 docs/dev/ENVIRONMENT.md
PR 9385 docs/dev/ENVIRONMENT.md
PR 9387 docs/dev/ENVIRONMENT.md
PR 9669 docs/dev/ENVIRONMENT.md
PR 9676 docs/dev/ENVIRONMENT.md
PR 9852 docs/dev/ENVIRONMENT.md
PR 9898 docs/dev/ENVIRONMENT.md
PR 9989 docs/dev/ENVIRONMENT.md
PR 10193 docs/dev/ENVIRONMENT.md
PR 10194 docs/dev/ENVIRONMENT.md
PR 10405 core/libs/prx/libc/include/FileStream.hpp
PR 10442 docs/dev/ENVIRONMENT.md
PR 10547 docs/dev/ENVIRONMENT.md

@iamthehimansh

Copy link
Copy Markdown
Contributor Author

@oneandonlydean @adriadam10 Could one of you review this when you have time? It's split PR 1 of #8658, as @adriadam10 asked: 6 files of macOS-only build fixes. Linux and Windows compile the same code as main, the hosted checks are green, @MarcZX10 has approved it, and it's current with main. It's in the same area as #4627, #8279 and #10052, which you merged.

AI-assisted: yes (Cana)

@adriadam10 adriadam10 self-assigned this Oct 24, 2026
@iamthehimansh

Copy link
Copy Markdown
Contributor Author

@oneandonlydean @adriadam10 a gentle ping for review when you have time.

It changes 6 files. Every code change is macOS-only: with __APPLE__ undefined, the Linux and Windows preprocessor views of each file are identical to main. All checks pass at 4050dce20, and I keep the branch merged with main. MarcZX10 approved it, and krishalivaibhav built and ran it on an M2 MacBook Air. Happy to split it further or change anything you'd like.

AI-assisted: yes (Cana)

@krishalivaibhav

Copy link
Copy Markdown
Contributor

@iamthehimansh a note for planning your next split PRs: on current main, a relinked macOS game can't start yet.

I built main (57f506f) plus the open macOS PRs on an M2 (x86_64 Release) and ran Balatro (PPSA21402). It stops in dyld before any guest code runs: symbol not found '_Aps5StartGuest_nid_no_patch'. The relinker's macOS output already binds that symbol (MacOsImage.cpp:668), but nothing on main defines it, and I found no open PR that does.

On a local scratch branch (not for a PR), I took these pieces from your 66a0ac4968, in the order the run needed them:

  1. libc: GuestStart.cpp, GuestTls.cpp, include/MainThread.hpp, the two source lines and the CoreFoundation link in libc/CMakeLists.txt, and the 0x400 load-command reserve in the relinker's MacOsImage.cpp. With these, Balatro gets past _Aps5StartGuest.
  2. The next stop is _Aps5RunOnMainThread_nid_no_patch, which libSceVideoOut.prx needs: the VideoOut main-thread hunks from the same commit.
  3. A current VideoOut links libSceAgcDriver, which doesn't build on macOS on main yet (SpirvOptimizer.cpp:42 pthread_getattr_np, plus Lifecycle.cpp, GuestMemory.cpp, GuestBufferMemory.cpp and Texture.cpp). I stopped there.
  4. libSceAudioIn.prx also needs build(libSceAudioIn): keep --exclude-libs off Apple's linker #10669 to link.

Are 1 and 2 already in one of your planned splits? If you open them, I'll run Balatro on M2 with them and report back.

AI-assisted: yes (Claude Code)

@iamthehimansh

Copy link
Copy Markdown
Contributor Author

@krishalivaibhav thanks, that's a useful map of what a game needs to start on main.

Yes, 1 and 2 are both planned, as one "start relinked games on macOS" PR built from 66a0ac4968: the libc guest entry, TLS and main-thread pieces, the CoreFoundation link, the relinker's 0x400 load-command reserve, and the VideoOut main-thread hunks. The four libSceAgcDriver files from your step 3 go in a separate AGC-driver PR. The SpirvOptimizer.cpp pthread_getattr_np failure is new since my branch, so I'll add a macOS fix for it there.

The repo's intake check allows one open PR for an author with no merged PRs, so these open one at a time after this one merges. I'll tag you on each one, and a Balatro run on your M2 would be very welcome.

AI-assisted: yes (Cana)

@adriadam10
adriadam10 merged commit 9c6d153 into boykopovar:main Oct 25, 2026
14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked on current main (6f58a04): the merge is clean. Main's change to GuestContentSearch.cpp (the extern block moved to Api.hpp) doesn't touch the added <initializer_list> include, and the macOS branches of the six files are unchanged. Linux and Windows views of each file are the same as main. Merged.

@iamthehimansh

Copy link
Copy Markdown
Contributor Author

@krishalivaibhav the game-start part from your Balatro note is now up as #11284: guest entry, guest TLS, main-thread windows and the relinker's load-command reserve. The SpirvOptimizer.cpp fix stays for the graphics-driver PR.

Balatro still needs libkernel to build on macOS before libc can link, which is your #10552 plus #11246, #11249, #11282 and #10898. If you get a chance to run it on your M2 once those are in, that would be the real test.

AI-assisted: yes (Cana)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants