diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-06-08 10:23:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-08 10:23:01 -0400 |
| commit | 8e6e884eca5b33218a8cb2714266fb6ed4548d75 (patch) | |
| tree | a9c8aee79a71450a64e6660da7266b6a45da0264 /source/compiler-core | |
| parent | 01d0154ae90f5c587321d39b8fd8f82e2764f360 (diff) | |
Actual global support (#2262)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Use TerminatedUnownedStringSlice for literals in output C++.
* Remove Escape/Unescape functions used in slang-token-reader.cpp
Add target type of 'host-cpp' etc to map to the target types.
* Fix some corner cases around string encoding.
* Added unit test for string escaping.
Fixed some assorted escaping bugs.
* Updated test output.
* Added decode test.
* Stop using hex output, to get around 'greedy' aspect. Use octal instead.
* Added HostHostCallable
Small changes to use ArtifactDesc/Info instead of large switches.
* Fix C++ emit to handle arbitrary function export.
* Add options handling for callable without an output being specified.
* Can compile with COM interface. Added example using com interface.
* Use the IR Ptr type instead of hack in C++ emit for interfaces.
* Fix issue with outputting the COM call when ptr is used.
* Fix crash issue on compilation failure.
* Add support for __global.
* Added `ActualGlobalRate`
Added special handling around globals and COM interfaces.
Tested out in cpu-com-example.
* Fix typo in NodeBase.
* Support for accessing globals by name working.
* Check that actual global initialization is working.
* Refactor the com replacement such that it doesn't need a cache or do anything special with GlobalVar.
* Remove context.
Only create replacement if needed.
* Split out COM host-callable into a unit-test.
* host-callable com testing on C++and llvm.
* Comment around the COM ptr replacement.
* Disable com test on vs 32 bit.
Fix C++ prelude
* Disable 32 bit targets testing com host-callable.
* Use JSON parsing to locate VS version.
* Need platform detection in C++prelude.
* Fix com host callable test for LLVM.
* Work around for not being able to include "targetConditionals.h"
Diffstat (limited to 'source/compiler-core')
| -rw-r--r-- | source/compiler-core/windows/slang-win-visual-studio-util.cpp | 134 |
1 files changed, 112 insertions, 22 deletions
diff --git a/source/compiler-core/windows/slang-win-visual-studio-util.cpp b/source/compiler-core/windows/slang-win-visual-studio-util.cpp index e1a0f6109..9b175f308 100644 --- a/source/compiler-core/windows/slang-win-visual-studio-util.cpp +++ b/source/compiler-core/windows/slang-win-visual-studio-util.cpp @@ -4,6 +4,9 @@ #include "../../core/slang-process-util.h" #include "../../core/slang-string-util.h" +#include "../slang-json-parser.h" +#include "../slang-json-value.h" + #include "../slang-visual-studio-compiler-util.h" #ifdef _WIN32 @@ -82,6 +85,7 @@ VersionInfo _makeVersionInfo(const char* name, int high, int dot = 0) return info; } +// https://en.wikipedia.org/wiki/Microsoft_Visual_Studio static const VersionInfo s_versionInfos[] = { _makeVersionInfo("VS 2005", 8), @@ -92,6 +96,7 @@ static const VersionInfo s_versionInfos[] = _makeVersionInfo("VS 2015", 14), _makeVersionInfo("VS 2017", 15), _makeVersionInfo("VS 2019", 16), + _makeVersionInfo("VS 2022", 17), }; // When trying to figure out how this stuff works by running regedit - care is needed, @@ -135,7 +140,7 @@ static int _getRegistryKeyIndex(Version version) /* static */WinVisualStudioUtil::Version WinVisualStudioUtil::getCompiledVersion() { // Get the version of visual studio used to compile this source - const uint32_t version = _MSC_VER; + uint32_t version = _MSC_VER; switch (version) { @@ -156,27 +161,51 @@ static int _getRegistryKeyIndex(Version version) case 1916: { return _makeVersion(15); - } - case 1920: - { - return _makeVersion(16); - } - default: - { - int lastKnownVersion = 1920; - if (version > lastKnownVersion) - { - // Its an unknown newer version - return Version::Future; - } - break; - } + } + default: break; + } + + // Seems like versions go in runs of 10 at this point + // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170 + + if (version >= 1920 && version < 1930) + { + return _makeVersion(16); + } + else if (version >= 1930 && version < 1940) + { + // We are going to assume it's a run of t0 + return _makeVersion(17); + } + else if (version >= 1940) + { + // Its an unknown newer version + return Version::Future; } // Unknown version return Version::Unknown; } +static SlangResult _parseJson(const String& contents, DiagnosticSink* sink, JSONContainer* container, JSONValue& outRoot) +{ + auto sourceManager = sink->getSourceManager(); + + SourceFile* sourceFile = sourceManager->createSourceFileWithString(PathInfo::makeUnknown(), contents); + SourceView* sourceView = sourceManager->createSourceView(sourceFile, nullptr, SourceLoc()); + + JSONLexer lexer; + lexer.init(sourceView, sink); + + JSONBuilder builder(container); + + JSONParser parser; + SLANG_RETURN_ON_FAIL(parser.parse(&lexer, sourceView, &builder, sink)); + + outRoot = builder.getRootValue(); + return SLANG_OK; +} + static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& outPath) { const auto& versionInfo = s_versionInfos[versionIndex]; @@ -202,22 +231,83 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out cmd.setExecutableLocation(ExecutableLocation(vswherePath)); + const auto desc = WinVisualStudioUtil::getDesc(version); + StringBuilder versionName; WinVisualStudioUtil::append(version, versionName); - String args[] = { "-version", versionName, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath" }; + // Using -? we can find out vswhere options. + + // Previous args - works but returns multiple versions, without listing what version is associated with which path + // or the order. + //String args[] = { "-version", versionName, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-json", "-property", "installationPath", "-property", "installationVersion" }; + + // Use JSON parsing, we can verify the versions for a path, otherwise multiple versions are returned + // not just the version specified. The ordering isn't defined (and -sort doesn't appear to work) + String args[] = { "-version", versionName, "-format", "json", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"}; + cmd.addArgs(args, SLANG_COUNT_OF(args)); + SourceManager sourceManager; + sourceManager.initialize(nullptr, nullptr); + DiagnosticSink sink(&sourceManager, nullptr); + + RefPtr<JSONContainer> container = new JSONContainer(&sourceManager); + ExecuteResult exeRes; if (SLANG_SUCCEEDED(ProcessUtil::execute(cmd, exeRes))) { - // We need to chopoff CR/LF if there is one - List<UnownedStringSlice> lines; - StringUtil::calcLines(exeRes.standardOutput.getUnownedSlice(), lines); + JSONValue jsonRoot; + SLANG_RETURN_ON_FAIL(_parseJson(exeRes.standardOutput, &sink, container, jsonRoot)); + + // Search through the array... + if (jsonRoot.getKind() != JSONValue::Kind::Array) + { + return SLANG_FAIL; + } + + auto arr = container->getArray(jsonRoot); + + const auto pathKey = container->getKey(UnownedStringSlice::fromLiteral("installationPath")); + const auto versionKey = container->getKey(UnownedStringSlice::fromLiteral("installationVersion")); - if (lines.getCount()) + for (auto elem : arr) { - outPath.vcvarsPath = lines[0]; + // Get the path and the name + if (elem.getKind() != JSONValue::Kind::Object) + { + continue; + } + + auto pathJsonValue = container->findObjectValue(elem, pathKey); + auto versionJsonValue = container->findObjectValue(elem, versionKey); + + if (!pathJsonValue.isValid() || !versionJsonValue.isValid()) + { + continue; + } + + auto pathString = container->getString(pathJsonValue); + auto versionString = container->getString(versionJsonValue).trim(); + + // If the versionString matches + List<UnownedStringSlice> versionSlices; + StringUtil::split(versionString, '.', versionSlices); + + if (versionSlices.getCount() <= 0) + { + continue; + } + + Int versionValue; + SLANG_RETURN_ON_FAIL(StringUtil::parseInt(versionSlices[0], versionValue)); + + if (versionValue != desc.majorVersion) + { + continue; + } + + outPath.vcvarsPath = pathString; outPath.vcvarsPath.append("\\VC\\Auxiliary\\Build\\"); return SLANG_OK; } |
