summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-05-01 18:29:39 -0700
committerGitHub <noreply@github.com>2024-05-01 18:29:39 -0700
commit08de73a5da92f722c53ae9ae8fab4139186ffcf8 (patch)
tree2b75e02d87459e2ac4da7d0657c96828be091748
parent9043bc5522cc86560ac5d57ddfc6cfa7612c9222 (diff)
Copy default target's optionSet to code-gen target's optionSet (#4073)
In current implementation, the some options will be to added to the target that is only specified by command line "-target". But if user specifies the target by just using slang API, e.g. 'spAddCodeGenTarget', those options will be missed. To fix the problem, we copy the default target's options to the code-gen target's option set. The default target will only be useful when there is no target specified in the command line.
-rwxr-xr-xsource/slang/slang-compiler.h2
-rw-r--r--source/slang/slang-options.cpp16
-rw-r--r--source/slang/slang.cpp1
3 files changed, 19 insertions, 0 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index cd4e7fdd5..2711da3c9 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -2835,6 +2835,8 @@ namespace Slang
};
Dictionary<TargetRequest*, RefPtr<TargetInfo>> m_targetInfos;
+ CompilerOptionSet m_optionSetForDefaultTarget;
+
CompilerOptionSet& getTargetOptionSet(TargetRequest* req);
CompilerOptionSet& getTargetOptionSet(Index targetIndex);
diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp
index 7337b9210..857f4272c 100644
--- a/source/slang/slang-options.cpp
+++ b/source/slang/slang-options.cpp
@@ -2909,7 +2909,23 @@ SlangResult OptionsParser::_parse(
// Copy all settings from linkage to targets.
for (auto target : linkage->targets)
+ {
target->getOptionSet().inheritFrom(linkage->m_optionSet);
+
+ // If there is no target specified in command line, we should inherit the default target options.
+ if(m_rawTargets.getCount() == 0)
+ {
+ target->getOptionSet().inheritFrom(m_defaultTarget.optionSet);
+ }
+ }
+
+ // If there are no targets specified in command line, and addCodeGenTarget() is not called
+ // yet, the options for the default target will be gone after option parsing. We
+ // should save the option for the future use when addCodeGenTarget() is called.
+ if ((linkage->targets.getCount() == 0) && (m_rawTargets.getCount() == 0))
+ {
+ m_requestImpl->m_optionSetForDefaultTarget = m_defaultTarget.optionSet;
+ }
applySettingsToDiagnosticSink(m_requestImpl->getSink(), m_sink, linkage->m_optionSet);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 5974656df..9b612b340 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -5529,6 +5529,7 @@ void EndToEndCompileRequest::_completeTargetRequest(UInt targetIndex)
TargetRequest* targetRequest = linkage->targets[Index(targetIndex)];
targetRequest->getOptionSet().inheritFrom(getLinkage()->m_optionSet);
+ targetRequest->getOptionSet().inheritFrom(m_optionSetForDefaultTarget);
}
void EndToEndCompileRequest::setCodeGenTarget(SlangCompileTarget target)