Skip to content

Fix RSTUDIO_USE_SYSTEM_DEPENDENCIES - #19239

Merged
gtritchie merged 42 commits into
rstudio:mainfrom
Flamefire:patch-1
Nov 2, 2026
Merged

gtritchie merged 42 commits into
rstudio:mainfrom
Flamefire:patch-1

Conversation

@Flamefire

@Flamefire Flamefire commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Intent

When RSTUDIO_USE_SYSTEM_DEPENDENCIES is set all dependencies must be found. Hunspell doesn't provide CMake targets and Rstudio uses the sources directly. Websocket++ doesn't provide a CMake config either

Approach

Add a flag to always download those and fix the names for RapidJSON and ZLIB find commands

Automated Tests

If desired a CI job could be added

Addresses #15965 (partially; see also #15996).

When `RSTUDIO_USE_SYSTEM_DEPENDENCIES` is set all dependencies must be found.
`Hunspell` doesn't provide CMake targets and Rstudio uses the sources directly.
Websocket++ doesn't provide a CMake config either

Add a flag to always download those and fix the names for RapidJSON and ZLIB find commands
This allows overriding the location by the caller
@gtritchie gtritchie added this to the 2026.11 (Montauk Daisy) milestone Oct 23, 2026

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this. As it stands, a configure with RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON still fails. The new REQUIRED flag is never read, and several other dependencies (dtl, utfcpp, websocketpp, gtest) hit the same kind of find_package failure. Details are inline. I checked package names and versions against the upstream sources at the revisions pinned in this file.

The broader issue: every CUSTOM dependency (DTL, HUNSPELL, RAPIDJSON, UTFCPP, WEBSOCKETPP, ZLIB) builds its rstudio-* target from ${PREFIX}_SOURCE_DIR, and only the fetch path sets that. A system package therefore can't satisfy any of them as written, whatever name find_package is given. Handling this once in fetch() (L184) would cover all of them, rather than tagging deps one at a time. For example: always fetch CUSTOM deps, or have the system path populate the include dirs. See the comment on L366.

Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
@gtritchie
gtritchie requested a review from kevinushey October 23, 2026 15:43

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. ALWAYS_FETCH is now applied, and the GTest and utf8cpp names plus the imported targets look right. I checked utf8cpp's exported include dir (include/utf8cpp, so <utf8.h> resolves) and its SameMajorVersion compatibility, and that the alias resolves from src/cpp/core. The Windows system-zlib issue is deferred to #19245.

One new problem: the zlib include-dir change at L451 breaks the default Windows build on a fresh configure (inline). Plus three small things inline: a RapidJSON gap with the 1.1.0 release, a stray-space typo, and indentation.

Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
…` and show error when it conflicts with ALWAYS_FETCH

This allows to enable all SYSTEM dependencies and select some that shall NOT be used which catches later additions.
@Flamefire

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Done all changes in the web editor, so should be fine but couldn't test them yet.
As for CI: Not sure how easy it would be to install all dependencies. Maybe EESSI could help here as it provides most dependencies already and the remaining ones should be relatively easy to add.

I also addressed your earlier comment about adding an error when RSTUDIO_USE_SYSTEM_X conflicts with ALWAYS_FETCH and extended it to allow RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON RSTUDIO_USE_SYSTEM_X=OFF to disable specific ones
That's a bit of new code added but should be reasonably clear and tightly related to the prior changes, so I hope it's fine to include.
For the RSTUDIO_USE_SYSTEM_DEPENDENCIES vs ALWAYS_FETCH the message could be downgraded to STATUS as it is (partly) expected but e.g. we try to not download anything during builds as our downloads get checksummed to avoid malicious modifications.

RapidJSON 1.1.0's config sets RAPIDJSON_INCLUDE_DIRS and exports no target. find_package() runs inside fetch(), so the variable was gone by the time rstudio-rapidjson checked it, and the target fell back to "/include". Addresses rstudio#15965.
dtl, Hunspell and websocketpp can never come from the system, so with RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON the warning fired on every configure for expected behavior. Addresses rstudio#15965.
@gtritchie

gtritchie commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Thanks for the quick iterations. Since maintainer edits are enabled, I've pushed the remaining changes to your branch rather than send another round:

  • Merged the latest main (no conflicts).
  • 79e553c: pass ${_PREFIX}_INCLUDE_DIRS out of fetch(). RapidJSON 1.1.0 (the only tagged release, and what Debian ships) exports no RapidJSON target and only sets RAPIDJSON_INCLUDE_DIRS; because find_package() runs inside the fetch() function, that variable never reached the new elseif, so rstudio-rapidjson still got /include. Checked against the v1.1.0 config.
  • b7d2717: report always-fetched dependencies as STATUS rather than WARNING, per your suggestion. fetch() already logs each download as "Fetching dependency ...", so they're still visible.
  • fd26a4b: indentation in the RSTUDIO_USE_SYSTEM_DEPENDENCIES branch.
  • 6f6c69a: NEWS entry.

I've also linked this PR to #15965 (partially, since Hunspell is fetched rather than taken from the system, so that issue stays open) and #15996. The pre-existing Windows system-zlib problem is tracked in #19245.

We'll approve once CI passes.

Please take a look at the changes and make sure it looks okay to you as well!

With RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON no 'gtest' target exists, so the test targets fell back to add_subdirectory() on src/cpp/tests/cpp/tests/vendor/gtest, which is not in the repo, and configure failed. Addresses rstudio#15965.
libgit2's installed config exports its target under the libgit2:: namespace, so with RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON rsession's 'libgit2package' became -llibgit2package and failed to link. Addresses rstudio#15965.
The entry said configuring with RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON was fixed outright; Windows system zlib is still broken (rstudio#19245). List the dependencies that were fixed instead. Addresses rstudio#15965.
@gtritchie

Copy link
Copy Markdown
Member

A few more commits on top, for two problems that come up after the ones fixed here when building with RSTUDIO_USE_SYSTEM_DEPENDENCIES=ON:

Both aliases are no-ops when the dependencies are fetched. Same plan as before: we'll approve once CI passes.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving, but will ping another reviewer to give it a fresh once-over before we merge.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working through this! A few issues inline. The first two (Windows zlib, GTest version) would still break -DRSTUDIO_USE_SYSTEM_DEPENDENCIES=ON for some setups; the rest are smaller.

One more outside the diff: the Windows hunspell include at L578 uses HUNSPELL_PREFIX_DIR, which is never defined, so it resolves to /msvc. That's pre-existing (it's on main too) and hunspell builds without it today, but since hunspell is now always fetched it'd be a good moment to change it to HUNSPELL_SOURCE_DIR.

Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the libgit2 fix works: configure now passes. The Linux and macOS builds then fail at:

ninja: error: 'src/cpp/ext/rstudio-zlib.lib', needed by 'src/cpp/session/rsession',
missing and no known rule to make it

This comes from 104bd51 removing PLATFORMS WIN32 from the zlib dependency: zlib is now fetched and built on every platform, using the Windows file name at L483. Beyond the file name, though, we want default Linux and macOS builds to keep linking the system zlib, as they do on main, rather than a bundled static copy. Before that commit CI found /usr/lib/x86_64-linux-gnu/libz.so; now it builds zlib 1.3.1 itself.

So rather than fixing the name, could you make the fetch Windows-only again while keeping rstudio-zlib available everywhere for core (from 5c4f9f0)?

  1. Put PLATFORMS WIN32 back on dependency(ZLIB ...).
  2. Find the system zlib in the not-fetched branch, since fetch() now skips zlib entirely off Windows:
if(NOT ZLIB_FETCHED)
   if(NOT TARGET ZLIB::ZLIB)
      find_package(ZLIB REQUIRED GLOBAL)
   endif()
   add_library(rstudio-zlib ALIAS ZLIB::ZLIB)
else()

On macOS this gives no zlib fetch, and rstudio-zlib resolves to the system libz. With the fetch Windows-only again, the .lib name at L483 and the "Windows only" comments at L476 and L490 are correct as they are.

@Flamefire

Copy link
Copy Markdown
Contributor Author

Another idea:

  • Fix the name
  • if(UNIX) set(RSTUDIO_SYSTEM_ZLIB TRUE)

That would keep the handling uniform.
Shall I do that instead?

Btw: It might be good to switch to namespace targets, i.e. rstudio::zlib. Then the configure fails already with a clearer message instead of only the build

@gtritchie

Copy link
Copy Markdown
Member

Thanks. Right, core needs zlib on Unix too (Response.cpp); on main that's covered by the system zlib, which is what we'd like to keep.

Routing zlib through the same fetch() path is appealing, but one catch: on the system path fetch() calls find_package(ZLIB "1.3.1" REQUIRED GLOBAL), using the pinned version as a minimum. The system zlib in CI is 1.3 on Ubuntu 24 and 1.2.12 in the macOS SDK, and both are rejected:

Could NOT find ZLIB: Found unsuitable version "1.3", but required is at least "1.3.1"

Main's core uses find_package(ZLIB REQUIRED) with no version, so this would break the default Linux and macOS builds. (Also, I assume you meant RSTUDIO_USE_SYSTEM_ZLIB; RSTUDIO_SYSTEM_ZLIB isn't read anywhere.)

So the uniform approach would need a zlib-specific exception to the version in fetch(). Keeping the fetch Windows-only with a versionless find_package(ZLIB REQUIRED GLOBAL) in zlib's own not-fetched branch (as in the review above) avoids that and matches main, so we'd lean that way. If you'd rather go uniform and handle the version, that works for us too.

On namespaced targets: agreed it's nicer. A missing rstudio::zlib fails at configure, where a missing rstudio-zlib silently becomes -lrstudio-zlib. It wouldn't have caught this particular failure, which came from the file path passed to libgit2, so let's leave renaming the targets for a separate PR.

It is only fetched on WIN32 and conditions at that point might be
confusing given the far-away usage.
So add it back here.
@Flamefire

Copy link
Copy Markdown
Contributor Author

Routing zlib through the same fetch() path is appealing, but one catch: on the system path fetch() calls find_package(ZLIB "1.3.1" REQUIRED GLOBAL), using the pinned version as a minimum. The system zlib in CI is 1.3 on Ubuntu 24 and 1.2.12 in the macOS SDK, and both are rejected:

True, that might be undesirable if any zlib version is fine on UNIX.
I decided to add back the original code: Use ZLIB::ZLIB for UNIX and rstudio-zlib for WIN32. To me the separation makes sense such that e.g. the following pattern is easier to understand:

if(WIN32)
   target_link_libraries(rstudio-core rstudio-zlib)
endif()

@gtritchie

Copy link
Copy Markdown
Member

Okay, I think we're close. I've merged your other PR so please merge main into this one again and we'll get another CI run.

@Flamefire

Copy link
Copy Markdown
Contributor Author

Done, diff is much smaller despite the many commits. I can rebase instead if desired to squash/remove the reverts, but might be good too to have the history.

One more thing I noticed when verifying the diff: I'd remove the PLATFORMS arg to dependency and move the fetch(ZLIB) into the if(WIN32) block. The mix of conditions in 2 places looks a bit odd

@gtritchie

Copy link
Copy Markdown
Member

We squash when we merge PRs so don't worry about the commit history.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the merge. The merge commit (f608e90) dropped one line in fetch(), though, and all four builds now fail at configure:

CMake Error at src/cpp/ext/CMakeLists.txt:568 (target_include_directories):
  Cannot specify include directories for target "libgit2package" which is not
  built by this project.

Before the merge there were two lines here:

set(${_PREFIX}_FETCHED ${do_fetch})
set(${_PREFIX}_FETCHED ${do_fetch} PARENT_SCOPE)

Only the PARENT_SCOPE one is left. That doesn't set the variable inside the function itself, so the if(${_PREFIX}_FETCHED) check in the second loop (L240) is false for every dependency and nothing is fetched. Could you add the first line back? Removing the duplicate fetch(GTest GTEST) block in the same merge was right; keep that.

On moving fetch(ZLIB ZLIB) into the if(WIN32) block and dropping PLATFORMS: either way works. PLATFORMS is how dependency() is documented to limit a dependency to some platforms, and the if(WIN32) around the target setup is needed regardless, so we'd leave it as it is.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks for all your work on this. I'll merge once CI passes.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 45b4c3e. Thanks for working through the dependency handling. I found two remaining issues, detailed inline: mixed-case RapidJSON include directories are lost across fetch(), and switching an existing Windows build to system zlib retains the bundled-library cache entries.

Both are reproduced with focused CMake checks. A Windows compile-and-run check using this revision's bundled libgit2, zlib, RapidJSON, and utf8cpp configuration passed, as did a clean build using the same system-zlib installation that fails after switching modes. Validation used CMake 4.2 and MSVC 19.51; I did not run a full RStudio build.

Comment thread src/cpp/ext/CMakeLists.txt Resolved
Comment thread src/cpp/ext/CMakeLists.txt Resolved
Configs from RapidJSON snapshots between 2017 and 2020 set only the
mixed-case variable and export no target, so the mixed-case branch in
the rstudio-rapidjson setup never saw it and configure failed.
@gtritchie
gtritchie requested a review from kevinushey October 30, 2026 18:25
@gtritchie

Copy link
Copy Markdown
Member

Unfortunately we're about to hit code freeze for the 2026.11 release, so this needs to wait until we've branched for that release before we merge this PR (i.e. Monday at the soonest).

So close!

@gtritchie
gtritchie merged commit 0ae1fff into rstudio:main Nov 2, 2026
38 checks passed
@Flamefire
Flamefire deleted the patch-1 branch November 3, 2026 07:47
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.

3 participants