Skip to content

Commit e5b1b18

Browse files
committed
add rid logic
1 parent 31c4d0c commit e5b1b18

2 files changed

Lines changed: 40 additions & 24 deletions

File tree

Rubjerg.Graphviz/GraphvizCommand.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Reflection;
55
using System.Text;
6+
using System.Runtime.InteropServices;
67

78
namespace Rubjerg.Graphviz;
89

@@ -11,6 +12,27 @@ namespace Rubjerg.Graphviz;
1112
/// </summary>
1213
public class GraphvizCommand
1314
{
15+
internal static string Rid
16+
{
17+
get
18+
{
19+
var os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win"
20+
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx"
21+
: "linux"; // default
22+
23+
var arch = RuntimeInformation.ProcessArchitecture switch
24+
{
25+
Architecture.X64 => "x64",
26+
Architecture.Arm64 => "arm64",
27+
Architecture.X86 => "x86",
28+
Architecture.Arm => "arm",
29+
_ => "unknown"
30+
};
31+
32+
return $"{os}-{arch}";
33+
}
34+
}
35+
1436
public static RootGraph CreateLayout(Graph input, string engine = LayoutEngines.Dot, CoordinateSystem coordinateSystem = CoordinateSystem.BottomLeft)
1537
{
1638
var (stdout, stderr) = Exec(input, engine: engine);
@@ -34,7 +56,7 @@ public static string ConvertBytesOutputToString(byte[] data)
3456
/// <returns>stderr may contain warnings, stdout is in utf8 encoding</returns>
3557
public static (byte[] stdout, string stderr) Exec(Graph input, string format = "xdot", string? outputPath = null, string engine = LayoutEngines.Dot)
3658
{
37-
string exeName = "dot";
59+
var exeName = Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot");
3860
string arguments = $"-T{format} -K{engine}";
3961
if (outputPath != null)
4062
{

Rubjerg.Graphviz/Rubjerg.Graphviz.csproj

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
<RepositoryUrl>https://github.com/Rubjerg/Graphviz.NetWrapper</RepositoryUrl>
2828
<PackageProjectUrl>https://github.com/Rubjerg/Graphviz.NetWrapper</PackageProjectUrl>
2929
<PackageLicenseFile>LICENSE</PackageLicenseFile>
30+
31+
<Rid Condition=" '$(OS)' == 'Windows_NT' ">win-x64</Rid>
32+
<Rid Condition=" '$(OS)' != 'Windows_NT' ">linux-x64</Rid>
3033
</PropertyGroup>
3134

32-
<!-- Platform‑specific compilation constant for Windows code paths -->
33-
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
34-
<DefineConstants>_WINDOWS</DefineConstants>
35-
</PropertyGroup>
35+
<ItemGroup>
36+
<None Include="..\LICENSE">
37+
<Pack>true</Pack>
38+
<PackagePath></PackagePath>
39+
</None>
40+
</ItemGroup>
3641

3742
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3843
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -44,34 +49,23 @@
4449
</ProjectReference>
4550
</ItemGroup>
4651

47-
<!--
48-
***** Native assets *****
49-
All files under Resources/ are copied to bin/ at build time *and* packed into
50-
runtimes/<rid>/native so consumers only get the bits for their platform.
51-
-->
52+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
53+
<DefineConstants>_WINDOWS</DefineConstants>
54+
</PropertyGroup>
5255

5356
<ItemGroup>
54-
<!-- Top‑level executables / libraries -->
5557
<None Include="Resources/*" Exclude="Resources/graphviz/**">
5658
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
57-
<Link>%(RecursiveDir)/%(Filename)%(Extension)</Link>
59+
<TargetPath>runtimes/$(Rid)/native/%(Filename)%(Extension)</TargetPath>
5860
<Pack>true</Pack>
59-
<PackagePath>runtimes/linux-x64/native/</PackagePath>
61+
<PackagePath>runtimes/$(Rid)/native/</PackagePath>
6062
</None>
61-
<!-- Graphviz plug‑ins & sub‑folder -->
63+
6264
<None Include="Resources/graphviz/**">
6365
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64-
<Link>%(RecursiveDir)/graphviz/%(Filename)%(Extension)</Link>
65-
<Pack>true</Pack>
66-
<PackagePath>runtimes/linux-x64/native/graphviz/%(RecursiveDir)</PackagePath>
67-
</None>
68-
</ItemGroup>
69-
70-
<!-- Shared assets such as the licence file -->
71-
<ItemGroup>
72-
<None Include="..\LICENSE">
66+
<TargetPath>runtimes/$(Rid)/native/graphviz/%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
7367
<Pack>true</Pack>
74-
<PackagePath></PackagePath>
68+
<PackagePath>runtimes/$(Rid)/native/graphviz/%(RecursiveDir)</PackagePath>
7569
</None>
7670
</ItemGroup>
7771

0 commit comments

Comments
 (0)