Repository navigation
Keep backend objects in MSVC static builds - #125
Merged
ethindp merged 6 commits intoSep 18, 2026
Merged
Conversation
Contributor
Author
|
The ARM64 lint job caught a real gap, thanks CI.
Pushed as 85ece1b. |
ethindp
pushed a commit
that referenced
this pull request
Sep 22, 2026
Fixes #130. A static prism linked with GCC or Clang registers no backends unless the archive is linked whole. `gnu::used` and `gnu::retain` keep a registrar inside its own object, but nothing references a backend's object, so the linker never pulls it out of the archive in the first place. #125 solved this for MSVC with `/include:` directives. Every other toolchain was still relying on the attributes. ## What this does The anchors #125 added are already emitted on every compiler. The generated `backend_anchors.h` now also covers GCC and Clang: it declares each backend's anchor and takes its address in a `[[gnu::used]]` array. The header is included by `prism.cpp`, which the linker always keeps because the application calls `prism_init`, so those references pull every backend object in. MSVC keeps its directives, unchanged. The header is generated and included on every platform now, rather than only under MSVC. ## Testing The reproduction from #130, on GitHub's runners, linking `libprism.a` with no `--whole-archive` or `-force_load`: Ubuntu 24.04, GCC 13.3 (`speech_dispatcher=on`): ``` registered backends: 1 Speech Dispatcher ``` macOS, Apple Clang (`avspeech=on voiceover=on`): ``` registered backends: 2 VoiceOver AVSpeech ``` The MSVC static build was checked as well, in a .NET Native AOT application that links `prism.lib` and lists its backends on x64, x86 and ARM64.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #124.
A backend registers itself through a file-scope static, so nothing outside its own object refers to it.
[[gnu::used, gnu::retain]]stops GCC and Clang dropping it; MSVC honours neither, so a static build discards every backend object andprism_create_bestreports "backend not available" with a screen reader running.What this does
REGISTER_BACKENDnow also emits anextern "C"anchor function, named byPRISM_BACKEND_ANCHOR, whichcmake/PrismBackends.cmakedefines per backend from the name it already has. The build then generates one/include:directive per backend that was actually built.Those directives go in a header included by
source/prism.cpp, not in a source file of their own. The linker reads directives only from objects it has already decided to link, so an object holding nothing but directives would be dropped for exactly the reason it exists to prevent.prism.cppis always in the link because the consumer calls into it.x86 gets the leading underscore that cdecl carries there; nothing else does. Non-MSVC builds are untouched, since the existing attributes already say this.
The second half
Retaining the objects then exposes their vendor imports, which a shared prism links for itself:
The import libraries were already installed for static builds, but only
prism-config.cmakenamed them, so consumers that do not build with CMake could not find out. The install step now also writeslib/prism-static-windows.txt, one line per backend giving the import library and the DLL behind it.The DLL name matters as much as the library. Those DLLs are delay loaded in the shared build, and a static consumer that does not delay load them turns every screen reader into a hard dependency: the program will not start unless all of them are present.
Testing
Built static on MSVC x64 and linked into a Rust application through
prism-sys:create_bestreturned "backend not available", NVDA runningcreate_bestreturnedNVDA, noprism.dllbeside the executable, and the program starts on a machine with none of the vendor DLLs installedShared builds were rebuilt and behave as before. I have not been able to test x86 or MinGW, so the underscore branch and the non-MSVC paths are reasoned rather than run.