Skip to content

Commit

Permalink
feat: publish native AOT
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne4to committed Jan 28, 2024
1 parent 9487564 commit e63022b
Show file tree
Hide file tree
Showing 28 changed files with 1,264 additions and 698 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/native-aot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish native AOT

on:
push:
branches: [ native-aot ]
# pull_request:
# # Sequence of patterns matched against refs/heads
# branches:
# - master

jobs:
build:
runs-on: ubuntu-latest
env:
# temp fix frontend build
# Treating warnings as errors because process.env.CI = true.
# Most CI servers set it automatically.
CI: 'false'
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
global-json-file: global.json
- uses: actions/setup-node@v4
with:
# Version Spec of the version to use in SemVer notation.
# It also emits such aliases as lts, latest, nightly and canary builds
# Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: 20
- name: Publish AOT version
shell: pwsh
run: |
./scripts/publish-native-aot.ps1
- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
with:
name: Heartbeat
path: artifacts/linux-x64/Heartbeat
retention-days: 1

# \artifacts\win-x64\Heartbeat.exe
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<PackageTags>ClrMd diagnostics</PackageTags>
<Description>Diagnostics utility to analyze memory dumps of a .NET application</Description>
</PropertyGroup>

<PropertyGroup>
<Configurations>Debug;Release;DebugOpenAPI;ReleaseAOT</Configurations>
</PropertyGroup>

<PropertyGroup>
<!--<EnableNETAnalyzers>true</EnableNETAnalyzers>-->
Expand Down
34 changes: 18 additions & 16 deletions Heartbeat.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Global
Release|arm64 = Release|arm64
Release|x64 = Release|x64
Release|x86 = Release|x86
DebugOpenAPI|Any CPU = DebugOpenAPI|Any CPU
ReleaseAOT|Any CPU = ReleaseAOT|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -57,14 +59,6 @@ Global
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Debug|x64.Build.0 = Debug|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Debug|x86.ActiveCfg = Debug|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Debug|x86.Build.0 = Debug|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|Any CPU.ActiveCfg = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|Any CPU.Build.0 = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|arm64.ActiveCfg = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|arm64.Build.0 = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|x64.ActiveCfg = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|x64.Build.0 = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|x86.ActiveCfg = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugLocal|x86.Build.0 = DebugLocal|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|Any CPU.Build.0 = Release|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|arm64.ActiveCfg = Release|Any CPU
Expand All @@ -73,6 +67,10 @@ Global
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|x64.Build.0 = Release|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|x86.ActiveCfg = Release|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.Release|x86.Build.0 = Release|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.DebugOpenAPI|Any CPU.Build.0 = DebugOpenAPI|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
{9E63F5A0-7695-474C-A946-64D75F8D9617}.ReleaseAOT|Any CPU.Build.0 = ReleaseAOT|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand All @@ -81,14 +79,6 @@ Global
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|x64.Build.0 = Debug|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|x86.ActiveCfg = Debug|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Debug|x86.Build.0 = Debug|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|Any CPU.ActiveCfg = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|Any CPU.Build.0 = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|arm64.ActiveCfg = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|arm64.Build.0 = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|x64.ActiveCfg = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|x64.Build.0 = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|x86.ActiveCfg = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugLocal|x86.Build.0 = DebugLocal|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|Any CPU.Build.0 = Release|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|arm64.ActiveCfg = Release|Any CPU
Expand All @@ -97,6 +87,10 @@ Global
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|x64.Build.0 = Release|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|x86.ActiveCfg = Release|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.Release|x86.Build.0 = Release|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.DebugOpenAPI|Any CPU.Build.0 = DebugOpenAPI|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
{D4060CFE-8141-49CE-99A5-559599D0E6B4}.ReleaseAOT|Any CPU.Build.0 = ReleaseAOT|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand All @@ -121,6 +115,8 @@ Global
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Release|x64.Build.0 = Release|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Release|x86.ActiveCfg = Release|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.Release|x86.Build.0 = Release|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{AC8E6790-14D5-42C5-AF51-98E8EB80644F}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand All @@ -145,6 +141,8 @@ Global
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Release|x64.Build.0 = Release|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Release|x86.ActiveCfg = Release|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.Release|x86.Build.0 = Release|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{789E65CA-B8F7-47B9-9013-B159D1E93F36}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand All @@ -169,6 +167,8 @@ Global
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Release|x64.Build.0 = Release|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Release|x86.ActiveCfg = Release|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.Release|x86.Build.0 = Release|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{F1FF76E5-3DEE-4C64-8A62-8A645B981D1D}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand All @@ -193,6 +193,8 @@ Global
{3D11554D-E09C-4710-B071-D90BB2447F46}.Release|x64.Build.0 = Release|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.Release|x86.ActiveCfg = Release|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.Release|x86.Build.0 = Release|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.DebugOpenAPI|Any CPU.ActiveCfg = DebugOpenAPI|Any CPU
{3D11554D-E09C-4710-B071-D90BB2447F46}.ReleaseAOT|Any CPU.ActiveCfg = ReleaseAOT|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Heartbeat
[![NuGet Badge](https://buildstats.info/nuget/heartbeat?includePreReleases=true&dWidth=0)](https://www.nuget.org/packages/Heartbeat/)

Diagnostics utility with web UI to analyze memory dumps of a .NET application
Diagnostics utility with web UI to analyze memory dumps of .NET application

## Getting started

Expand Down
69 changes: 69 additions & 0 deletions scripts/publish-native-aot.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
$ErrorActionPreference = "Stop"

function Get-Runtime {
if ($IsWindows) {
return $env:PROCESSOR_ARCHITECTURE -eq 'AMD64' ? 'win-x64' : 'win-arm64'
}

if ($IsLinux) {
return (uname -m) -eq 'aarch64' ? 'linux-arm64' : 'linux-x64'
}

if ($IsMacOS) {
return (uname -m) -eq 'arm64' ? 'osx-arm64' : 'osx-x64'
}
}

function Assert-ExitCode {
if (-not $?) {
throw 'Latest command failed'
}
}

$Configuration = 'ReleaseAOT'
$RepositoryRoot = Split-Path $PSScriptRoot
$ArtifactsRoot = Join-Path $RepositoryRoot 'artifacts'

Push-Location
try {
Set-Location $RepositoryRoot

# [xml]$XmlConfig = Get-Content 'Directory.Build.props'

# $XmlElement = Select-Xml '/Project/PropertyGroup/VersionPrefix' $XmlConfig |
# Select-Object -ExpandProperty Node

# $VersionPrefix = $XmlElement.InnerText
# $VersionSuffix = "rc.$(Get-Date -Format 'yyyy-MM-dd-HHmm')"
# $PackageVersion = "$VersionPrefix-$VersionSuffix"

dotnet clean --configuration $Configuration

# https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
# $Runtimes = @('win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
$Runtimes = @(Get-Runtime)
# TODO check `uname -m` for linux and macos
# $env:PROCESSOR_ARCHITECTURE
foreach ($Runtime in $Runtimes) {
$OutDir = Join-Path $ArtifactsRoot $Runtime
Write-Host "Publish AOT version for $Runtime to $OutDir"
dotnet publish --configuration $Configuration --runtime $Runtime --output $OutDir
Assert-ExitCode

Write-Host "Files in $OutDir"
Get-ChildItem $OutDir
}

# TODO zip?
}
catch {
Write-Host 'Publish AOT - FAILED!' -ForegroundColor Red
throw
}
finally {
Pop-Location
}

# TODO Cross-OS native compilation
# C:\Users\Ne4to\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.1\build\Microsoft.NETCore.Native.Windows.targets(123,5): error : Platform linker not found. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites, in particular the Desktop Development for C++ workload in Visual Studio. For ARM64 development also install C++ ARM64 build tools. [C:\Users\Ne4to\projects\github.com\Ne4to\Heartbeat\src\Heartbeat\Heartbeat.csproj]
# C:\Users\Ne4to\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.1\build\Microsoft.NETCore.Native.Publish.targets(60,5): error : Cross-OS native compilation is not supported. [C:\Users\Ne4to\projects\github.com\Ne4to\Heartbeat\src\Heartbeat\Heartbeat.csproj]
23 changes: 17 additions & 6 deletions scripts/reinstall-dev-tool.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
$ErrorActionPreference = "Stop"

function Assert-ExitCode {
if (-not $?) {
throw 'Latest command failed'
}
}

$RepositoryRoot = Split-Path $PSScriptRoot

Push-Location
Expand All @@ -16,17 +22,22 @@ try

dotnet tool uninstall -g Heartbeat
dotnet clean --configuration Release
Get-Date -Format ''
$VersionSuffix = "rc.$(Get-Date -Format 'yyyy-MM-dd-HHmm')"
dotnet publish --runtime win-x64
dotnet pack --runtime win-x64 --version-suffix $VersionSuffix
# $PackageVersion = "$VersionPrefix-$VersionSuffix"
# dotnet tool install --global --add-source ./src/Heartbeat/nupkg Heartbeat --version $PackageVersion
dotnet publish
Assert-ExitCode
dotnet pack --version-suffix $VersionSuffix
Assert-ExitCode
$PackageVersion = "$VersionPrefix-$VersionSuffix"
dotnet tool install --global --add-source ./src/Heartbeat/nupkg Heartbeat --version $PackageVersion
Assert-ExitCode
}
catch {
Write-Host 'Install global tool - FAILED!' -ForegroundColor Red
throw
}
finally {
Pop-Location
}
}



9 changes: 4 additions & 5 deletions scripts/update-ts-client.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
$ErrorActionPreference = "Stop"

$Configuration = 'DebugOpenAPI'
$RepositoryRoot = Split-Path $PSScriptRoot
$FrontendRoot = Join-Path $RepositoryRoot 'src/Heartbeat/ClientApp'
$ContractPath = Join-Path $FrontendRoot 'api.yml'
$DllPath = Join-Path $RepositoryRoot 'src/Heartbeat/bin/Debug/net8.0/Heartbeat.dll'
$DllPath = Join-Path $RepositoryRoot "src/Heartbeat/bin/$Configuration/net8.0/Heartbeat.dll"

Push-Location
try
{
Set-Location $RepositoryRoot

dotnet tool restore
dotnet build --configuration Debug
dotnet build --configuration $Configuration

Set-Location $FrontendRoot
$env:HEARTBEAT_GENERATE_CONTRACTS = 'true'
dotnet swagger tofile --yaml --output $ContractPath $DllPath Heartbeat
dotnet kiota generate -l typescript --openapi $ContractPath -c HeartbeatClient -o ./src/client --clean-output

Expand All @@ -26,5 +26,4 @@ catch {
}
finally {
Pop-Location
$env:HEARTBEAT_GENERATE_CONTRACTS = $null
}
4 changes: 0 additions & 4 deletions src/Heartbeat.Runtime/Heartbeat.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
</ItemGroup>

<PropertyGroup>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

Expand All @@ -17,8 +15,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="3.1.456101" />


<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading

0 comments on commit e63022b

Please sign in to comment.