Skip to content
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

Enable resource directory for DXC. #6954

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tools/clang/lib/Frontend/InitHeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,12 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
#if 1 // HLSL Change Starts
return;
if (HSOpts.UseBuiltinIncludes) {
SmallString<128> P = StringRef(HSOpts.ResourceDir);
llvm::sys::path::append(P, "include");
AddUnmappedPath(P, Angled, false);
}
return;
#else
// NB: This code path is going away. All of the logic is moving into the
// driver which has the information necessary to do target-specific
Expand Down
6 changes: 6 additions & 0 deletions tools/clang/tools/dxcompiler/dxcfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "dxc/Support/Unicode.h"
#include "dxc/Support/dxcfilesystem.h"
#include "clang/Frontend/CompilerInstance.h"
#include "llvm/Support/Path.h"

#ifndef _WIN32
#include <sys/stat.h>
Expand Down Expand Up @@ -395,6 +396,11 @@ class DxcArgsFileSystemImpl : public DxcArgsFileSystem {
m_searchEntries.emplace_back(std::move(ws));
}
}
if (compiler.getHeaderSearchOpts().UseBuiltinIncludes) {
SmallString<128> P = StringRef(compiler.getHeaderSearchOpts().ResourceDir);
llvm::sys::path::append(P, "include");
m_searchEntries.emplace_back(Unicode::UTF8ToWideStringOrThrow(P.c_str()));
}
}

HRESULT RegisterOutputStream(LPCWSTR pName, IStream *pStream) override {
Expand Down
4 changes: 3 additions & 1 deletion tools/clang/tools/dxcompiler/dxcompilerobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,9 @@ class DxcCompiler : public IDxcCompiler3,

// Pick additional arguments.
clang::HeaderSearchOptions &HSOpts = compiler.getHeaderSearchOpts();
HSOpts.UseBuiltinIncludes = 0;
HSOpts.UseBuiltinIncludes = true;
HSOpts.ResourceDir =
clang::CompilerInvocation::GetResourcesPath("Hoping this is not needed on any of our platforms", nullptr);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have something that "works", but there is a problem. I don't know the right way to pass new information from dxc::main to this point. I don't have the path for the executable from argv[0] available. It is skipped when passing along the argument.

This works on my linux system where GetResourcePath uses /proc/self/exe to get the executable, but I don't know how to set up these parameters to work on other platforms.

Note that we could call GetResourcePath in another place if we determine how to pass the inforamtion along. This just seemed like the best place for now because this is where we are processing the -I options.

// Consider: should we force-include '.' if the source file is relative?
for (const llvm::opt::Arg *A : Opts.Args.filtered(options::OPT_I)) {
const bool IsFrameworkFalse = false;
Expand Down
Loading