Add macOS static AvaloniaNative experiment

This commit is contained in:
geruipu committed 2026-06-21 03:09:02 +08:00
1 parent 2db7a80ae6
commit b3dee2dd87
5 files changed
+261 -49

No files matched your search

@@ -0,0 +1,199 @@
name: macOS static AvaloniaNative experiment
on:
workflow_dispatch:
inputs:
publish_to_release:
description: Publish experimental artifacts to GitHub Release
required: true
default: true
type: boolean
permissions:
contents: write
jobs:
build-macos-native:
strategy:
fail-fast: false
matrix:
include:
- rid: osx-x64
runner: macos-14
target_cpu: x64
- rid: osx-arm64
runner: macos-latest
target_cpu: arm64
runs-on: ${{ matrix.runner }}
env:
RID: ${{ matrix.rid }}
TARGET_CPU: ${{ matrix.target_cpu }}
WORK_DIR: ${{ github.workspace }}/External/NativeStatic/.work
OUTPUT_DIR: ${{ github.workspace }}/External/NativeStatic/${{ matrix.rid }}/native
AVALONIA_VERSION: 11.3.14
steps:
- uses: actions/checkout@v4
- name: Build macOS static graphics libraries
run: bash ./scripts/build-macos-static-graphics.sh all
- name: Build static AvaloniaNative
run: bash ./scripts/build-macos-avalonia-native-static.sh
- name: List native outputs
run: find "External/NativeStatic/${{ matrix.rid }}/native" -maxdepth 1 -type f -print
- name: Upload macOS native libraries
uses: actions/upload-artifact@v4
with:
name: macos-static-native-${{ matrix.rid }}
path: External/NativeStatic/${{ matrix.rid }}/native/*
if-no-files-found: error
pack-experimental:
runs-on: ubuntu-latest
needs: build-macos-native
outputs:
package_version: ${{ steps.version.outputs.package_version }}
steps:
- uses: actions/checkout@v4
- name: Download macOS native libraries
uses: actions/download-artifact@v4
with:
pattern: macos-static-native-*
path: artifacts/native
- name: Stage native libraries
run: |
mkdir -p External/NativeStatic/osx-x64/native External/NativeStatic/osx-arm64/native
cp artifacts/native/macos-static-native-osx-x64/* External/NativeStatic/osx-x64/native/
cp artifacts/native/macos-static-native-osx-arm64/* External/NativeStatic/osx-arm64/native/
find External/NativeStatic/osx-x64/native External/NativeStatic/osx-arm64/native -maxdepth 1 -type f -print
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Compute experimental package version
id: version
run: |
version="3.119.2-7151.8-macavn.${GITHUB_RUN_NUMBER}"
echo "package_version=$version" >> "$GITHUB_OUTPUT"
echo "$version"
- name: Pack experimental NuGet package
run: |
dotnet pack NuGet/StaticGraphics/Shiroka.Avalonia.StaticLink.csproj \
-c Release \
-o artifacts/nuget \
/p:PackageVersion=${{ steps.version.outputs.package_version }} \
/p:Version=${{ steps.version.outputs.package_version }}
- name: Upload experimental NuGet package
uses: actions/upload-artifact@v4
with:
name: macos-static-avalonia-native-nuget
path: artifacts/nuget/*.nupkg
if-no-files-found: error
smoke-macos:
strategy:
fail-fast: false
matrix:
include:
- rid: osx-x64
runner: macos-14
- rid: osx-arm64
runner: macos-latest
runs-on: ${{ matrix.runner }}
needs: pack-experimental
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Download experimental NuGet package
uses: actions/download-artifact@v4
with:
name: macos-static-avalonia-native-nuget
path: artifacts/nuget
- name: Publish Avalonia smoke app
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$projectDir = Join-Path $PWD "artifacts/avalonia-smoke-src"
pwsh ./scripts/create-avalonia-smoke.ps1 `
-ProjectDir $projectDir `
-NuGetSource (Resolve-Path "artifacts/nuget") `
-StaticLinkVersion "${{ needs.pack-experimental.outputs.package_version }}"
dotnet publish (Join-Path $projectDir "AvaloniaStaticLinkSmoke.csproj") `
-c Release `
-r "${{ matrix.rid }}" `
--configfile (Join-Path $projectDir "NuGet.config") `
/p:PublishAot=true `
/p:SelfContained=true `
/p:PublishSingleFile=true `
/p:StripSymbols=true `
/p:PublishDir="$PWD/artifacts/smoke-${{ matrix.rid }}/"
- name: Verify static macOS output
shell: pwsh
run: |
$publishDir = "artifacts/smoke-${{ matrix.rid }}"
$blocked = Get-ChildItem -Path $publishDir -Recurse -File | Where-Object {
$_.Name -in @("libAvaloniaNative.dylib", "libHarfBuzzSharp.dylib", "libSkiaSharp.dylib")
}
if ($blocked) {
$blocked | ForEach-Object { Write-Error "Unexpected dynamic library: $($_.FullName)" }
exit 1
}
Get-ChildItem -Path $publishDir -Recurse -File | ForEach-Object { $_.FullName }
- name: Upload macOS smoke app
uses: actions/upload-artifact@v4
with:
name: macos-static-avalonia-native-smoke-${{ matrix.rid }}
path: artifacts/smoke-${{ matrix.rid }}/**
if-no-files-found: error
release:
runs-on: ubuntu-latest
needs:
- pack-experimental
- smoke-macos
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish_to_release == true }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: release-artifacts
- name: Prepare release files
run: |
mkdir -p release-files
find release-artifacts/macos-static-avalonia-native-nuget -type f -name '*.nupkg' -exec cp {} release-files/ \;
for dir in release-artifacts/macos-static-avalonia-native-smoke-*; do
[ -d "$dir" ] || continue
name="$(basename "$dir")"
(cd "$dir" && zip -r "../../release-files/$name.zip" .)
done
ls -la release-files
- name: Publish experimental GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
release_tag="macos-static-avalonia-native-${GITHUB_RUN_NUMBER}"
if gh release view "$release_tag" >/dev/null 2>&1; then
gh release upload "$release_tag" release-files/* --clobber
else
gh release create "$release_tag" release-files/* \
--title "macOS static AvaloniaNative ${GITHUB_RUN_NUMBER}" \
--notes "Experimental macOS NativeAOT package with SkiaSharp, HarfBuzzSharp, and AvaloniaNative statically linked."
fi
@@ -301,52 +301,6 @@ jobs:
}
Get-ChildItem -Path $publishDir -Recurse -File | ForEach-Object { $_.FullName }
- name: Bundle macOS smoke app
if: ${{ startsWith(matrix.rid, 'osx-') }}
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$publishDir = Resolve-Path "artifacts/smoke-${{ matrix.rid }}"
$bundleRoot = Join-Path $publishDir "AvaloniaStaticLinkSmoke.app"
$contentsDir = Join-Path $bundleRoot "Contents"
$macosDir = Join-Path $contentsDir "MacOS"
New-Item -ItemType Directory -Path $macosDir -Force | Out-Null
Get-ChildItem -Path $publishDir -Force | Where-Object { $_.Name -ne "AvaloniaStaticLinkSmoke.app" } | ForEach-Object {
Move-Item -LiteralPath $_.FullName -Destination $macosDir -Force
}
@"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>AvaloniaStaticLinkSmoke</string>
<key>CFBundleIdentifier</key>
<string>com.shiroka.avalonia-staticlink-smoke</string>
<key>CFBundleName</key>
<string>AvaloniaStaticLinkSmoke</string>
<key>CFBundleDisplayName</key>
<string>Avalonia StaticLink Smoke</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>${{ github.run_number }}</string>
<key>LSMinimumSystemVersion</key>
<string>12.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
"@ | Set-Content -Path (Join-Path $contentsDir "Info.plist") -Encoding UTF8
Get-ChildItem -Path $publishDir -Recurse -File | ForEach-Object { $_.FullName }
- name: Upload Avalonia smoke app
uses: actions/upload-artifact@v4
with:
@@ -6,7 +6,7 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>false</SuppressDependenciesWhenPacking>
<PackageId>Shiroka.Avalonia.StaticLink</PackageId>
<Version>3.119.2-7151.6</Version>
<Version>3.119.2-7151.7</Version>
<Authors>greepar</Authors>
<Company>greepar</Company>
<Description>Static SkiaSharp, HarfBuzzSharp, and ANGLE libraries for Avalonia NativeAOT single-file publishing.</Description>
@@ -49,21 +49,25 @@
</ItemGroup>
<ItemGroup Condition="'$(PublishAot)' == 'true' and ('$(RuntimeIdentifier)' == 'osx-x64' or '$(RuntimeIdentifier)' == 'osx-arm64') and '$(_ShirokaAvaloniaStaticLinkNativeRoot)' != ''">
<DirectPInvoke Include="libAvaloniaNative" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libAvaloniaNative.a')" />
<DirectPInvoke Include="libHarfBuzzSharp" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libHarfBuzzSharp.a')" />
<DirectPInvoke Include="libSkiaSharp" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libSkiaSharp.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libAvaloniaNative.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libAvaloniaNative.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libHarfBuzzSharp.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libHarfBuzzSharp.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libskia.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libskia.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libSkiaSharp.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libSkiaSharp.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libANGLE_static.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libANGLE_static.a')" />
<NativeLibrary Include="$(_ShirokaAvaloniaStaticLinkNativeRoot)/libGLESv2_static.a" Condition="Exists('$(_ShirokaAvaloniaStaticLinkNativeRoot)/libGLESv2_static.a')" />
<NativeSystemLibrary Include="c++" />
<LinkerArg Include="-framework AppKit" />
<LinkerArg Include="-framework Carbon" />
<LinkerArg Include="-framework CoreFoundation" />
<LinkerArg Include="-framework CoreGraphics" />
<LinkerArg Include="-framework CoreText" />
<LinkerArg Include="-framework Foundation" />
<LinkerArg Include="-framework IOSurface" />
<LinkerArg Include="-framework Metal" />
<LinkerArg Include="-framework OpenGL" />
<LinkerArg Include="-framework QuartzCore" />
<LinkerArg Include="-framework UniformTypeIdentifiers" />
</ItemGroup>
<Target Name="ShirokaAvaloniaStaticLinkDisableStaticExecutableOnApple"
@@ -89,6 +93,7 @@
<_ShirokaAvaloniaStaticLinkFilesToDelete Include="$(PublishDir)libSkiaSharp.so" />
<_ShirokaAvaloniaStaticLinkFilesToDelete Include="$(PublishDir)libHarfBuzzSharp.dylib" />
<_ShirokaAvaloniaStaticLinkFilesToDelete Include="$(PublishDir)libSkiaSharp.dylib" />
<_ShirokaAvaloniaStaticLinkFilesToDelete Include="$(PublishDir)libAvaloniaNative.dylib" />
</ItemGroup>
<Delete Files="@(_ShirokaAvaloniaStaticLinkFilesToDelete)" TreatErrorsAsWarnings="true" />
</Target>
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euo pipefail
RID="${RID:-osx-arm64}"
AVALONIA_VERSION="${AVALONIA_VERSION:-11.3.14}"
WORK_DIR="${WORK_DIR:-$PWD/External/NativeStatic/.work}"
OUTPUT_DIR="${OUTPUT_DIR:-$PWD/External/NativeStatic/$RID/native}"
BUILD_JOBS="${BUILD_JOBS:-$(sysctl -n hw.ncpu 2>/dev/null || echo 4)}"
case "$RID" in
osx-arm64) ARCH="arm64" ;;
osx-x64) ARCH="x86_64" ;;
*) echo "Unsupported RID: $RID" >&2; exit 2 ;;
esac
mkdir -p "$WORK_DIR" "$OUTPUT_DIR"
src="$WORK_DIR/Avalonia-$AVALONIA_VERSION"
if [[ ! -d "$src/.git" ]]; then
rm -rf "$src"
git clone --depth 1 --branch "$AVALONIA_VERSION" https://github.com/AvaloniaUI/Avalonia.git "$src"
fi
project="$src/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj"
build_dir="$WORK_DIR/avalonia-native-$RID"
rm -rf "$build_dir"
mkdir -p "$build_dir"
xcodebuild \
-project "$project" \
-target Avalonia.Native.OSX \
-configuration Release \
-sdk macosx \
-arch "$ARCH" \
CONFIGURATION_BUILD_DIR="$build_dir" \
ONLY_ACTIVE_ARCH=NO \
CODE_SIGNING_ALLOWED=NO \
MACH_O_TYPE=staticlib \
EXECUTABLE_PREFIX=lib \
EXECUTABLE_EXTENSION=a \
PRODUCT_NAME=AvaloniaNative \
CLANG_ENABLE_MODULES=YES \
GCC_GENERATE_DEBUGGING_SYMBOLS=NO \
-jobs "$BUILD_JOBS"
candidate="$(find "$build_dir" -maxdepth 2 -type f -name 'libAvaloniaNative.a' -print -quit)"
if [[ -z "$candidate" ]]; then
echo "Failed to find libAvaloniaNative.a in $build_dir" >&2
find "$build_dir" -maxdepth 3 -type f -print >&2
exit 1
fi
cp "$candidate" "$OUTPUT_DIR/libAvaloniaNative.a"
echo "Wrote $OUTPUT_DIR/libAvaloniaNative.a"