Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack DXC native libs with generator #349

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ComputeSharp.Package/ComputeSharp.Package.msbuildproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<!-- Include the custom .targets file to check the source generator -->
<None Include="..\ComputeSharp\ComputeSharp.targets" PackagePath="buildTransitive\ComputeSharp.targets" Pack="true" />
<None Include="..\ComputeSharp\ComputeSharp.targets" PackagePath="build\ComputeSharp.targets" Pack="true" />

<!-- Include the DXC compiler files -->
<None Include="..\ComputeSharp.Dynamic\Libraries\x64\dxcompiler.dll" PackagePath="analyzers\dotnet\cs\Libraries\x64\dxcompiler.dll" Pack="true" />
<None Include="..\ComputeSharp.Dynamic\Libraries\x64\dxil.dll" PackagePath="analyzers\dotnet\cs\Libraries\x64\dxil.dll" Pack="true" />
<None Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxcompiler.dll" PackagePath="analyzers\dotnet\cs\Libraries\arm64\dxcompiler.dll" Pack="true" />
<None Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxil.dll" PackagePath="analyzers\dotnet\cs\Libraries\arm64\dxil.dll" Pack="true" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,22 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\ComputeSharp.Dynamic\Libraries\x64\dxcompiler.dll" Link="ComputeSharp\Libraries\x64\dxcompiler.dll" />
<EmbeddedResource Include="..\ComputeSharp.Dynamic\Libraries\x64\dxil.dll" Link="ComputeSharp\Libraries\x64\dxil.dll" />
<EmbeddedResource Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxcompiler.dll" Link="ComputeSharp\Libraries\arm64\dxcompiler.dll" />
<EmbeddedResource Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxil.dll" Link="ComputeSharp\Libraries\arm64\dxil.dll" />
<None Include="..\ComputeSharp.Dynamic\Libraries\x64\dxcompiler.dll"
Link="Libraries\x64\dxcompiler.dll"
Visible="False"
CopyToOutputDirectory="PreserveNewest" />
<None Include="..\ComputeSharp.Dynamic\Libraries\x64\dxil.dll"
Link="Libraries\x64\dxil.dll"
Visible="False"
CopyToOutputDirectory="PreserveNewest" />
<None Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxcompiler.dll"
Link="Libraries\arm64\dxcompiler.dll"
Visible="False"
CopyToOutputDirectory="PreserveNewest" />
<None Include="..\ComputeSharp.Dynamic\Libraries\arm64\dxil.dll"
Link="Libraries\arm64\dxil.dll"
Visible="False"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<!-- Shared project with common helpers -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,6 @@ private static string FixupExceptionMessage(string message)
/// <exception cref="Win32Exception">Thrown if a library fails to load.</exception>
private static void LoadNativeDxcLibraries()
{
// Extracts a specified native library for a given runtime identifier
static string ExtractLibrary(string folder, string rid, string name)
{
string sourceFilename = $"ComputeSharp.SourceGenerators.ComputeSharp.Libraries.{rid}.{name}.dll";
string targetFilename = Path.Combine(folder, rid, $"{name}.dll");

_ = Directory.CreateDirectory(Path.GetDirectoryName(targetFilename));

using Stream sourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(sourceFilename);

try
{
using Stream destinationStream = File.Open(targetFilename, FileMode.CreateNew, FileAccess.Write);

sourceStream.CopyTo(destinationStream);
}
catch (IOException)
{
}

return targetFilename;
}

// Loads a target native library
static unsafe void LoadLibrary(string filename)
{
Expand All @@ -267,10 +244,10 @@ static unsafe void LoadLibrary(string filename)
_ => throw new NotSupportedException("Invalid process architecture")
};

string folder = Path.Combine(Path.GetTempPath(), "ComputeSharp.SourceGenerators", Path.GetRandomFileName());
string folder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Libraries", rid);

LoadLibrary(ExtractLibrary(folder, rid, "dxil"));
LoadLibrary(ExtractLibrary(folder, rid, "dxcompiler"));
LoadLibrary(Path.Combine(folder, "dxil.dll"));
LoadLibrary(Path.Combine(folder, "dxcompiler.dll"));

areDxcLibrariesLoaded = true;
}
Expand Down