Repository navigation
build(win): share session code via rsession-shared.dll between launcher stubs - #18070
Conversation
…er stubs On Windows the rsession.exe and rsession-utf8.exe binaries were identical code with different embedded manifests, each statically linking its own full copy of the session code. Build the code once into rsession-shared.dll and make the two executables thin launcher stubs that load it, so we ship a single copy of the (large) session code instead of two. The executables differ only in the manifest embedded via their .rc file; the active code page is fixed at process startup from the launching exe's manifest and applies process-wide, including to code in the DLL, so the per-manifest stubs are sufficient. Non-Windows builds are unchanged apart from moving main() into SessionMainStub.cpp.
Code review findingsActionable items from an automated multi-agent review (code quality + comment accuracy). The build mechanism itself was verified sound: CMake wiring, the Important
Suggestions
|
gtritchie
left a comment
There was a problem hiding this comment.
LGTM! Some minor comment tweaks to consider, and wrong copyright year on a new file.
🍎 macOS Desktop E2E · ARM64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · macos-26 ARM64 · commit |
🪟 Windows Desktop E2E · Server 2025 x64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · Windows Server 2025 x64 · commit |
#18070 moved the bulk of the session code out of rsession.exe and rsession-utf8.exe into a shared library, leaving the two executables as thin launcher stubs. The Sign Executables stage was not updated, so the signed stubs load an unsigned DLL holding essentially all of the session implementation -- which WDAC, AppLocker publisher rules, and some EDR configurations evaluate as a loaded module. Add both build-tree copies of the DLL to %EXECUTABLES%: the x64 one next to the stubs, and the x86 one that the multiarch build installs into src/cpp/session/x86 alongside x86/rsession.exe. Signing already runs before the Package stage, so the installer picks up the signed DLLs. Addresses #18512
The multiarch Windows Desktop build installs the 32-bit session into <build>/src/cpp/session/x86, and the 64-bit build had an install rule that collected that directory into resources/app/bin/x86 at package time. That rule sat inside an "install winpty on windows" block and was deleted with it in 04db3f5, so since 2026.06.0 the shipped installer has resources/app/bin/x86 with only the x86 VC runtime DLLs -- no rsession.exe, and since #18070 no rsession.dll. With a 32-bit R, session-launcher.ts finds no x86/rsession.exe and falls back to the 64-bit session, which cannot load a 32-bit R.dll. Restore the rule under a comment that names its actual source, and keep the file(MAKE_DIRECTORY) call: install(DIRECTORY) errors on a missing source directory, and non-multiarch builds never create it. Addresses #18515
Backport of #18516 (06473dc) to Yellow Yarrow. This branch carries the rsession-shared library from #18070, so rsession.exe and rsession-utf8.exe are thin launcher stubs and rsession.dll holds essentially all of the session implementation -- but %EXECUTABLES% in the Sign Executables stage still named only the .exe files, so the shipped DLL was unsigned. Add both build-tree copies of the DLL: the x64 one next to the stubs, and the x86 one that the multiarch build installs into src/cpp/session/x86 alongside x86/rsession.exe. Signing runs before the Package stage, so the installer picks up the signed DLLs. The NEWS entry goes in version/news/os/NEWS-2026.08.1-yellow-yarrow.md, since NEWS.md is not carried on this branch. Addresses #18557
Backport of #18519 (9e0e8e9) to Yellow Yarrow. The multiarch Windows Desktop build installs the 32-bit session into <build>/src/cpp/session/x86, and the 64-bit build had an install rule that collected that directory into resources/app/bin/x86 at package time. That rule sat inside an "install winpty on windows" block and was deleted with it in 04db3f5 (#17814), so the shipped installer has resources/app/bin/x86 with only the x86 VC runtime DLLs -- no rsession.exe, and since #18070 no rsession.dll. With a 32-bit R, session-launcher.ts finds no x86/rsession.exe and falls back to the 64-bit session, which cannot load a 32-bit R.dll. Restore the rule under a comment that names its actual source, and keep the file(MAKE_DIRECTORY) call: install(DIRECTORY) errors on a missing source directory, and non-multiarch builds never create it. This is what makes the x86 binaries signed by 999de99 (#18562) actually reach the installer. The NEWS entry goes in version/news/os/NEWS-2026.08.1-yellow-yarrow.md, since NEWS.md is not carried on this branch. Addresses #18558
Summary
On Windows we ship two R session executables,
rsession.exeandrsession-utf8.exe. They are identical code with different embedded manifests (rsession-utf8.exedeclares a UTF-8activeCodePagefor UCRT builds of R 4.2.0+, selected at runtime viaR_RUNTIME=='ucrt'). Until now each executable statically linked its own full copy of the (large) session code, so we shipped two big binaries.This builds the session code once into
rsession.dlland turns the two executables into thin launcher stubs that load it. We now ship one copy of the heavy code plus two small stubs.Why this is safe
The process active code page is fixed at startup from the launching executable's manifest and applies process-wide -- including to code running in a DLL it loads. So a per-manifest stub is all that needs to differ between the two; the shared DLL inherits the correct (legacy or UTF-8) code page from whichever stub launched it.
This was verified empirically on a Windows VM: a single test DLL reported
GetACP() == 1252when loaded by a stub with no UTF-8 manifest and65001when loaded by an otherwise-identical stub carrying the UTF-8 manifest.What changed
SessionMain.cpp: theint main(...)body becomesRSESSION_MAIN_API int rsessionMain(...)(no logic changes).SessionMain.hpp: adds theRSESSION_MAIN_APIexport/import macro and thersessionMain()declaration.SessionMainStub.cpp(new): thinint main()that forwards torsessionMain(). Compiled into each stub on Windows, and into the single executable on other platforms.CMakeLists.txt(Windows): the oldrsession-objectsOBJECT library becomes aSHAREDlibrary shipped asrsession.dll(holdingSESSION_LIBRARIES+LIBR_LIBRARIES);rsession.exe/rsession-utf8.exebecome stubs that link it and keep their existing.rc/manifest. The CMake target stays namedrsession-sharedand its import lib /.pdbare namedrsession-shared.*so they do not collide with thersession.exestub's own.lib/.pdb. The DLL (and its PDB) are installed alongside. Non-Windows link configuration is unchanged (just fenced underNOT WIN32).Notes
rsessionexporting_rd_*viarsession.exports. On Windows the tword_*debug helpers (rd_eval/rd_traceback, declaredRS_EXPORT==__declspec(dllexport)) were previously exported fromrsession.exe; they are now exported fromrsession.dllinstead. They remain exported and debugger-discoverable in the loaded module, so this is behavior-preserving; the only newly added export isrsessionMain(so the stub can call into the DLL).rsession --run-testsstill works (the stub forwards argv torsessionMainin the DLL).rsession.dll; its import lib and.pdbare kept under thersession-sharedname (viaARCHIVE_OUTPUT_NAME/PDB_NAME) so they don't collide with thersession.exestub's.lib/.pdb.rsession-utf8target and theR_RUNTIME=='ucrt'launcher branch can be removed and a single UTF-8rsession.exeshipped.Validation
Windows build/packaging is exercised by CI. Worth confirming there:
rsession.dllis colocated with the stubs for dev/run-in-place launches, the installer picks up the new DLL, and the 32-bitSessionWin32build (no UTF-8 variant) packages its DLL + stub.Developer-only / build change; no user-facing behavior change, so no NEWS.md entry.