Skip to content
Merged
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
36 changes: 36 additions & 0 deletions .github/workflows/win-build-nonportable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: win-build-nonportable

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch

on:
push: { branches: [ master ] }
pull_request: { branches: [ master ] }
release: { types: [published] } # runs on “Publish release” button
workflow_dispatch: # lets you run it by hand

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
name: Checkout Code
with:
fetch-depth: 0

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Setup NuGet.exe for use with actions
uses: NuGet/[email protected]

- name: Setup Just
uses: extractions/setup-just@v3

- name: Build and test
run: just test-win-x64
3 changes: 3 additions & 0 deletions README-src.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ In particular, if you only want to read graphs and run the DOT layout algorithm,
To run our tests successfully you will also need libgts and libpcre2 (for the neato algorithm).
For more details, check the dependencies of any graphviz binaries with `ldd`.

It is currently not possible to use this package on linux in a non-portable application, i.e. an application that targets linux-x64.
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.

## Installation

Add the [Rubjerg.Graphviz nuget package](https://www.nuget.org/packages/Rubjerg.Graphviz/) to your project.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ In particular, if you only want to read graphs and run the DOT layout algorithm,
To run our tests successfully you will also need libgts and libpcre2 (for the neato algorithm).
For more details, check the dependencies of any graphviz binaries with `ldd`.

It is currently not possible to use this package on linux in a non-portable application, i.e. an application that targets linux-x64.
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.

## Installation

Add the [Rubjerg.Graphviz nuget package](https://www.nuget.org/packages/Rubjerg.Graphviz/) to your project.
Expand Down
2 changes: 2 additions & 0 deletions Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>
<!-- Need to list these in order to do a nonportable build -->
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>latest</LangVersion>
<DebugType>embedded</DebugType>
<!-- Need to list these in order to do a nonportable build -->
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
14 changes: 12 additions & 2 deletions Rubjerg.Graphviz/GraphvizCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Text;
using System.Runtime.InteropServices;
using System.Linq;

namespace Rubjerg.Graphviz;

Expand Down Expand Up @@ -33,6 +34,16 @@ internal static string Rid
}
}

internal static Lazy<string> _DotExePath = new Lazy<string>(() =>
// If graphviz is not found in the runtimes folder, look in the current directory for compatibility with nonportable windows builds.
new string[] {
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot"),
Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot.exe"),
"dot",
"dot.exe"
}.FirstOrDefault(File.Exists));
internal static string DotExePath => _DotExePath.Value;

public static RootGraph CreateLayout(Graph input, string engine = LayoutEngines.Dot, CoordinateSystem coordinateSystem = CoordinateSystem.BottomLeft)
{
var (stdout, stderr) = Exec(input, engine: engine);
Expand All @@ -56,7 +67,6 @@ public static string ConvertBytesOutputToString(byte[] data)
/// <returns>stderr may contain warnings, stdout is in utf8 encoding</returns>
public static (byte[] stdout, string stderr) Exec(Graph input, string format = "xdot", string? outputPath = null, string engine = LayoutEngines.Dot)
{
var exeName = Path.Combine(AppContext.BaseDirectory, "runtimes", Rid, "native", "dot");
string arguments = $"-T{format} -K{engine}";
if (outputPath != null)
{
Expand All @@ -71,7 +81,7 @@ public static (byte[] stdout, string stderr) Exec(Graph input, string format = "
?? Path.GetDirectoryName(System.AppContext.BaseDirectory);

// Construct the path to the executable
string exePath = Path.Combine(exeDirectory, exeName);
string exePath = Path.Combine(exeDirectory, DotExePath);

Process process = new Process();

Expand Down
16 changes: 13 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ build SOLUTION:
dotnet build {{SOLUTION}} --configuration Release --no-restore; \
fi

build-rid SOLUTION RID:
dotnet build {{SOLUTION}} --configuration Release --no-restore -r {{RID}};

# Build nuget package
build-package: restore
just build Rubjerg.Graphviz.sln
Expand All @@ -32,9 +35,9 @@ build-tests: restore-tests
just build Rubjerg.Graphviz.Tests.sln

# Run unit tests for a project
test PROJECT:
test PROJECT OUTPUT_PATH='bin/x64/Release/net8.0/':
dotnet test --no-build \
-p:OutputPath=bin/x64/Release/net8.0 \
-p:OutputPath={{OUTPUT_PATH}} \
-c Release \
-f net8.0 \
-v d \
Expand All @@ -54,6 +57,13 @@ test-nugetorg:
just test NugetOrgTests/Rubjerg.Graphviz.NugetOrgTest/Rubjerg.Graphviz.NugetOrgTest.csproj
just test NugetOrgTests/Rubjerg.Graphviz.NugetOrgTransitiveTest/Rubjerg.Graphviz.NugetOrgTransitiveTest.csproj

# Build and test nonportable win-x64 deployment
test-win-x64: restore-tests
dotnet build Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj --configuration Release --no-restore -r win-x64;
dotnet build Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj --configuration Release --no-restore -r win-x64;
just test Rubjerg.Graphviz.Test/Rubjerg.Graphviz.Test.csproj bin/Release/net8.0/win-x64/
just test Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj bin/Release/net8.0/win-x64/

locate-nupkg GITHUB_OUTPUT:
echo "package=$(find . -name "Rubjerg.Graphviz.*.nupkg" | head -1)" >> "{{GITHUB_OUTPUT}}"

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

# Format the code
format:
format:
dotnet format whitespace -v diag Rubjerg.Graphviz.sln
dotnet format whitespace -v diag Rubjerg.Graphviz.Tests.sln

Expand Down
Loading