Skip to content

Commit 6a411d3

Browse files
authored
Test nonportable build and make it work on windows (#107)
1 parent 5b34630 commit 6a411d3

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: win-build-nonportable
2+
3+
# Controls when the action will run. Triggers the workflow on push or pull request
4+
# events but only for the master branch
5+
6+
on:
7+
push: { branches: [ master ] }
8+
pull_request: { branches: [ master ] }
9+
release: { types: [published] } # runs on “Publish release” button
10+
workflow_dispatch: # lets you run it by hand
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
name: Checkout Code
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup .NET SDK
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: '8.0.x'
25+
26+
- name: Add msbuild to PATH
27+
uses: microsoft/[email protected]
28+
29+
- name: Setup NuGet.exe for use with actions
30+
uses: NuGet/[email protected]
31+
32+
- name: Setup Just
33+
uses: extractions/setup-just@v3
34+
35+
- name: Build and test
36+
run: just test-win-x64

README-src.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ In particular, if you only want to read graphs and run the DOT layout algorithm,
2121
To run our tests successfully you will also need libgts and libpcre2 (for the neato algorithm).
2222
For more details, check the dependencies of any graphviz binaries with `ldd`.
2323

24+
It is currently not possible to use this package on linux in a non-portable application, i.e. an application that targets linux-x64.
25+
The reason for this is that [dotnet flattens the directory structure of native dependencies when targetting a single runtime](https://github.com/dotnet/sdk/issues/9643), and this breaks graphviz.
26+
2427
## Installation
2528

2629
Add the [Rubjerg.Graphviz nuget package](https://www.nuget.org/packages/Rubjerg.Graphviz/) to your project.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ In particular, if you only want to read graphs and run the DOT layout algorithm,
2121
To run our tests successfully you will also need libgts and libpcre2 (for the neato algorithm).
2222
For more details, check the dependencies of any graphviz binaries with `ldd`.
2323

24+
It is currently not possible to use this package on linux in a non-portable application, i.e. an application that targets linux-x64.
25+
The reason for this is that [dotnet flattens the directory structure of native dependencies when targetting a single runtime](https://github.com/dotnet/sdk/issues/9643), and this breaks graphviz.
26+
2427
## Installation
2528

2629
Add the [Rubjerg.Graphviz nuget package](https://www.nuget.org/packages/Rubjerg.Graphviz/) to your project.

Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1010
<LangVersion>latest</LangVersion>
1111
<DebugType>embedded</DebugType>
12+
<!-- Need to list these in order to do a nonportable build -->
13+
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
1214
</PropertyGroup>
1315

1416
<PropertyGroup Condition="'$(Configuration)'=='Release'">

Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1010
<LangVersion>latest</LangVersion>
1111
<DebugType>embedded</DebugType>
12+
<!-- Need to list these in order to do a nonportable build -->
13+
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
1214
</PropertyGroup>
1315

1416
<PropertyGroup Condition="'$(Configuration)'=='Release'">

Rubjerg.Graphviz/GraphvizCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using System.Text;
66
using System.Runtime.InteropServices;
7+
using System.Linq;
78

89
namespace Rubjerg.Graphviz;
910

@@ -33,6 +34,16 @@ internal static string Rid
3334
}
3435
}
3536

37+
internal static Lazy<string> _DotExePath = new Lazy<string>(() =>
38+
// If graphviz is not found in the runtimes folder, look in the current directory for compatibility with nonportable windows builds.
39+
new string[] {
40+
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot"),
41+
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot.exe"),
42+
"dot",
43+
"dot.exe"
44+
}.FirstOrDefault(File.Exists));
45+
internal static string DotExePath => _DotExePath.Value;
46+
3647
public static RootGraph CreateLayout(Graph input, string engine = LayoutEngines.Dot, CoordinateSystem coordinateSystem = CoordinateSystem.BottomLeft)
3748
{
3849
var (stdout, stderr) = Exec(input, engine: engine);
@@ -56,7 +67,6 @@ public static string ConvertBytesOutputToString(byte[] data)
5667
/// <returns>stderr may contain warnings, stdout is in utf8 encoding</returns>
5768
public static (byte[] stdout, string stderr) Exec(Graph input, string format = "xdot", string? outputPath = null, string engine = LayoutEngines.Dot)
5869
{
59-
var exeName = Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot");
6070
string arguments = $"-T{format} -K{engine}";
6171
if (outputPath != null)
6272
{
@@ -71,7 +81,7 @@ public static (byte[] stdout, string stderr) Exec(Graph input, string format = "
7181
?? Path.GetDirectoryName(System.AppContext.BaseDirectory);
7282

7383
// Construct the path to the executable
74-
string exePath = Path.Combine(exeDirectory, exeName);
84+
string exePath = Path.Combine(exeDirectory, DotExePath);
7585

7686
Process process = new Process();
7787

justfile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ build SOLUTION:
1919
dotnet build {{SOLUTION}} --configuration Release --no-restore; \
2020
fi
2121

22+
build-rid SOLUTION RID:
23+
dotnet build {{SOLUTION}} --configuration Release --no-restore -r {{RID}};
24+
2225
# Build nuget package
2326
build-package: restore
2427
just build Rubjerg.Graphviz.sln
@@ -32,9 +35,9 @@ build-tests: restore-tests
3235
just build Rubjerg.Graphviz.Tests.sln
3336

3437
# Run unit tests for a project
35-
test PROJECT:
38+
test PROJECT OUTPUT_PATH='bin/x64/Release/net8.0/':
3639
dotnet test --no-build \
37-
-p:OutputPath=bin/x64/Release/net8.0 \
40+
-p:OutputPath={{OUTPUT_PATH}} \
3841
-c Release \
3942
-f net8.0 \
4043
-v d \
@@ -54,6 +57,13 @@ test-nugetorg:
5457
just test NugetOrgTests/Rubjerg.Graphviz.NugetOrgTest/Rubjerg.Graphviz.NugetOrgTest.csproj
5558
just test NugetOrgTests/Rubjerg.Graphviz.NugetOrgTransitiveTest/Rubjerg.Graphviz.NugetOrgTransitiveTest.csproj
5659

60+
# Build and test nonportable win-x64 deployment
61+
test-win-x64: restore-tests
62+
dotnet build Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj --configuration Release --no-restore -r win-x64;
63+
dotnet build Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj --configuration Release --no-restore -r win-x64;
64+
just test Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj bin/Release/net8.0/win-x64/
65+
just test Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj bin/Release/net8.0/win-x64/
66+
5767
locate-nupkg GITHUB_OUTPUT:
5868
echo "package=$(find . -name "Rubjerg.Graphviz.*.nupkg" | head -1)" >> "{{GITHUB_OUTPUT}}"
5969

@@ -70,7 +80,7 @@ normalize:
7080
bash -c "git ls-files -- ':!GraphvizWrapper/graphvizfiles/*' ':!*.sh' | xargs unix2dos"
7181

7282
# Format the code
73-
format:
83+
format:
7484
dotnet format whitespace -v diag Rubjerg.Graphviz.sln
7585
dotnet format whitespace -v diag Rubjerg.Graphviz.Tests.sln
7686

0 commit comments

Comments
 (0)