From 798d7731eca286df456bc2ec56c0695ba006b472 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 26 Jan 2021 12:15:08 -0500 Subject: Improved NVRTC location finding (#1674) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP more sophisticated mechanism to find NVRTC. * Improve nvrtc searching to include PATH. * Make getting an extension able to differentiate between no extension, and just a . * Add comment. * Add support for searching instance path. * Small improvements around scope and finding NVRTC. * Improve documentation around NVRTC loading. --- source/core/slang-platform.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source/core/slang-platform.cpp') diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index 10b9b576b..20dfed5a8 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -66,6 +66,19 @@ SLANG_COMPILE_TIME_ASSERT(E_NOTIMPL == SLANG_E_NOT_IMPLEMENTED); SLANG_COMPILE_TIME_ASSERT(E_INVALIDARG == SLANG_E_INVALID_ARG); SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); +/* static */SlangResult PlatformUtil::getInstancePath(StringBuilder& out) +{ + wchar_t path[_MAX_PATH]; + ::GetModuleFileName(::GetModuleHandle(NULL), path, SLANG_COUNT_OF(path)); + String pathString = String::fromWString(path); + + // We don't want the instance name, just the path to it + out.Clear(); + out.append(Path::getParentDirectory(pathString)); + + return out.getLength() > 0 ? SLANG_OK : SLANG_FAIL; +} + /* static */SlangResult PlatformUtil::appendResult(SlangResult res, StringBuilder& builderOut) { if (SLANG_FAILED(res) && res != SLANG_FAIL) @@ -142,6 +155,13 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); #else // _WIN32 +/* static */SlangResult PlatformUtil::getInstancePath(StringBuilder& out) +{ + // On non Windows it's typically hard to get the instance path, so we'll say not implemented. + // The meaning is also somewhat more ambiguous - is it the exe or the shared library path? + return SLANG_E_NOT_IMPLEMENTED; +} + /* static */SlangResult PlatformUtil::appendResult(SlangResult res, StringBuilder& builderOut) { return SLANG_E_NOT_IMPLEMENTED; @@ -260,4 +280,6 @@ static const PlatformFlags s_familyFlags[int(PlatformFamily::CountOf)] = return s_familyFlags[int(family)]; } + + } -- cgit v1.2.3