This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Remove extra dependancies for clangd
ClosedPublic

Authored by saghir on Jul 17 2023, 7:59 PM.

Details

Summary

This patch removes dependancies for clangd that were duplicated in
915659bfa1e9fe2e2c748ac84d33881e248f9ad5.
The original patch was added to fix build failure with BUILD_SHARED_LIBS=ON.

Diff Detail

Event Timeline

saghir created this revision.Jul 17 2023, 7:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 8:00 PM
saghir requested review of this revision.Jul 17 2023, 8:00 PM
saghir retitled this revision from [clangd] Move dependancies for clangd to [clangd] Remove extra dependancies for clangd.
saghir edited the summary of this revision. (Show Details)
saghir added reviewers: nemanjai, mstorsjo, ivanmurashko.
saghir edited the summary of this revision. (Show Details)Jul 17 2023, 8:02 PM
mstorsjo added a subscriber: sammccall.

Thanks for looking at my suggestion! At this point, I'd defer the judgement to the code owner, @sammccall - whether it's nicer to have a tighter set of dependencies, or to reduce the risk of churn and accidentally breaking the shared libs build again.

sammccall accepted this revision.Jul 21 2023, 1:49 PM

I don't have a strong opinion here (or solid understanding of dynamic linking!)

I suppose the idea is that clangdMain has dependencies from the source files in this directory, and the clangd binary has dependencies from the tweaks that we link in as object files.
This seems reasonable but also fragile - I honestly don't see a good workflow to understand exactly which deps are necessary and when this changes other than watching for failure reports on various platforms. (The static build is much simpler in this regard)

So I can see an argument (though not really the practical benefit) for minimizing the set of deps now to be more correct, and also an argument for having all targets depend on everything to minimize churn. Up to you.

This revision is now accepted and ready to land.Jul 21 2023, 1:49 PM
saghir added a comment.EditedJul 21 2023, 3:49 PM

Thank you for the review and your comments @sammccall and @mstorsjo. As I understand there is no strong opinion here either way. I think we can leave things as they are for now. I am going to abandon this patch. If someone else feels strongly about removing them, they can put up a patch for this.

llvm/cmake/modules/HandleLLVMOptions.cmake passes -Wl,-z,defs. -DBUILD_SHARED_LIBS=on builds get checking from the linker option (https://maskray.me/blog/2021-06-13-dependency-related-linker-options#z-defs). This is similar Bazel's layering_check.

For a dependency, say, clangTooling, if a source file within the clangd target (executable) uses (directly or transitively) clangTooling, the dependency should be kept, otherwise it should be removed.
If the source files are completely IWYU clean, it should be straightforward to tell whether a dependency can be removed by inspecting the #include lines.

sammccall added a comment.EditedJul 21 2023, 4:54 PM

llvm/cmake/modules/HandleLLVMOptions.cmake passes -Wl,-z,defs. -DBUILD_SHARED_LIBS=on builds get checking from the linker option (https://maskray.me/blog/2021-06-13-dependency-related-linker-options#z-defs). This is similar Bazel's layering_check.

Thanks! This is good to know - it seems like this means when things break I can repro locally and should get the same results, if I anticipate a breakage I can test for it. I can't easily tell if I have *too many* deps, but that's probably not an urgent problem.

For a dependency, say, clangTooling, if a source file within the clangd target (executable) uses (directly or transitively) clangTooling, the dependency should be kept, otherwise it should be removed.
If the source files are completely IWYU clean, it should be straightforward to tell whether a dependency can be removed by inspecting the #include lines.

I'm not sure this is the case:

// clangdMain.cpp
#include "clangDaemon.h"
int result = clangDaemonThings();

// clangDaemon.h
#include "Tooling.h"
inline int clangDaemonThings() { tooling::doStuff(); }

IIUC if the call to clangDaemonThings gets inlined, now clangdMain has to be linked against Tooling, despite being IWYU-clean and not including any of its headers.

(This would be unlike bazel, which doesn't require cc_library(name="clangdMain", deps=["clangTooling"]) in that case, maybe I'm misunderstanding though...)

llvm/cmake/modules/HandleLLVMOptions.cmake passes -Wl,-z,defs. -DBUILD_SHARED_LIBS=on builds get checking from the linker option (https://maskray.me/blog/2021-06-13-dependency-related-linker-options#z-defs). This is similar Bazel's layering_check.

Thanks! This is good to know - it seems like this means when things break I can repro locally and should get the same results, if I anticipate a breakage I can test for it. I can't easily tell if I have *too many* deps, but that's probably not an urgent problem.

For a dependency, say, clangTooling, if a source file within the clangd target (executable) uses (directly or transitively) clangTooling, the dependency should be kept, otherwise it should be removed.
If the source files are completely IWYU clean, it should be straightforward to tell whether a dependency can be removed by inspecting the #include lines.

I'm not sure this is the case:

// clangdMain.cpp
#include "clangDaemon.h"
int result = clangDaemonThings();

// clangDaemon.h
#include "Tooling.h"
inline int clangDaemonThings() { tooling::doStuff(); }

IIUC if the call to clangDaemonThings gets inlined, now clangdMain has to be linked against Tooling, despite being IWYU-clean and not including any of its headers.

(This would be unlike bazel, which doesn't require cc_library(name="clangdMain", deps=["clangTooling"]) in that case, maybe I'm misunderstanding though...)

You are right! This is unlike Bazel...

lei added a subscriber: lei.Aug 9 2023, 2:52 PM

I was thinking to commit this patch to minimize the dependencies if there are no objections. @MaskRay @nemanjai any preferences?

I was thinking to commit this patch to minimize the dependencies if there are no objections. @MaskRay @nemanjai any preferences?

LGTM. Please commit it.

lei updated this revision to Diff 549374.Aug 11 2023, 6:56 AM

Rebase to ToT

This revision was landed with ongoing or failed builds.Aug 11 2023, 6:57 AM
This revision was automatically updated to reflect the committed changes.