Skip to content

[llvm] Fix resource path when building tools#16294

Merged
strega-nil merged 2 commits intomicrosoft:masterfrom
JackBoosY:dev/jack/16284
Feb 22, 2021
Merged

[llvm] Fix resource path when building tools#16294
strega-nil merged 2 commits intomicrosoft:masterfrom
JackBoosY:dev/jack/16284

Conversation

@JackBoosY
Copy link
Copy Markdown
Contributor

Default resource directory for clang is constructed relative to the location of the clang executable:

From clang/lib/Driver/Driver.cpp:

std::string Driver::GetResourcesPath(StringRef BinaryPath,
                                     StringRef CustomResourceDir) {
...
  // Dir is bin/ or lib/, depending on where BinaryPath is.
  std::string Dir = llvm::sys::path::parent_path(BinaryPath);
...
    P = llvm::sys::path::parent_path(Dir);
    llvm::sys::path::append(P, Twine("lib") + CLANG_LIBDIR_SUFFIX, "clang",
                            CLANG_VERSION_STRING);
...
}

Vcpkg moves clang to tools/llvm adding a subdirectory. As a result the above code produces tools/lib/clang/11.0.0 which does not exist. Clang is therefore unable to find header files under lib/clang/11.0.0.

From clang/lib/Driver/ToolChains/Clang.cpp:

  // Pass the path to compiler resource files.
  CmdArgs.push_back("-resource-dir");
  CmdArgs.push_back(D.ResourceDir.c_str());

I have worked around the problem by adding this to my ports/llvm/portfile.cmake

list(APPEND FEATURE_OPTIONS
     -DCLANG_RESOURCE_DIR=../../lib/clang/11.0.0
)

Fix this.

Fixes #16284.

@JackBoosY JackBoosY added category:port-bug The issue is with a library, which is something the port should already support info:internal labels Feb 19, 2021
@JackBoosY
Copy link
Copy Markdown
Contributor Author

Hi @mcurtis-cadence, does this changes meet your requirement?

@PhoebeHui
Copy link
Copy Markdown
Contributor

cc @yurybura

@mcurtis-cadence
Copy link
Copy Markdown

@JackBoosY

does this changes meet your requirement?

Yes, that works for me.
Thanks!

Copy link
Copy Markdown
Contributor

@PhoebeHui PhoebeHui left a comment

Choose a reason for hiding this comment

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

LGTM, @strega-nil, could you help futher review?

@PhoebeHui PhoebeHui requested a review from strega-nil February 22, 2021 09:52
@strega-nil strega-nil merged commit 319b8f0 into microsoft:master Feb 22, 2021
Jimmy-Hu added a commit to Jimmy-Hu/vcpkg that referenced this pull request Feb 23, 2021
[llvm] Fix resource path when building tools (microsoft#16294)
@JackBoosY JackBoosY deleted the dev/jack/16284 branch February 23, 2021 01:27
sthagen added a commit to sthagen/microsoft-vcpkg that referenced this pull request Feb 23, 2021
[llvm] Fix resource path when building tools (microsoft#16294)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:port-bug The issue is with a library, which is something the port should already support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[llvm] default clang resource dir is incorrect

4 participants