diff --git a/.pick_status.json b/.pick_status.json index ca1d1d446b4..a16afeb865d 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -174,7 +174,7 @@ "description": "clc: retrieve libclang path at runtime.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e22491c83265200f518e9fb4deff54e3c2823b68", "notes": null diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index 55287f22683..63026a806ee 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -23,6 +23,7 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +#include #include #include #include @@ -57,6 +58,10 @@ #include "spirv.h" +#if DETECT_OS_UNIX +#include +#endif + #ifdef USE_STATIC_OPENCL_C_H #if LLVM_VERSION_MAJOR < 15 #include "opencl-c.h.h" @@ -876,12 +881,24 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, #endif } #else + + Dl_info info; + if (dladdr((void *)clang::CompilerInvocation::CreateFromArgs, &info) == 0) { + clc_error(logger, "Couldn't find libclang path.\n"); + return {}; + } + + char *clang_path = realpath(info.dli_fname, NULL); + if (clang_path == nullptr) { + clc_error(logger, "Couldn't find libclang path.\n"); + return {}; + } + // GetResourcePath is a way to retrive the actual libclang resource dir based on a given binary - // or library. The path doesn't even need to exist, we just have to put something in there, - // because we might have linked clang statically. - auto libclang_path = fs::path(LLVM_LIB_DIR) / "libclang.so"; + // or library. auto clang_res_path = - fs::path(Driver::GetResourcesPath(libclang_path.string(), CLANG_RESOURCE_DIR)) / "include"; + fs::path(Driver::GetResourcesPath(std::string(clang_path), CLANG_RESOURCE_DIR)) / "include"; + free(clang_path); c->getHeaderSearchOpts().UseBuiltinIncludes = true; c->getHeaderSearchOpts().UseStandardSystemIncludes = true;