20 changed files with 544 additions and 116 deletions

No files matched your search

@@ -0,0 +1,93 @@
name: daily-avalonia-native
on:
schedule:
- cron: '17 3 * * *'
workflow_dispatch:
inputs:
force_build:
description: Rebuild even if matching successful Actions artifacts exist
type: boolean
default: false
permissions:
contents: read
actions: write
concurrency:
group: daily-avalonia-native
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
major: [11, 12]
steps:
- name: Check latest stable Avalonia and dispatch Native build
env:
GH_TOKEN: ${{ github.token }}
AVALONIA_MAJOR: ${{ matrix.major }}
FORCE_BUILD: ${{ inputs.force_build }}
NATIVE_BRANCH: avalonia-native
PACKAGE_REVISION: '2'
run: |
python3 - <<'PY'
import json
import os
import re
import subprocess
repository = os.environ['GITHUB_REPOSITORY']
branch = os.environ['NATIVE_BRANCH']
major = int(os.environ['AVALONIA_MAJOR'])
def api(endpoint):
return json.loads(subprocess.check_output(['gh', 'api', endpoint], text=True))
def summary(message):
print(message, flush=True)
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a', encoding='utf-8') as output:
output.write(message + '\n')
upstream = json.loads(subprocess.check_output([
'curl', '--fail', '--silent', '--show-error', '--location', '--retry', '3',
'https://api.nuget.org/v3-flatcontainer/avalonia/index.json',
], text=True))
candidates = [version for version in upstream['versions']
if re.fullmatch(r'\d+\.\d+\.\d+', version)
and int(version.split('.')[0]) == major]
if not candidates:
raise SystemExit(f'No stable Avalonia {major} version found')
version = max(candidates, key=lambda value: tuple(map(int, value.split('.'))))
package_version = version + '.' + os.environ['PACKAGE_REVISION']
artifact_name = 'staticlink-avalonia-native-' + package_version
head_sha = api(f'repos/{repository}/branches/{branch}')['commit']['sha']
if os.environ['FORCE_BUILD'] != 'true':
already_validated = False
runs = api(f'repos/{repository}/actions/workflows/nuget-avalonia-native.yml/runs'
f'?branch={branch}&status=success&per_page=100')['workflow_runs']
for run in runs:
if run['head_sha'] != head_sha or run['conclusion'] != 'success':
continue
artifacts = api(f"repos/{repository}/actions/runs/{run['id']}/artifacts?per_page=100")['artifacts']
if any(artifact['name'] == artifact_name and not artifact['expired']
for artifact in artifacts):
summary(f"Already validated {package_version}: {run['html_url']}")
already_validated = True
break
if already_validated:
raise SystemExit(0)
payload = json.dumps({'ref': branch, 'inputs': {
'avalonia_version': version, 'force_build': True, 'publish_to_nuget': False,
}})
subprocess.run([
'gh', 'api', '--method', 'POST',
f'repos/{repository}/actions/workflows/nuget-avalonia-native.yml/dispatches',
'--input', '-',
], input=payload, text=True, check=True)
summary(f'Dispatched {package_version} on {branch}; Actions artifacts only, no NuGet publication.')
PY
@@ -0,0 +1,76 @@
name: daily-native-release
on:
workflow_dispatch:
inputs:
force_build:
description: Build current stable versions even if already published
type: boolean
default: false
permissions:
contents: read
actions: write
concurrency:
group: daily-native-release-${{ github.ref }}
cancel-in-progress: false
jobs:
dispatch:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
branch: [skia3, skia4, avalonia-native]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: Check and dispatch this branch
env:
GH_TOKEN: ${{ github.token }}
TRACK_BRANCH: ${{ matrix.branch }}
FORCE_BUILD: ${{ inputs.force_build }}
run: |
python3 - <<'PY'
import json
import os
import subprocess
branch = os.environ["TRACK_BRANCH"]
force = os.environ["FORCE_BUILD"] == "true"
def dispatch(workflow, inputs):
payload = json.dumps({"ref": branch, "inputs": inputs})
subprocess.run(
["gh", "api", "--method", "POST",
f"repos/{os.environ['GITHUB_REPOSITORY']}/actions/workflows/{workflow}/dispatches",
"--input", "-"],
input=payload, text=True, check=True,
)
if branch == "avalonia-native":
dispatch("nuget-avalonia-native.yml", {
"force_build": force, "publish_to_nuget": False,
})
else:
command = ["python3", "scripts/check-upstream-releases.py"]
if force:
command.append("--force")
subprocess.run(command, check=True)
for release in json.load(open("release-plan.json")):
if release["ref"] != branch:
raise SystemExit("Release track does not match the checked-out branch")
dispatch("nuget-static-graphics.yml", {
"skiasharp_version": release["skiasharp_version"],
"publish_to_nuget": False, "publish_to_release": False,
})
print(f"Dispatched {release['package_version']} on {branch}")
PY
- uses: actions/upload-artifact@v4
if: ${{ always() && matrix.branch != 'avalonia-native' }}
with:
name: daily-release-plan-${{ matrix.branch }}
path: release-plan.json
if-no-files-found: warn
+61 -43
View File
@@ -1,12 +1,10 @@
name: staticlink-avalonia-native
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
inputs:
avalonia_version:
description: Avalonia version to build; empty uses the latest stable NuGet version
description: Avalonia version to build; empty checks the latest stable 11.x and 12.x versions
required: false
type: string
force_build:
@@ -17,21 +15,16 @@ on:
publish_to_nuget:
description: Publish with NuGet Trusted Publishing after smoke tests
required: true
default: true
default: false
type: boolean
concurrency:
group: staticlink-avalonia-native
cancel-in-progress: false
jobs:
detect:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
avalonia_version: ${{ steps.version.outputs.avalonia_version }}
package_version: ${{ steps.version.outputs.package_version }}
versions: ${{ steps.version.outputs.versions }}
should_build: ${{ steps.version.outputs.should_build }}
steps:
- name: Detect unpublished Avalonia version
@@ -43,31 +36,46 @@ jobs:
run: |
set -euo pipefail
avalonia_version="$REQUESTED_VERSION"
if [ -z "$avalonia_version" ]; then
avalonia_version="$(curl --fail --silent --show-error --location \
https://api.nuget.org/v3-flatcontainer/avalonia/index.json \
| jq -r '[.versions[] | select(contains("-") | not)] | last')"
if [ -n "$REQUESTED_VERSION" ]; then
candidate_versions=("$REQUESTED_VERSION")
else
nuget_versions="$(curl --fail --silent --show-error --location \
https://api.nuget.org/v3-flatcontainer/avalonia/index.json)"
candidate_versions=()
for major in 11 12; do
candidate_versions+=("$(jq -r --arg major "$major" \
'[.versions[] | select(startswith($major + ".") and (contains("-") | not))] | last' \
<<< "$nuget_versions")")
done
fi
if [ -z "$avalonia_version" ] || [ "$avalonia_version" = "null" ]; then
echo "Could not determine the latest stable Avalonia version." >&2
exit 1
fi
versions='[]'
for avalonia_version in "${candidate_versions[@]}"; do
if [ -z "$avalonia_version" ] || [ "$avalonia_version" = "null" ]; then
echo "Could not determine a stable Avalonia version." >&2
exit 1
fi
package_version="$avalonia_version.1"
package_url="https://api.nuget.org/v3-flatcontainer/staticlink.avalonia.native/$package_version/staticlink.avalonia.native.$package_version.nupkg"
should_build=true
if [ "$FORCE_BUILD" != "true" ] && curl --fail --silent --location --output /dev/null "$package_url"; then
should_build=false
fi
package_version="$avalonia_version.1"
package_url="https://api.nuget.org/v3-flatcontainer/staticlink.avalonia.native/$package_version/staticlink.avalonia.native.$package_version.nupkg"
if [ "$FORCE_BUILD" != "true" ] && curl --fail --silent --location --output /dev/null "$package_url"; then
echo "Already published: $package_version"
continue
fi
echo "Avalonia version: $avalonia_version"
echo "StaticLink.Avalonia.Native version: $package_version"
echo "Build required: $should_build"
echo "avalonia_version=$avalonia_version" >> "$GITHUB_OUTPUT"
echo "package_version=$package_version" >> "$GITHUB_OUTPUT"
echo "should_build=$should_build" >> "$GITHUB_OUTPUT"
echo "Build required: $package_version"
versions="$(jq -cn --argjson versions "$versions" \
--arg avalonia_version "$avalonia_version" \
--arg package_version "$package_version" \
'$versions + [{avalonia_version: $avalonia_version, package_version: $package_version}]')"
done
echo "versions=$versions" >> "$GITHUB_OUTPUT"
if [ "$versions" = '[]' ]; then
echo 'should_build=false' >> "$GITHUB_OUTPUT"
else
echo 'should_build=true' >> "$GITHUB_OUTPUT"
fi
build:
needs: detect
@@ -75,6 +83,8 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.detect.outputs.versions) }}
rid: [osx-x64, osx-arm64]
include:
- rid: osx-x64
runner: macos-14
@@ -85,7 +95,7 @@ jobs:
contents: read
env:
RID: ${{ matrix.rid }}
AVALONIA_VERSION: ${{ needs.detect.outputs.avalonia_version }}
AVALONIA_VERSION: ${{ matrix.version.avalonia_version }}
WORK_DIR: ${{ github.workspace }}/External/AvaloniaNative/.work
OUTPUT_DIR: ${{ github.workspace }}/External/AvaloniaNative/${{ matrix.rid }}/native
steps:
@@ -107,7 +117,7 @@ jobs:
- name: Upload static AvaloniaNative
uses: actions/upload-artifact@v4
with:
name: native-avalonia-${{ matrix.rid }}
name: native-avalonia-${{ matrix.version.avalonia_version }}-${{ matrix.rid }}
path: |
External/AvaloniaNative/${{ matrix.rid }}/native/libAvaloniaNative.a
External/AvaloniaNative/${{ matrix.rid }}/native/macos_font_preinit.o
@@ -118,6 +128,9 @@ jobs:
- detect
- build
if: ${{ needs.detect.outputs.should_build == 'true' }}
strategy:
matrix:
version: ${{ fromJSON(needs.detect.outputs.versions) }}
runs-on: ubuntu-latest
permissions:
contents: read
@@ -132,7 +145,7 @@ jobs:
- name: Download static AvaloniaNative archives
uses: actions/download-artifact@v4
with:
pattern: native-avalonia-*
pattern: native-avalonia-${{ matrix.version.avalonia_version }}-*
path: artifacts/native
merge-multiple: false
@@ -142,8 +155,8 @@ jobs:
set -euo pipefail
for rid in osx-x64 osx-arm64; do
mkdir -p "External/AvaloniaNative/$rid/native"
cp "artifacts/native/native-avalonia-$rid/libAvaloniaNative.a" "External/AvaloniaNative/$rid/native/"
cp "artifacts/native/native-avalonia-$rid/macos_font_preinit.o" "External/AvaloniaNative/$rid/native/"
cp "artifacts/native/native-avalonia-${{ matrix.version.avalonia_version }}-$rid/libAvaloniaNative.a" "External/AvaloniaNative/$rid/native/"
cp "artifacts/native/native-avalonia-${{ matrix.version.avalonia_version }}-$rid/macos_font_preinit.o" "External/AvaloniaNative/$rid/native/"
done
- name: Pack StaticLink.Avalonia.Native
@@ -151,13 +164,13 @@ jobs:
dotnet pack NuGet/AvaloniaNative/StaticLink.Avalonia.Native.csproj \
-c Release \
-o artifacts/nuget \
/p:PackageVersion=${{ needs.detect.outputs.package_version }} \
/p:Version=${{ needs.detect.outputs.package_version }}
/p:PackageVersion=${{ matrix.version.package_version }} \
/p:Version=${{ matrix.version.package_version }}
- name: Upload NuGet package
uses: actions/upload-artifact@v4
with:
name: staticlink-avalonia-native-${{ needs.detect.outputs.package_version }}
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
path: artifacts/nuget/*.nupkg
if-no-files-found: error
@@ -169,6 +182,8 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.detect.outputs.versions) }}
rid: [osx-x64, osx-arm64]
include:
- rid: osx-x64
runner: macos-14
@@ -188,7 +203,7 @@ jobs:
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: staticlink-avalonia-native-${{ needs.detect.outputs.package_version }}
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
path: artifacts/nuget
- name: Publish Avalonia NativeAOT smoke app
@@ -198,8 +213,8 @@ jobs:
pwsh ./scripts/create-avalonia-smoke.ps1 `
-ProjectDir $projectDir `
-NuGetSource (Resolve-Path "artifacts/nuget") `
-AvaloniaVersion "${{ needs.detect.outputs.avalonia_version }}" `
-StaticLinkNativeVersion "${{ needs.detect.outputs.package_version }}"
-AvaloniaVersion "${{ matrix.version.avalonia_version }}" `
-StaticLinkNativeVersion "${{ matrix.version.package_version }}"
dotnet publish (Join-Path $projectDir "AvaloniaStaticLinkSmoke.csproj") `
-c Release `
-r "${{ matrix.rid }}" `
@@ -248,6 +263,9 @@ jobs:
- detect
- smoke
if: ${{ needs.detect.outputs.should_build == 'true' && (github.event_name == 'schedule' || inputs.publish_to_nuget == true) }}
strategy:
matrix:
version: ${{ fromJSON(needs.detect.outputs.versions) }}
runs-on: ubuntu-latest
permissions:
contents: read
@@ -256,7 +274,7 @@ jobs:
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: staticlink-avalonia-native-${{ needs.detect.outputs.package_version }}
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
path: artifacts/nuget
- name: Validate Trusted Publishing configuration
@@ -6,7 +6,7 @@ on:
source_version:
description: Existing package version containing the static libraries
required: true
default: 3.119.4-7922.1
default: 4.150.1-7922.1
type: string
publish_to_nuget:
description: Publish package to nuget.org
@@ -360,11 +360,103 @@ jobs:
path: artifacts/smoke-${{ matrix.rid }}/**
if-no-files-found: error
smoke-macos-metal:
runs-on: macos-15
needs: pack
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.302"
- name: Download NuGet package
uses: actions/download-artifact@v4
with:
name: staticlink-avalonia-nuget
path: artifacts/nuget
- name: Publish Avalonia 12 macOS arm64 smoke app
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$package = Get-ChildItem -Path "artifacts/nuget" -Filter "StaticLink.Avalonia.*.nupkg" | Where-Object { $_.Name -notlike "StaticLink.Avalonia.Native.*" } | Select-Object -First 1
if (-not $package) { throw "StaticLink NuGet package was not downloaded." }
if ($package.BaseName -notmatch '^StaticLink\.Avalonia\.(.+)$') { throw "Unexpected package name: $($package.Name)" }
$projectDir = Join-Path $PWD "artifacts/avalonia-metal-smoke-src"
pwsh ./scripts/create-avalonia-smoke.ps1 `
-ProjectDir $projectDir `
-NuGetSource (Resolve-Path "artifacts/nuget") `
-StaticLinkVersion $Matches[1] `
-AvaloniaVersion "12.1.0" `
-StaticLinkNativeVersion "12.1.0.1"
dotnet publish (Join-Path $projectDir "AvaloniaStaticLinkSmoke.csproj") `
-c Release `
-r osx-arm64 `
--configfile (Join-Path $projectDir "NuGet.config") `
/p:PublishAot=true `
/p:SelfContained=true `
/p:PublishSingleFile=true `
/p:StripSymbols=true `
/p:PublishDir="$PWD/artifacts/smoke-osx-arm64-metal/"
- name: Verify fully static third-party libraries
shell: bash
run: |
set -euo pipefail
publish_dir="artifacts/smoke-osx-arm64-metal"
test -x "$publish_dir/AvaloniaStaticLinkSmoke"
for library in libAvaloniaNative.dylib libSkiaSharp.dylib libHarfBuzzSharp.dylib; do
test ! -f "$publish_dir/$library"
done
- name: Run default and Metal-only smoke tests
shell: bash
run: |
set -euo pipefail
cd artifacts/smoke-osx-arm64-metal
python3 - <<'PY'
import os
import pathlib
import subprocess
for renderer in ("default", "metal"):
environment = os.environ.copy()
environment["STATICLINK_MAC_RENDERER"] = renderer
environment["STATICLINK_SMOKE_AUTOCLOSE"] = "1"
try:
result = subprocess.run(
["./AvaloniaStaticLinkSmoke"],
env=environment,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
timeout=15,
)
except subprocess.TimeoutExpired as exception:
output = exception.stdout or ""
if isinstance(output, bytes):
output = output.decode(errors="replace")
pathlib.Path(f"avalonia-{renderer}.log").write_text(output)
raise SystemExit(f"Avalonia {renderer} smoke app timed out.\n{output}")
output = result.stdout or ""
pathlib.Path(f"avalonia-{renderer}.log").write_text(output)
print(output, end="")
marker = f"STATICLINK_SMOKE_READY={renderer}"
if result.returncode != 0 or marker not in output.splitlines():
raise SystemExit(f"Avalonia {renderer} smoke app failed with exit code {result.returncode}.")
PY
publish-nuget:
runs-on: ubuntu-24.04
needs:
- pack
- smoke-avalonia
- smoke-macos-metal
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
@@ -400,6 +492,7 @@ jobs:
- preflight
- pack
- smoke-avalonia
- smoke-macos-metal
- publish-nuget
if: ${{ startsWith(github.ref, 'refs/tags/staticlink-avalonia-v') || (github.event_name == 'workflow_dispatch' && inputs.publish_to_release == true) }}
permissions:
+1 -1
View File
@@ -13,7 +13,7 @@ on:
inputs:
skiasharp_version:
required: true
default: "3.119.4"
default: "4.150.1"
type: string
angle_branch:
required: true
+1 -1
View File
@@ -13,7 +13,7 @@ on:
inputs:
skiasharp_version:
required: true
default: "3.119.4"
default: "4.150.1"
type: string
angle_branch:
required: true
+2 -1
View File
@@ -16,7 +16,7 @@ on:
inputs:
skiasharp_version:
required: true
default: "3.119.4"
default: "4.150.1"
type: string
angle_branch:
required: true
@@ -70,6 +70,7 @@ jobs:
sh -lc '
set -e
apk add --no-cache bash ca-certificates git python3 py3-httplib2 py3-pysocks py3-six clang compiler-rt lld llvm g++ ninja pkgconf fontconfig-dev glib-dev mesa-dev libx11-dev libxcb-dev libxext-dev pciutils-dev linux-headers perl curl tar xz patch gcompat libc6-compat
git config --global --add safe.directory "*"
python3 - <<'"'"'PY'"'"'
import pathlib
import httplib2
@@ -13,7 +13,7 @@ on:
inputs:
skiasharp_version:
required: true
default: "3.119.4"
default: "4.150.1"
type: string
angle_branch:
required: true
+45
View File
@@ -0,0 +1,45 @@
# Manual artifact validation
Native daily checks are enabled by daily-avalonia-native.yml on main at 03:17
UTC (11:17 Singapore time). Skia3/4 daily schedules remain disabled. No
NuGet.org publication or GitHub Release is requested by either dispatcher.
The Native checker handles the latest stable Avalonia 11 and 12 independently.
It skips versions with non-expired NuGet artifacts from a successful Native
run at the current avalonia-native branch commit. New versions, changed Native
code, expired artifacts, or failed builds trigger a new artifact-only build.
Set force_build=true on the daily checker to bypass this successful-run check.
Before release builds, run nuget-static-graphics.yml on skia4 with
environment_only=true. This checks the actual container's Python/depot_tools,
.NET 8/10, SDKs, sysroots, and C/C++ compilation plus C executable linking for
all nine RIDs. Download toolchain-environment-validation to inspect the report.
The same environment gate runs before every graphics and native build and
must pass before the toolchain image is published for release compilation.
- skia3: nuget-static-graphics.yml; latest stable SkiaSharp 3.
- skia4: nuget-static-graphics.yml; latest stable SkiaSharp 4.
- avalonia-native: nuget-avalonia-native.yml; latest stable Avalonia 11 and 12.
Download staticlink-avalonia-nuget and avalonia-smoke-<RID> from each graphics run.
Download staticlink-avalonia-native-<version> and
avalonia-native-smoke-<AvaloniaVersion>-<RID> from the native run.
Native archives and source locks are also retained as Actions artifacts.
Graphics macOS smoke tests use the already published AvaloniaNative revision 1
by default, so the graphics builds do not require the experimental native
revision 2 to be published. The native branch validates its own local revision 2
package separately. To test both experimental packages together, put both
downloaded packages in a local NuGet feed and reference their exact versions.
Smoke executables are retained even if a later runtime validation fails.
An artifact is not evidence that all validation gates passed; check job results.
The daily-native-release workflow on main currently supports manual dispatch
only. Its three matrix jobs check out their own branch and dispatch independently.
Use force_build=true to rebuild published versions for testing.
After validation, enable the schedule on main only; non-default branches cannot
run their own GitHub cron schedules. Publication remains an explicit opt-in.
The manual graphics dispatcher still checks publication rather than successful
Actions runs. Add the same successful-run tracking before enabling artifact-only
daily graphics builds if avoiding repeated builds is required.
+30 -14
View File
@@ -4,32 +4,48 @@ Static native libraries for Avalonia single-file NativeAOT publishing.
## Install
```bash
dotnet add package StaticLink.Avalonia
Choose the static graphics package that matches the Avalonia and SkiaSharp major versions used by your application.
| Avalonia version | SkiaSharp version | `StaticLink.Avalonia` version |
| --- | --- | --- |
| 11 | 2.88.9 | `2.88.9-7151.10` |
| 11 | 3.119.4 | `3.119.4-7922.1` |
| 12 | 3.119.4 | `3.119.4-7922.1` |
| 12 | 4.150.1 | `4.150.1-7922.1` |
Example:
```xml
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.1.0" />
<PackageReference Include="StaticLink.Avalonia" Version="4.150.1-7922.1" />
</ItemGroup>
```
Or add it manually:
### macOS
```xml
<PackageReference Include="StaticLink.Avalonia" Version="3.119.4-7922.1" />
```
For macOS, also reference `StaticLink.Avalonia.Native`. This package is macOS-only and must match your Avalonia version because it contains `libAvaloniaNative.a`.
For macOS, also reference `StaticLink.Avalonia.Native`. This package contains `libAvaloniaNative.a`, so its version must match the Avalonia version used by the application.
```xml
<!-- Avalonia 11.3.14 -->
<PackageReference Include="StaticLink.Avalonia.Native" Version="11.3.14.1" />
<!-- Avalonia 12.1.0 -->
<PackageReference Include="StaticLink.Avalonia.Native" Version="12.1.0.1" />
```
Add only the `StaticLink.Avalonia.Native` reference matching your Avalonia version.
On macOS, only Avalonia 12 with skia3/4 supports Metal. Avalonia 11 fully static apps must use OpenGL or Software because its Metal path dynamically loads `libSkiaSharp`.
## Publish
```bash
dotnet publish -c Release -r win-x64 \
-p:PublishAot=true \
-p:SelfContained=true \
-p:PublishSingleFile=true \
-p:StripSymbols=true
dotnet publish -c Release -r win-x64 -p:PublishAot=true
```
Use the RID you need, such as `win-x86`, `linux-x64`, `linux-arm64`, `osx-arm64`, or `osx-x64`.
For macOS, avoid the Metal renderer for fully static output. Use OpenGL or Software.
## Native Package Automation
`.github/workflows/nuget-avalonia-native.yml` runs daily and checks the latest stable `Avalonia` version on NuGet.org. If `StaticLink.Avalonia.Native.<AvaloniaVersion>.1` does not exist, it builds both macOS architectures from the matching Avalonia source tag, runs NativeAOT smoke tests, and publishes the package with NuGet Trusted Publishing.
@@ -6,7 +6,7 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>false</SuppressDependenciesWhenPacking>
<PackageId>StaticLink.Avalonia</PackageId>
<Version>3.119.4-7922.1</Version>
<Version>4.150.1-7922.1</Version>
<Authors>greepar</Authors>
<Company>greepar</Company>
<Description>Static SkiaSharp, HarfBuzzSharp, and ANGLE libraries for Avalonia NativeAOT single-file publishing.</Description>
@@ -19,7 +19,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.119.4" />
<PackageReference Include="SkiaSharp" Version="4.150.1" />
</ItemGroup>
<ItemGroup>
+27 -38
View File
@@ -4,59 +4,48 @@ Static native libraries for Avalonia single-file NativeAOT publishing.
## Install
```bash
dotnet add package StaticLink.Avalonia
Choose the static graphics package that matches the Avalonia and SkiaSharp major versions used by your application.
| Avalonia version | SkiaSharp version | `StaticLink.Avalonia` version |
| --- | --- | --- |
| 11 | 2.88.9 | `2.88.9-7151.10` |
| 11 | 3.119.4 | `3.119.4-7922.1` |
| 12 | 3.119.4 | `3.119.4-7922.1` |
| 12 | 4.150.1 | `4.150.1-7922.1` |
Example:
```xml
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.1.0" />
<PackageReference Include="StaticLink.Avalonia" Version="4.150.1-7922.1" />
</ItemGroup>
```
Or add it manually:
### macOS
```xml
<PackageReference Include="StaticLink.Avalonia" Version="3.119.4-7922.1" />
```
`3.119.4-7922.1` supports Avalonia 11. If you need the SkiaSharp 2 line for an Avalonia 11 project, use this optional package variant:
```xml
<PackageReference Include="StaticLink.Avalonia" Version="2.88.9-7151.10" />
```
`2.88.9-7151.10` is only for Avalonia 11 projects that specifically want SkiaSharp 2.
For macOS, also reference `StaticLink.Avalonia.Native`. This package is macOS-only and must match your Avalonia version because it contains `libAvaloniaNative.a`.
For macOS, also reference `StaticLink.Avalonia.Native`. This package contains `libAvaloniaNative.a`, so its version must match the Avalonia version used by the application.
```xml
<!-- Avalonia 11.3.14 -->
<PackageReference Include="StaticLink.Avalonia.Native" Version="11.3.14.1" />
<!-- Avalonia 12.1.0 -->
<PackageReference Include="StaticLink.Avalonia.Native" Version="12.1.0.1" />
```
Add only the `StaticLink.Avalonia.Native` reference matching your Avalonia version.
On macOS, only Avalonia 12 with skia3/4 supports Metal. Avalonia 11 fully static apps must use OpenGL or Software because its Metal path dynamically loads `libSkiaSharp`.
## Publish
```bash
dotnet publish -c Release -r win-x64 \
-p:PublishAot=true \
-p:SelfContained=true \
-p:PublishSingleFile=true \
-p:StripSymbols=true
dotnet publish -c Release -r win-x64 -p:PublishAot=true
```
Use the RID you need, such as `win-x86`, `linux-x64`, `linux-arm64`, `osx-arm64`, or `osx-x64`.
For macOS, avoid the Metal renderer for fully static output. Use OpenGL or Software.
## Native Package Automation
`.github/workflows/nuget-avalonia-native.yml` runs daily and checks the latest stable `Avalonia` version on NuGet.org. If `StaticLink.Avalonia.Native.<AvaloniaVersion>.1` does not exist, it builds both macOS architectures from the matching Avalonia source tag, runs NativeAOT smoke tests, and publishes the package with NuGet Trusted Publishing.
Configure NuGet.org Trusted Publishing for this repository and the `nuget-avalonia-native.yml` workflow, then add the NuGet.org account name as the repository variable `NUGET_USER`. No long-lived NuGet API key is used by this workflow.
## Static Graphics Automation
`.github/workflows/nuget-static-graphics.yml` runs a fast version, upstream-ref, patch, script, and smoke-project preflight before starting native builds. It then calls independent Windows, Linux, Linux musl, and macOS workflows, packs their artifacts, runs all NativeAOT smoke tests, and only then publishes NuGet and GitHub Release assets.
The platform workflows can also be dispatched independently when diagnosing a single platform:
- `static-graphics-windows.yml`
- `static-graphics-linux.yml`
- `static-graphics-musl.yml`
- `static-graphics-macos.yml`
The release workflow derives the SkiaSharp version and ANGLE branch from `NuGet/StaticGraphics/StaticLink.Avalonia.csproj`. Native source and build directories are cached by platform, RID, version, patch, and build script.
`.github/workflows/nuget-avalonia-native.yml` runs daily and checks the latest stable `Avalonia` version on NuGet.org. If `StaticLink.Avalonia.Native.<AvaloniaVersion>.1` does not exist, it builds both macOS architectures from the matching Avalonia source tag, runs NativeAOT smoke tests, and publishes the package with NuGet Trusted Publishing.
+23 -1
View File
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
namespace AvaloniaStaticLinkSmoke;
@@ -15,7 +16,28 @@ public sealed partial class App : Application
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
var renderer = Environment.GetEnvironmentVariable("STATICLINK_MAC_RENDERER") ?? "opengl";
var autoClose = Environment.GetEnvironmentVariable("STATICLINK_SMOKE_AUTOCLOSE") == "1";
desktop.MainWindow = new MainWindow(autoClose ? CompleteSmoke : null);
void CompleteSmoke(string backend)
{
Dispatcher.UIThread.Post(() =>
{
if (!renderer.Equals("metal", StringComparison.OrdinalIgnoreCase) ||
backend.Equals("Metal", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine($"STATICLINK_SMOKE_READY={renderer}");
}
else
{
Console.Error.WriteLine($"Expected the Metal renderer, but the active Skia backend was {backend}.");
Environment.ExitCode = 1;
}
desktop.MainWindow?.Close();
});
}
}
base.OnFrameworkInitializationCompleted();
@@ -1,11 +1,60 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia;
namespace AvaloniaStaticLinkSmoke;
public sealed partial class MainWindow : Window
{
public MainWindow()
private readonly Action<string>? _renderResult;
private int _renderResultReported;
public MainWindow() : this(null)
{
}
public MainWindow(Action<string>? renderResult)
{
_renderResult = renderResult;
InitializeComponent();
}
public override void Render(DrawingContext context)
{
base.Render(context);
if (_renderResult is not null)
{
context.Custom(new MetalBackendProbe(new Rect(Bounds.Size), ReportMetalResult));
}
}
private void ReportMetalResult(string backend)
{
if (Interlocked.Exchange(ref _renderResultReported, 1) == 0)
{
_renderResult?.Invoke(backend);
}
}
private sealed class MetalBackendProbe(Rect bounds, Action<string> report) : ICustomDrawOperation
{
public Rect Bounds { get; } = bounds;
public void Dispose()
{
}
public bool Equals(ICustomDrawOperation? other) => false;
public bool HitTest(Point point) => false;
public void Render(ImmediateDrawingContext context)
{
var feature = context.TryGetFeature(typeof(ISkiaSharpApiLeaseFeature)) as ISkiaSharpApiLeaseFeature;
using var lease = feature?.Lease();
report(lease?.GrContext?.Backend.ToString() ?? "Software");
}
}
}
+9 -7
View File
@@ -39,14 +39,16 @@ internal static class Program
if (OperatingSystem.IsMacOS())
{
builder = builder.With(new AvaloniaNativePlatformOptions
var renderer = Environment.GetEnvironmentVariable("STATICLINK_MAC_RENDERER");
if (!string.Equals(renderer, "default", StringComparison.OrdinalIgnoreCase))
{
RenderingMode =
[
AvaloniaNativeRenderingMode.OpenGl,
AvaloniaNativeRenderingMode.Software
]
});
builder = builder.With(new AvaloniaNativePlatformOptions
{
RenderingMode = string.Equals(renderer, "metal", StringComparison.OrdinalIgnoreCase)
? [AvaloniaNativeRenderingMode.Metal]
: [AvaloniaNativeRenderingMode.OpenGl, AvaloniaNativeRenderingMode.Software]
});
}
}
return builder;
+2 -2
View File
@@ -6,7 +6,7 @@ WORK_DIR="${WORK_DIR:-$ROOT_DIR/External/NativeStatic/.work}"
TARGET_CPU="${TARGET_CPU:-x64}"
RID="${RID:-linux-$TARGET_CPU}"
OUTPUT_DIR="${OUTPUT_DIR:-$ROOT_DIR/External/NativeStatic/$RID}"
SKIASHARP_VERSION="${SKIASHARP_VERSION:-3.119.4}"
SKIASHARP_VERSION="${SKIASHARP_VERSION:-4.150.1}"
ANGLE_BRANCH="${ANGLE_BRANCH:-7922}"
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
ANGLE_PATCH_DIR="${ANGLE_PATCH_DIR:-$ROOT_DIR/External/NativeStatic/patches}"
@@ -20,7 +20,7 @@ Usage: scripts/build-linux-static-graphics.sh [skia|angle|all]
Environment:
WORK_DIR Source/build cache directory. Default: External/NativeStatic/.work
OUTPUT_DIR Final static library directory. Default: External/NativeStatic/linux-$TARGET_CPU
SKIASHARP_VERSION SkiaSharp release branch version. Default: 3.119.4
SKIASHARP_VERSION SkiaSharp release branch version. Default: 4.150.1
ANGLE_BRANCH ANGLE chromium branch. Default: 7922
TARGET_CPU GN target_cpu. Default: x64. Supported: x64, arm64
RID Output RID. Default: linux-$TARGET_CPU
@@ -26,7 +26,12 @@ if git -C "$src" config -f .gitmodules --get-regexp path | grep -q 'external/Num
fi
if [[ ! -f "$src/native/Avalonia.Native/inc/avalonia-native.h" ]]; then
bash "$src/native/Avalonia.Native/generate-headers.sh"
header_project="$src/native/Avalonia.Native/Avalonia.Native.macOS.proj"
if [[ -f "$header_project" ]]; then
dotnet build "$header_project" -t:GenerateMicroComItems
else
bash "$src/native/Avalonia.Native/generate-headers.sh"
fi
fi
project="$src/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj"
+1 -1
View File
@@ -6,7 +6,7 @@ WORK_DIR="${WORK_DIR:-$ROOT_DIR/External/NativeStatic/.work}"
TARGET_CPU="${TARGET_CPU:-arm64}"
RID="${RID:-osx-$TARGET_CPU}"
OUTPUT_DIR="${OUTPUT_DIR:-$ROOT_DIR/External/NativeStatic/$RID}"
SKIASHARP_VERSION="${SKIASHARP_VERSION:-3.119.4}"
SKIASHARP_VERSION="${SKIASHARP_VERSION:-4.150.1}"
ANGLE_BRANCH="${ANGLE_BRANCH:-7922}"
BUILD_JOBS="${BUILD_JOBS:-$(sysctl -n hw.ncpu)}"
ANGLE_PATCH_DIR="${ANGLE_PATCH_DIR:-$ROOT_DIR/External/NativeStatic/patches}"
+20 -1
View File
@@ -7,7 +7,7 @@ $ErrorActionPreference = "Stop"
$RootDir = Split-Path -Parent $PSScriptRoot
$WorkDir = if ($env:WORK_DIR) { $env:WORK_DIR } else { Join-Path $RootDir "External\NativeStatic\.work" }
$SkiaSharpVersion = if ($env:SKIASHARP_VERSION) { $env:SKIASHARP_VERSION } else { "3.119.4" }
$SkiaSharpVersion = if ($env:SKIASHARP_VERSION) { $env:SKIASHARP_VERSION } else { "4.150.1" }
$AngleBranch = if ($env:ANGLE_BRANCH) { $env:ANGLE_BRANCH } else { "7922" }
$TargetCpu = if ($env:TARGET_CPU) { $env:TARGET_CPU } else { "x64" }
$Rid = if ($env:RID) { $env:RID } else { "win-$TargetCpu" }
@@ -353,6 +353,24 @@ function Sync-SkiaSharp {
return $src
}
function Patch-WinX86SkiaLinker($SkiaDir) {
if ($TargetCpu -ne "x86") {
return
}
$linkerPath = Join-Path $SkiaDir "src\c\sk_linker.cpp"
$text = Get-Content -Path $linkerPath -Raw
$pattern = '(?m)^ skjson::ObjectValue\* a = nullptr;\r?\n auto r = \(\*a\)\["tmp"\]\.getType\(\);\r?$'
$patched = [regex]::Replace($text, $pattern, ' int r = 0;')
if ($patched -eq $text) {
if ($text -match '(?m)^ int r = 0;\r?$') {
return
}
throw "Unable to patch win-x86 sk_linker JSON keep-alive references."
}
Set-Content -Path $linkerPath -Value $patched -NoNewline -Encoding UTF8
}
function Prepare-SkiaGitSyncDeps($SkiaDir) {
$syncDeps = Join-Path $SkiaDir "tools\git-sync-deps"
$text = Get-Content -Path $syncDeps -Raw
@@ -390,6 +408,7 @@ function Build-Skia {
Ensure-DepotTools
$src = Sync-SkiaSharp
$skiaDir = Join-Path $src "externals\skia"
Patch-WinX86SkiaLinker $skiaDir
if (-not (Test-Path (Join-Path $skiaDir "bin\gn.exe"))) {
Invoke-SkiaGitSyncDeps $skiaDir
}