Skip to content

Remove extraneous dependencies from libclangDependencyScanning to fix regression in clangd size #10173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

benlangmuir
Copy link

  • Explanation: After clangd added support for c++ modules, its binary size doubled unnecessarily due to extraneous dependencies on clang's codegen and llvm target libraries that were present in clang's dep scanner. The changes here remove those dependencies, with a small refactoring to split the ObjectFilePCHContainer reader (needed) from the writer (not needed by the scanner). This fixes the regression, reducing clangd size by ~half.
  • Scope: Change should be NFC. If something has gone wrong, it will affect the dependency scanner and/or clangd.
  • Risk: Low. This is a straightforward refactoring. The most likely risk would be at build time that we were accidentally depending on one of these transitive dependencies and it fails to link, but I have spot checked users of this library and they look okay and no build failures have been observed with BUILD_SHARED_LIBS=1.
  • Tests: clangd size checkd manually, existing tests pass
  • Issues: rdar://144790713
  • Original PRs: [clang] Split ObjectFilePCHContainerReader from ObjectFilePCHContainerWriter llvm/llvm-project#99599 and [clang][deps] Remove dependency on llvm targets from lib DependencyScanning llvm/llvm-project#129774
  • Reviewers: @benlangmuir and @jansvoboda11 for the first PR, @jansvoboda11 and @Bigcheese for the latter one.

ChuanqiXu9 and others added 3 commits March 5, 2025 10:42
…rWriter (llvm#99599)

Close llvm#99479

See llvm#99479 for details

(cherry picked from commit d64eccf)

 Conflicts:
	clang/lib/Tooling/DependencyScanning/CMakeLists.txt
	clang/tools/c-index-test/CMakeLists.txt
	clang/tools/c-index-test/core_main.cpp
	clang/tools/driver/cc1_main.cpp

(cherry picked from commit 756acd5)
…anning (llvm#129774)

In d64eccf we split the object file reader from the writer and removed
the dependency on clangCodeGen from the dependency scanner. However, we
were still initializing all the llvm targets, which was needed for
writing object file pcms but not reading them. This caused us to link
more llvm target code than necessary. Shrinks clangd by nearly 50% for
me.

rdar://144790713
(cherry picked from commit f8ba0df)
(cherry picked from commit c0eb45d)
@benlangmuir
Copy link
Author

swiftlang/swift#79803

@swift-ci please test

@benlangmuir
Copy link
Author

@swift-ci please test llvm

@benlangmuir
Copy link
Author

swiftlang/swift#79803

@swift-ci please test Windows

@fredriss fredriss merged commit b3bb7aa into swiftlang:swift/release/6.1 Mar 6, 2025
5 checks passed
@benlangmuir benlangmuir deleted the cherry-pick-144790713-6.1 branch March 6, 2025 18:29
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.

4 participants