From 7a942cfdc338d199b8e775d16b0b9b49699363d7 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 12 Mar 2025 09:55:19 +0200 Subject: Add referenced modules as libraries when creating a session (#6569) In the legacy compile request based API, the referenced modules are added to the request's linkage libraries as part of compiler option parsing. In the non-legacy compilation API, the argument parsing creates a temprary compile request and so those libraries only survive as options. This change will look for such options when creating an ISession object, and again add the referenced modules to the libraries of the new linkage that's contained in the ISession object. This is done in two steps: 1. Factor out a helper to create a referenced module artifact in the same way as it's done during legacy option parsing. 2. Use the helper function to create artifacts to add to the linkage libararies, when the session is created. This helps to address issue #4760, because it enables passing in downstream modules via options, as is required for the following tests: tests/library/library-test.slang.2 (dx12) tests/library/export-test.slang.2 (dx12) --- source/slang/slang.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 8dfaf115e..18368b33b 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -861,6 +861,29 @@ Session::createSession(slang::SessionDesc const& inDesc, slang::ISession** outSe Math::Max(linkageDebugInfoLevel, target->getOptionSet().getDebugInfoLevel()); linkage->m_optionSet.set(CompilerOptionName::DebugInformation, linkageDebugInfoLevel); + // Add any referenced modules to the linkage + for (auto& option : linkage->m_optionSet.options) + { + if (option.key != CompilerOptionName::ReferenceModule) + continue; + for (auto& path : option.value) + { + DiagnosticSink sink; + ComPtr artifact; + SlangResult result = createArtifactFromReferencedModule( + path.stringValue, + SourceLoc{}, + &sink, + artifact.writeRef()); + if (SLANG_FAILED(result)) + { + sink.diagnose(SourceLoc{}, Diagnostics::unableToReadFile, path.stringValue); + return result; + } + linkage->m_libModules.add(artifact); + } + } + *outSession = asExternal(linkage.detach()); return SLANG_OK; } -- cgit v1.2.3