summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-26 12:43:28 -0400
committerGitHub <noreply@github.com>2022-04-26 12:43:28 -0400
commitf9432467cac85eae6f7120cd94208f3a3dd9aa19 (patch)
tree1370c70a0159a1f8dd89cc8c86db930f556bdc5d /source/compiler-core/slang-artifact.cpp
parent79dd12c21e8f5c5ce01051a280679cf6ac8ffe97 (diff)
Improvements around Artifacts (#2192)
* #include an absolute path didn't work - because paths were taken to always be relative. * Compile to a dxil library. * Added CompileProduct. * Support handling of ModuleLibrary. * CacheBehavior -> Cache * Use CompileProduct for -r references. * CompileProduct -> Artifact. * Determining an artifact type on binding. * Determine binary linkability. * Added Artifact::exists. * Added ArtifactKeep. * Small fixes. * Small improvements to Artifact. * Add zip extension. * Fix some comments. * Fix multiple adding of PublicDecoration. Make public output export for DXIL/lib. Add checking for simpleDecorations such that only added once. * Use 'whole program' to identify library build. * Move slang-artifact into compiler-core. * Split out Keep free functions. * Artifact::Keep -> ArtifactKeep. * Handle libraries as artifacts. * Add -target dxil so test infrastructure knows it needs DXC. * Linking working in DXC. * Improve handling around emit for 'export'. * Add comment around Artifact name. * Render test working with linking. * Improvements around Artifact handling.
Diffstat (limited to 'source/compiler-core/slang-artifact.cpp')
-rw-r--r--source/compiler-core/slang-artifact.cpp103
1 files changed, 98 insertions, 5 deletions
diff --git a/source/compiler-core/slang-artifact.cpp b/source/compiler-core/slang-artifact.cpp
index 5d9f8692c..1f11c31df 100644
--- a/source/compiler-core/slang-artifact.cpp
+++ b/source/compiler-core/slang-artifact.cpp
@@ -364,11 +364,88 @@ ISlangUnknown* Artifact::findInterfaceInstance(const Guid& guid)
return nullptr;
}
-SlangResult Artifact::requireFilePath(Keep keep, String& outFilePath)
+/* static */String Artifact::getBaseNameFromPath(Desc& desc, const UnownedStringSlice& path)
+{
+ String name = Path::getFileName(path);
+
+ const bool isSharedLibraryPrefixPlatform = SLANG_LINUX_FAMILY || SLANG_APPLE_FAMILY;
+ if (isSharedLibraryPrefixPlatform)
+ {
+ // Strip lib prefix
+ if (desc.isCpuBinary() &&
+ (desc.kind == ArtifactKind::Library ||
+ desc.kind == ArtifactKind::SharedLibrary))
+ {
+ // If it starts with lib strip it
+ if (name.startsWith("lib"))
+ {
+ const String stripLib = name.getUnownedSlice().tail(3);
+ name = stripLib;
+ }
+ }
+ }
+
+ // Strip any extension
+ {
+ auto descExt = desc.getDefaultExtension();
+ // Strip the extension if it's a match
+ if (descExt.getLength() &&
+ Path::getPathExt(name) == descExt)
+ {
+ name = Path::getFileNameWithoutExt(name);
+ }
+ }
+
+ return name;
+}
+
+String Artifact::getBaseName()
+{
+ if (m_pathType != PathType::None)
+ {
+ return getBaseNameFromPath(m_desc, m_path.getUnownedSlice());
+ }
+ return m_name;
+}
+
+String Artifact::getParentPath()
+{
+ if (m_pathType != PathType::None && m_path.getLength())
+ {
+ return Path::getParentDirectory(m_path);
+ }
+ return String();
+}
+
+SlangResult Artifact::requireFileLike(Keep keep)
+{
+ // If there is no path set and no blob we still need a name.
+ // If the artifact is a library we can assume it's a system level library,
+ // or it can be found by appropriate search paths.
+ if (m_pathType == PathType::None &&
+ m_blob == nullptr &&
+ (m_desc.kind == ArtifactKind::Library ||
+ m_desc.kind == ArtifactKind::SharedLibrary))
+ {
+ if (m_name.getLength() > 0)
+ {
+ return SLANG_OK;
+ }
+
+ // TODO(JS): If we could serialize, we could turn some other representation into a file, and therefore
+ // a name, but currently that's not supported
+ return SLANG_E_NOT_FOUND;
+ }
+
+ // Will turn into a file if necessary
+ SLANG_RETURN_ON_FAIL(requireFile(keep));
+ return SLANG_OK;
+}
+
+SlangResult Artifact::requireFile(Keep keep)
{
if (m_pathType != PathType::None)
{
- outFilePath = m_path;
return SLANG_OK;
}
@@ -377,15 +454,28 @@ SlangResult Artifact::requireFilePath(Keep keep, String& outFilePath)
// Get the contents as a blob. If we can't do that, then we can't write anything...
SLANG_RETURN_ON_FAIL(loadBlob(getIntermediateKeep(keep), blob));
- const UnownedStringSlice ext = m_desc.getDefaultExtension();
+ // If we have a name, make the generated name based on that name
+ // Else just use 'slang-generated' the basis
+
+ UnownedStringSlice nameBase;
+ if (m_name.getLength() > 0)
+ {
+ nameBase = m_name.getUnownedSlice();
+ }
+ else
+ {
+ nameBase = UnownedStringSlice::fromLiteral("slang-generated");
+ }
// TODO(JS): NOTE! This isn't strictly correct, as the generated filename is not guarenteed to be unique
// if we change it with an extension (or prefix).
// This doesn't change the previous behavior though.
String path;
- SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), path));
+ SLANG_RETURN_ON_FAIL(File::generateTemporary(nameBase, path));
- if (m_desc.isCpuBinary() && m_desc.kind == ArtifactKind::SharedLibrary)
+ if (m_desc.isCpuBinary() &&
+ (m_desc.kind == ArtifactKind::SharedLibrary ||
+ m_desc.kind == ArtifactKind::Library))
{
const bool isSharedLibraryPrefixPlatform = SLANG_LINUX_FAMILY || SLANG_APPLE_FAMILY;
if (isSharedLibraryPrefixPlatform)
@@ -409,6 +499,9 @@ SlangResult Artifact::requireFilePath(Keep keep, String& outFilePath)
}
// If there is an extension append it
+
+ const UnownedStringSlice ext = m_desc.getDefaultExtension();
+
if (ext.getLength())
{
path.appendChar('.');