StaticLink.Avalonia baseline

This commit is contained in:
geruipu committed 2026-06-21 12:37:51 +08:00
commit ff4458d089
23 files changed
+2417

No files matched your search

+329
View File
@@ -0,0 +1,329 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
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.2}"
ANGLE_BRANCH="${ANGLE_BRANCH:-7151}"
BUILD_JOBS="${BUILD_JOBS:-$(nproc)}"
ANGLE_PATCH_DIR="${ANGLE_PATCH_DIR:-$ROOT_DIR/External/NativeStatic/patches}"
LLVM_AR="${LLVM_AR:-llvm-ar-19}"
SKIA_DEPS_RETRIES="${SKIA_DEPS_RETRIES:-3}"
usage() {
cat <<'USAGE'
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.2
ANGLE_BRANCH ANGLE chromium branch. Default: 7151
TARGET_CPU GN target_cpu. Default: x64. Supported: x64, arm64
RID Output RID. Default: linux-$TARGET_CPU
BUILD_JOBS Ninja parallelism. Default: nproc
ANGLE_PATCH_DIR ANGLE patch directory. Default: External/NativeStatic/patches
LLVM_AR llvm-ar command used to expand thin archives. Default: llvm-ar-19
USAGE
}
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
ensure_tools() {
require_cmd git
require_cmd python3
require_cmd clang
require_cmd clang++
require_cmd ar
require_cmd "$LLVM_AR"
require_cmd ninja
require_cmd pkg-config
}
ensure_depot_tools() {
local depot_dir="$WORK_DIR/depot_tools"
if [[ ! -d "$depot_dir/.git" ]]; then
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git "$depot_dir"
else
git -C "$depot_dir" pull --ff-only
fi
export PATH="$depot_dir:$PATH"
}
sync_skiasharp() {
local src="$WORK_DIR/SkiaSharp-$SKIASHARP_VERSION"
if [[ ! -d "$src/.git" ]]; then
git clone --depth 1 --branch "release/$SKIASHARP_VERSION" https://github.com/mono/SkiaSharp.git "$src"
else
git -C "$src" fetch --depth 1 origin "release/$SKIASHARP_VERSION"
git -C "$src" checkout -q FETCH_HEAD
fi
git -C "$src" submodule update --init --depth 1 externals/skia >&2
echo "$src"
}
prepare_skia_git_sync_deps() {
local sync_deps="$1/tools/git-sync-deps"
python3 - "$sync_deps" <<'PY'
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
text = path.read_text()
old = " multithread(git_checkout_to_directory, list_of_arg_lists)"
new = " for args in list_of_arg_lists:\n git_checkout_to_directory(*args)"
if old in text:
path.write_text(text.replace(old, new))
PY
}
sync_skia_deps() {
local skia_dir="$1/externals/skia"
if [[ ! -x "$skia_dir/bin/gn" ]]; then
prepare_skia_git_sync_deps "$skia_dir"
local attempt
for attempt in $(seq 1 "$SKIA_DEPS_RETRIES"); do
if python3 "$skia_dir/tools/git-sync-deps"; then
return 0
fi
if [[ "$attempt" == "$SKIA_DEPS_RETRIES" ]]; then
return 1
fi
echo "git-sync-deps failed; retrying ($attempt/$SKIA_DEPS_RETRIES)..." >&2
sleep 10
done
fi
}
build_skia() {
ensure_tools
ensure_depot_tools
local src
src="$(sync_skiasharp)"
sync_skia_deps "$src"
local skia_dir="$src/externals/skia"
local out_dir="$skia_dir/out/linux-static-$TARGET_CPU"
mkdir -p "$out_dir" "$OUTPUT_DIR"
cat >"$out_dir/args.gn" <<EOF_ARGS
target_os = "linux"
target_cpu = "$TARGET_CPU"
is_official_build = true
is_static_skiasharp = true
skia_enable_tools = false
skia_enable_ganesh = true
skia_enable_pdf = false
skia_enable_skottie = false
skia_use_dng_sdk = false
skia_use_fontconfig = true
skia_use_freetype = true
skia_use_harfbuzz = false
skia_use_icu = false
skia_use_piex = false
skia_use_sfntly = false
skia_use_system_expat = false
skia_use_system_freetype2 = false
skia_use_system_libjpeg_turbo = false
skia_use_system_libpng = false
skia_use_system_libwebp = false
skia_use_system_zlib = false
skia_use_vulkan = false
skia_use_xps = false
cc = "clang"
cxx = "clang++"
ar = "ar"
extra_cflags = [
"-DSKIA_C_DLL",
"-DHAVE_SYSCALL_GETRANDOM",
"-DXML_DEV_URANDOM",
]
extra_cflags_cc = [ "-frtti" ]
extra_ldflags = [ "-static-libstdc++", "-static-libgcc" ]
EOF_ARGS
(cd "$skia_dir" && "$skia_dir/bin/gn" gen "$out_dir")
ninja -C "$out_dir" -j "$BUILD_JOBS" skia SkiaSharp HarfBuzzSharp
copy_first_existing "$OUTPUT_DIR/libskia.a" \
"$out_dir/libskia.a" \
"$out_dir/obj/libskia.a"
copy_first_existing "$OUTPUT_DIR/libSkiaSharp.a" \
"$out_dir/libSkiaSharp.a" \
"$out_dir/obj/libSkiaSharp.a"
copy_first_existing "$OUTPUT_DIR/libHarfBuzzSharp.a" \
"$out_dir/libHarfBuzzSharp.a" \
"$out_dir/obj/libHarfBuzzSharp.a"
}
sync_angle() {
local src="$WORK_DIR/ANGLE-$ANGLE_BRANCH"
if [[ ! -d "$src/.git" ]]; then
git clone --depth 1 --branch "chromium/$ANGLE_BRANCH" https://github.com/google/angle.git "$src"
else
git -C "$src" fetch --depth 1 origin "chromium/$ANGLE_BRANCH"
git -C "$src" checkout -q FETCH_HEAD
fi
echo "$src"
}
build_angle() {
ensure_tools
ensure_depot_tools
local src
src="$(sync_angle)"
mkdir -p "$OUTPUT_DIR"
cd "$src"
apply_angle_patches "$src"
python3 scripts/bootstrap.py
gclient sync -f -D -R
local out_dir="$src/out/linux-static-$TARGET_CPU"
mkdir -p "$out_dir"
cat >"$out_dir/args.gn" <<EOF_ARGS
target_os = "linux"
target_cpu = "$TARGET_CPU"
is_debug = false
is_component_build = false
is_clang = false
treat_warnings_as_errors = false
use_custom_libcxx = false
use_sysroot = false
use_lld = false
use_thin_lto = false
symbol_level = 0
angle_build_tests = false
build_angle_deqp_tests = false
angle_enable_swiftshader = false
angle_enable_vulkan = false
angle_enable_wgpu = false
EOF_ARGS
gn gen "$out_dir"
ninja -C "$out_dir" -j "$BUILD_JOBS" libANGLE_static libGLESv2_static
copy_full_archive_from_thin "$out_dir" "$OUTPUT_DIR/libANGLE_static.a" \
"$out_dir/obj/libANGLE_static.a" \
"$out_dir/obj/libANGLE_static/libANGLE_static.a" \
"$out_dir/libANGLE_static.a"
copy_full_archive_from_thin "$out_dir" "$OUTPUT_DIR/libGLESv2_static.a" \
"$out_dir/obj/libGLESv2_static.a" \
"$out_dir/obj/libGLESv2_static/libGLESv2_static.a" \
"$out_dir/libGLESv2_static.a"
}
apply_angle_patches() {
local src="$1"
local build_patch="$ANGLE_PATCH_DIR/angle-chromium-$ANGLE_BRANCH.patch"
local deps_patch="$ANGLE_PATCH_DIR/angle-chromium-$ANGLE_BRANCH-deps.patch"
if ! git -C "$src" grep -q 'angle_static_library("libANGLE_static")' -- BUILD.gn; then
python3 - "$src/BUILD.gn" <<'PY'
import pathlib
import re
import sys
path = pathlib.Path(sys.argv[1])
text = path.read_text()
targets = '''angle_static_library("libANGLE_static") {
complete_static_lib = true
public_deps = [ ":libANGLE" ]
}
angle_static_library("libANGLE_with_capture_static") {
complete_static_lib = true
public_deps = [ ":libANGLE_with_capture" ]
}
angle_static_library("libGLESv2_static") {
'''
text = re.sub(r'^angle_static_library\("libGLESv2_static"\) \{', targets, text, count=1, flags=re.M)
text = re.sub(r'^angle_static_library\("libGLESv2_static"\) \{\n sources = libglesv2_sources', 'angle_static_library("libGLESv2_static") {\n complete_static_lib = true\n sources = libglesv2_sources', text, count=1, flags=re.M)
path.write_text(text)
PY
fi
if [[ -f "$build_patch" ]] && git -C "$src" grep -q "'third_party/catapult'" -- DEPS; then
git -C "$src" apply "$build_patch"
elif [[ -f "$deps_patch" ]] && ! git -C "$src" apply --check "$deps_patch" >/dev/null 2>&1; then
:
elif [[ -f "$deps_patch" ]]; then
git -C "$src" apply "$deps_patch"
fi
}
copy_first_existing() {
local dest="$1"
shift
for src in "$@"; do
if [[ -f "$src" ]]; then
cp "$src" "$dest"
echo "Wrote $dest"
return 0
fi
done
echo "None of the expected files exist for $dest:" >&2
printf ' %s\n' "$@" >&2
return 1
}
copy_full_archive_from_thin() {
local base_dir="$1"
local dest="$2"
shift 2
local src
for src in "$@"; do
if [[ -f "$src" ]]; then
if [[ "$(head -c 7 "$src")" == "!<thin>" ]]; then
local tmp="$dest.tmp"
local rel_src="${src#$base_dir/}"
(
cd "$base_dir"
mapfile -t members < <("$LLVM_AR" t "$rel_src")
"$LLVM_AR" rcs "$tmp" "${members[@]}"
)
mv "$tmp" "$dest"
else
cp "$src" "$dest"
fi
echo "Wrote $dest"
return 0
fi
done
echo "None of the expected files exist for $dest:" >&2
printf ' %s\n' "$@" >&2
return 1
}
main() {
mkdir -p "$WORK_DIR" "$OUTPUT_DIR"
case "${1:-all}" in
skia) build_skia ;;
angle) build_angle ;;
all)
build_skia
build_angle
;;
-h|--help|help)
usage
;;
*)
usage >&2
exit 1
;;
esac
}
main "$@"
@@ -0,0 +1,64 @@
#!/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
if git -C "$src" config -f .gitmodules --get-regexp path | grep -q 'external/Numerge' && [[ ! -d "$src/external/Numerge/.git" ]]; then
git -C "$src" submodule update --init --depth 1 external/Numerge
fi
if [[ ! -f "$src/native/Avalonia.Native/inc/avalonia-native.h" ]]; then
bash "$src/native/Avalonia.Native/generate-headers.sh"
fi
project="$src/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj"
include_dir="$src/native/Avalonia.Native/inc"
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 \
HEADER_SEARCH_PATHS="$include_dir" \
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"
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
RID="${RID:-osx-arm64}"
OUTPUT_DIR="${OUTPUT_DIR:-$PWD/External/NativeStatic/$RID/native}"
case "$RID" in
osx-arm64) ARCH="arm64" ;;
osx-x64) ARCH="x86_64" ;;
*) echo "Unsupported RID: $RID" >&2; exit 2 ;;
esac
mkdir -p "$OUTPUT_DIR"
src="$OUTPUT_DIR/macos_font_preinit.m"
cat > "$src" <<'OBJC'
#import <AppKit/AppKit.h>
#import <objc/message.h>
#import <objc/runtime.h>
__attribute__((constructor(101)))
static void StaticLinkAvaloniaPreinitializeAppKitFonts(void)
{
@autoreleasepool
{
[NSApplication sharedApplication];
[NSFont systemFontOfSize:13.0];
((id (*)(id, SEL, CGFloat, CGFloat))objc_msgSend)([NSFont class], sel_registerName("systemFontOfSize:width:"), 13.0, 0.0);
}
}
OBJC
clang -arch "$ARCH" \
-mmacosx-version-min=12.0 \
-fobjc-arc \
-c "$src" \
-o "$OUTPUT_DIR/macos_font_preinit.o"
rm -f "$src"
echo "Wrote $OUTPUT_DIR/macos_font_preinit.o"
+240
View File
@@ -0,0 +1,240 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
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.2}"
ANGLE_BRANCH="${ANGLE_BRANCH:-7151}"
BUILD_JOBS="${BUILD_JOBS:-$(sysctl -n hw.ncpu)}"
ANGLE_PATCH_DIR="${ANGLE_PATCH_DIR:-$ROOT_DIR/External/NativeStatic/patches}"
SKIA_DEPS_RETRIES="${SKIA_DEPS_RETRIES:-3}"
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
ensure_tools() {
require_cmd git
require_cmd python3
require_cmd clang
require_cmd clang++
require_cmd ar
require_cmd ninja
}
ensure_depot_tools() {
local depot_dir="$WORK_DIR/depot_tools"
if [[ ! -d "$depot_dir/.git" ]]; then
git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git "$depot_dir"
else
git -C "$depot_dir" pull --ff-only
fi
export PATH="$depot_dir:$PATH"
}
copy_first_existing() {
local dest="$1"
shift
for src in "$@"; do
if [[ -f "$src" ]]; then
cp "$src" "$dest"
echo "Wrote $dest"
return 0
fi
done
echo "None of the expected files exist for $dest:" >&2
printf ' %s\n' "$@" >&2
return 1
}
sync_skiasharp() {
local src="$WORK_DIR/SkiaSharp-$SKIASHARP_VERSION"
if [[ ! -d "$src/.git" ]]; then
git clone --depth 1 --branch "release/$SKIASHARP_VERSION" https://github.com/mono/SkiaSharp.git "$src"
else
git -C "$src" fetch --depth 1 origin "release/$SKIASHARP_VERSION"
git -C "$src" checkout -q FETCH_HEAD
fi
git -C "$src" submodule update --init --depth 1 externals/skia >&2
echo "$src"
}
prepare_skia_git_sync_deps() {
local sync_deps="$1/tools/git-sync-deps"
python3 - "$sync_deps" <<'PY'
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
text = path.read_text()
old = " multithread(git_checkout_to_directory, list_of_arg_lists)"
new = " for args in list_of_arg_lists:\n git_checkout_to_directory(*args)"
if old in text:
path.write_text(text.replace(old, new))
PY
}
sync_skia_deps() {
local skia_dir="$1"
prepare_skia_git_sync_deps "$skia_dir"
local attempt
for attempt in $(seq 1 "$SKIA_DEPS_RETRIES"); do
if python3 "$skia_dir/tools/git-sync-deps"; then
return 0
fi
if [[ "$attempt" == "$SKIA_DEPS_RETRIES" ]]; then
return 1
fi
echo "git-sync-deps failed; retrying ($attempt/$SKIA_DEPS_RETRIES)..." >&2
sleep 10
done
}
build_skia() {
ensure_tools
ensure_depot_tools
local src
src="$(sync_skiasharp)"
local skia_dir="$src/externals/skia"
if [[ ! -x "$skia_dir/bin/gn" ]]; then
sync_skia_deps "$skia_dir"
fi
local out_dir="$skia_dir/out/mac-static-$TARGET_CPU"
mkdir -p "$out_dir" "$OUTPUT_DIR"
cat >"$out_dir/args.gn" <<EOF_ARGS
target_os = "mac"
target_cpu = "$TARGET_CPU"
is_official_build = true
is_static_skiasharp = true
skia_enable_tools = false
skia_enable_ganesh = true
skia_enable_pdf = false
skia_enable_skottie = false
skia_use_dng_sdk = false
skia_use_fontconfig = false
skia_use_freetype = false
skia_use_harfbuzz = false
skia_use_icu = false
skia_use_piex = false
skia_use_sfntly = false
skia_use_system_expat = false
skia_use_system_libjpeg_turbo = false
skia_use_system_libpng = false
skia_use_system_libwebp = false
skia_use_system_zlib = false
skia_use_vulkan = false
skia_use_xps = false
cc = "clang"
cxx = "clang++"
ar = "ar"
extra_cflags = [ "-DSKIA_C_DLL" ]
extra_cflags_cc = [ "-frtti" ]
EOF_ARGS
(cd "$skia_dir" && "$skia_dir/bin/gn" gen "$out_dir")
ninja -C "$out_dir" -j "$BUILD_JOBS" skia SkiaSharp HarfBuzzSharp
copy_first_existing "$OUTPUT_DIR/libskia.a" "$out_dir/libskia.a" "$out_dir/obj/libskia.a"
copy_first_existing "$OUTPUT_DIR/libSkiaSharp.a" "$out_dir/libSkiaSharp.a" "$out_dir/obj/libSkiaSharp.a"
copy_first_existing "$OUTPUT_DIR/libHarfBuzzSharp.a" "$out_dir/libHarfBuzzSharp.a" "$out_dir/obj/libHarfBuzzSharp.a"
}
sync_angle() {
local src="$WORK_DIR/ANGLE-$ANGLE_BRANCH"
if [[ ! -d "$src/.git" ]]; then
git clone --depth 1 --branch "chromium/$ANGLE_BRANCH" https://github.com/google/angle.git "$src"
else
git -C "$src" fetch --depth 1 origin "chromium/$ANGLE_BRANCH"
git -C "$src" checkout -q FETCH_HEAD
fi
echo "$src"
}
apply_angle_patches() {
local src="$1"
local patch="$ANGLE_PATCH_DIR/angle-chromium-$ANGLE_BRANCH.patch"
if ! git -C "$src" grep -q 'angle_static_library("libANGLE_static")' -- BUILD.gn; then
python3 - "$src/BUILD.gn" <<'PY'
import pathlib
import re
import sys
path = pathlib.Path(sys.argv[1])
text = path.read_text()
targets = '''angle_static_library("libANGLE_static") {
complete_static_lib = true
public_deps = [ ":libANGLE" ]
}
angle_static_library("libANGLE_with_capture_static") {
complete_static_lib = true
public_deps = [ ":libANGLE_with_capture" ]
}
angle_static_library("libGLESv2_static") {
'''
text = re.sub(r'^angle_static_library\("libGLESv2_static"\) \{', targets, text, count=1, flags=re.M)
text = re.sub(r'^angle_static_library\("libGLESv2_static"\) \{\n sources = libglesv2_sources', 'angle_static_library("libGLESv2_static") {\n complete_static_lib = true\n sources = libglesv2_sources', text, count=1, flags=re.M)
path.write_text(text)
PY
fi
if [[ -f "$patch" ]] && git -C "$src" grep -q "'third_party/catapult'" -- DEPS; then
git -C "$src" apply "$patch"
fi
}
build_angle() {
ensure_tools
ensure_depot_tools
local src
src="$(sync_angle)"
mkdir -p "$OUTPUT_DIR"
apply_angle_patches "$src"
cd "$src"
python3 scripts/bootstrap.py
gclient sync -f -D -R
local out_dir="$src/out/mac-static-$TARGET_CPU"
mkdir -p "$out_dir"
cat >"$out_dir/args.gn" <<EOF_ARGS
target_os = "mac"
target_cpu = "$TARGET_CPU"
is_debug = false
is_component_build = false
is_clang = true
use_lld = false
use_thin_lto = false
symbol_level = 0
angle_build_tests = false
build_angle_deqp_tests = false
angle_enable_swiftshader = false
angle_enable_vulkan = false
angle_enable_wgpu = false
EOF_ARGS
gn gen "$out_dir"
ninja -C "$out_dir" -j "$BUILD_JOBS" libANGLE_static libGLESv2_static
copy_first_existing "$OUTPUT_DIR/libANGLE_static.a" "$out_dir/libANGLE_static.a" "$out_dir/obj/libANGLE_static.a" "$out_dir/obj/libANGLE_static/libANGLE_static.a"
copy_first_existing "$OUTPUT_DIR/libGLESv2_static.a" "$out_dir/libGLESv2_static.a" "$out_dir/obj/libGLESv2_static.a" "$out_dir/obj/libGLESv2_static/libGLESv2_static.a"
}
main() {
mkdir -p "$WORK_DIR" "$OUTPUT_DIR"
case "${1:-all}" in
skia) build_skia ;;
angle) build_angle ;;
all) build_skia; build_angle ;;
*) echo "Usage: scripts/build-macos-static-graphics.sh [skia|angle|all]" >&2; exit 1 ;;
esac
}
main "$@"
+290
View File
@@ -0,0 +1,290 @@
param(
[ValidateSet("skia", "angle", "angle-preflight", "all")]
[string]$Target = "all"
)
$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.2" }
$AngleBranch = if ($env:ANGLE_BRANCH) { $env:ANGLE_BRANCH } else { "7151" }
$TargetCpu = if ($env:TARGET_CPU) { $env:TARGET_CPU } else { "x64" }
$Rid = if ($env:RID) { $env:RID } else { "win-$TargetCpu" }
$OutputDir = if ($env:OUTPUT_DIR) { $env:OUTPUT_DIR } else { Join-Path $RootDir "External\NativeStatic\$Rid" }
$BuildJobs = if ($env:BUILD_JOBS) { $env:BUILD_JOBS } else { [Environment]::ProcessorCount }
$AnglePatchDir = if ($env:ANGLE_PATCH_DIR) { $env:ANGLE_PATCH_DIR } else { Join-Path $RootDir "External\NativeStatic\patches" }
$SkiaDepsRetries = if ($env:SKIA_DEPS_RETRIES) { [int]$env:SKIA_DEPS_RETRIES } else { 3 }
if (-not $env:DEPOT_TOOLS_WIN_TOOLCHAIN) {
$env:DEPOT_TOOLS_WIN_TOOLCHAIN = "0"
}
if ($env:DEPOT_TOOLS_WIN_TOOLCHAIN -eq "0") {
if (-not $env:GYP_MSVS_VERSION) {
$env:GYP_MSVS_VERSION = "17.0"
}
if (-not $env:GYP_MSVS_OVERRIDE_PATH) {
if ($env:VSINSTALLDIR) {
$env:GYP_MSVS_OVERRIDE_PATH = $env:VSINSTALLDIR.TrimEnd("\", "/")
} else {
$vswhere = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vswhere) {
$vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($vsPath) {
$env:GYP_MSVS_OVERRIDE_PATH = $vsPath.TrimEnd("\", "/")
}
}
}
}
}
function Require-Command($Name) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "Missing required command: $Name"
}
}
function Ensure-Tools {
Require-Command git
Require-Command python
Require-Command ninja
git config --global core.longpaths true
}
function Ensure-DepotTools {
$depotDir = Join-Path $WorkDir "depot_tools"
if (-not (Test-Path (Join-Path $depotDir ".git"))) {
$null = git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git $depotDir
} else {
$null = git -C $depotDir pull --ff-only
}
$env:PATH = "$depotDir;$env:PATH"
}
function Copy-FirstExisting($Destination, [string[]]$Candidates) {
foreach ($candidate in $Candidates) {
if (Test-Path $candidate) {
Copy-Item $candidate $Destination -Force
Write-Host "Wrote $Destination"
return
}
}
throw "None of the expected files exist for ${Destination}: $($Candidates -join ', ')"
}
function Sync-SkiaSharp {
$src = Join-Path $WorkDir "SkiaSharp-$SkiaSharpVersion"
if (-not (Test-Path (Join-Path $src ".git"))) {
$null = git -c core.longpaths=true clone --depth 1 --branch "release/$SkiaSharpVersion" https://github.com/mono/SkiaSharp.git $src
} else {
$null = git -C $src fetch --depth 1 origin "release/$SkiaSharpVersion"
$null = git -C $src checkout -q FETCH_HEAD
}
$null = git -C $src submodule update --init --depth 1 externals/skia
return $src
}
function Prepare-SkiaGitSyncDeps($SkiaDir) {
$syncDeps = Join-Path $SkiaDir "tools\git-sync-deps"
$text = Get-Content -Path $syncDeps -Raw
$old = " multithread(git_checkout_to_directory, list_of_arg_lists)"
$new = " for args in list_of_arg_lists:`n git_checkout_to_directory(*args)"
if ($text.Contains($old)) {
Set-Content -Path $syncDeps -Value $text.Replace($old, $new) -NoNewline -Encoding UTF8
}
}
function Invoke-SkiaGitSyncDeps($SkiaDir) {
Prepare-SkiaGitSyncDeps $SkiaDir
for ($attempt = 1; $attempt -le $SkiaDepsRetries; $attempt++) {
python (Join-Path $SkiaDir "tools\git-sync-deps")
if ($LASTEXITCODE -eq 0) {
return
}
if ($attempt -eq $SkiaDepsRetries) {
throw "git-sync-deps failed after $SkiaDepsRetries attempts"
}
Write-Warning "git-sync-deps failed; retrying ($attempt/$SkiaDepsRetries)..."
Start-Sleep -Seconds 10
}
}
function Build-Skia {
Ensure-Tools
Ensure-DepotTools
$src = Sync-SkiaSharp
$skiaDir = Join-Path $src "externals\skia"
if (-not (Test-Path (Join-Path $skiaDir "bin\gn.exe"))) {
Invoke-SkiaGitSyncDeps $skiaDir
}
$outDir = Join-Path $skiaDir "out\win-static-$TargetCpu"
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
@"
target_os = "win"
target_cpu = "$TargetCpu"
is_official_build = true
is_static_skiasharp = true
is_clang = true
skia_enable_tools = false
skia_enable_ganesh = true
skia_enable_pdf = false
skia_enable_skottie = false
skia_use_dng_sdk = false
skia_use_fontconfig = false
skia_use_freetype = false
skia_use_harfbuzz = false
skia_use_icu = false
skia_use_piex = false
skia_use_sfntly = false
skia_use_system_expat = false
skia_use_system_freetype2 = false
skia_use_system_libjpeg_turbo = false
skia_use_system_libpng = false
skia_use_system_libwebp = false
skia_use_system_zlib = false
skia_use_vulkan = false
skia_use_xps = false
extra_cflags = [ "-DSKIA_C_DLL" ]
extra_cflags_cc = [ "/GR" ]
"@ | Set-Content -Path (Join-Path $outDir "args.gn") -Encoding ASCII
Push-Location $skiaDir
try {
& (Join-Path $skiaDir "bin\gn.exe") gen $outDir
ninja -C $outDir -j $BuildJobs skia SkiaSharp HarfBuzzSharp
} finally {
Pop-Location
}
Copy-FirstExisting (Join-Path $OutputDir "skia.lib") @((Join-Path $outDir "skia.lib"), (Join-Path $outDir "obj\skia.lib"))
Copy-FirstExisting (Join-Path $OutputDir "SkiaSharp.lib") @((Join-Path $outDir "SkiaSharp.lib"), (Join-Path $outDir "obj\SkiaSharp.lib"))
Copy-FirstExisting (Join-Path $OutputDir "libHarfBuzzSharp.lib") @(
(Join-Path $outDir "libHarfBuzzSharp.lib"),
(Join-Path $outDir "HarfBuzzSharp.lib"),
(Join-Path $outDir "obj\libHarfBuzzSharp.lib"),
(Join-Path $outDir "obj\HarfBuzzSharp.lib"),
(Join-Path $outDir "obj\HarfBuzzSharp\libHarfBuzzSharp.lib"),
(Join-Path $outDir "obj\HarfBuzzSharp\HarfBuzzSharp.lib")
)
}
function Sync-Angle {
$src = Join-Path $WorkDir "ANGLE-$AngleBranch"
if (-not (Test-Path (Join-Path $src ".git"))) {
$null = git -c core.longpaths=true clone --depth 1 --branch "chromium/$AngleBranch" https://github.com/google/angle.git $src
} else {
$null = git -C $src fetch --depth 1 origin "chromium/$AngleBranch"
$null = git -C $src checkout -q FETCH_HEAD
}
return $src
}
function Apply-AnglePatches($Src) {
$buildFile = Join-Path $Src "BUILD.gn"
$buildText = Get-Content -Path $buildFile -Raw
if (-not $buildText.Contains('angle_static_library("libANGLE_static")')) {
$libAngleTargets = @'
angle_static_library("libANGLE_static") {
complete_static_lib = true
public_deps = [ ":libANGLE" ]
}
angle_static_library("libANGLE_with_capture_static") {
complete_static_lib = true
public_deps = [ ":libANGLE_with_capture" ]
}
angle_static_library("libGLESv2_static") {
'@
$buildText = [regex]::Replace($buildText, '(?m)^angle_static_library\("libGLESv2_static"\) \{', $libAngleTargets)
$buildText = [regex]::Replace($buildText, '(?m)^angle_static_library\("libGLESv2_static"\) \{\r?\n sources = libglesv2_sources', "angle_static_library(`"libGLESv2_static`") {`n complete_static_lib = true`n sources = libglesv2_sources")
Set-Content -Path $buildFile -Value $buildText -NoNewline -Encoding UTF8
}
$patch = Join-Path $AnglePatchDir "angle-chromium-$AngleBranch.patch"
$depsFile = Join-Path $Src "DEPS"
if ((Test-Path $patch) -and (Select-String -Path $depsFile -Pattern "'third_party/catapult'" -Quiet)) {
$null = git -C $Src apply $patch
if ($LASTEXITCODE -ne 0) {
throw "Failed to apply ANGLE patch: $patch"
}
}
}
function Assert-AngleVisualStudioVersion {
if ($env:VisualStudioVersion -and -not ($env:VisualStudioVersion -in @("17.0", "16.0", "15.0"))) {
throw "ANGLE $AngleBranch requires Visual Studio 2022/2019/2017, but VisualStudioVersion is $env:VisualStudioVersion. Use windows-2022 or a VS 2022 developer prompt."
}
if ($env:GYP_MSVS_OVERRIDE_PATH -and ($env:GYP_MSVS_OVERRIDE_PATH -match '\\Microsoft Visual Studio\\18\\')) {
throw "ANGLE $AngleBranch requires Visual Studio 2022/2019/2017, but GYP_MSVS_OVERRIDE_PATH points to $env:GYP_MSVS_OVERRIDE_PATH. Use windows-2022 or a VS 2022 developer prompt."
}
}
function Test-AnglePatch {
Require-Command git
Assert-AngleVisualStudioVersion
$src = Sync-Angle
Apply-AnglePatches $src
if (-not (Select-String -Path (Join-Path $src "BUILD.gn") -Pattern 'angle_static_library\("libANGLE_static"\)' -Quiet)) {
throw "ANGLE BUILD.gn preflight failed."
}
Write-Host "ANGLE preflight passed."
}
function Build-Angle {
Ensure-Tools
Assert-AngleVisualStudioVersion
Ensure-DepotTools
$src = Sync-Angle
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
Apply-AnglePatches $src
Push-Location $src
try {
python scripts/bootstrap.py
gclient sync -f -D -R
$outDir = Join-Path $src "out\win-static-$TargetCpu"
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
@"
target_os = "win"
target_cpu = "$TargetCpu"
is_debug = false
is_component_build = false
is_clang = true
use_lld = false
use_custom_libcxx = false
use_thin_lto = false
symbol_level = 0
angle_build_tests = false
build_angle_deqp_tests = false
angle_enable_swiftshader = false
angle_enable_vulkan = false
angle_enable_wgpu = false
"@ | Set-Content -Path (Join-Path $outDir "args.gn") -Encoding ASCII
gn gen $outDir
ninja -C $outDir -j $BuildJobs libANGLE_static libGLESv2_static
Copy-FirstExisting (Join-Path $OutputDir "libANGLE_static.lib") @((Join-Path $outDir "libANGLE_static.lib"), (Join-Path $outDir "obj\libANGLE_static.lib"), (Join-Path $outDir "obj\libANGLE_static\libANGLE_static.lib"))
Copy-FirstExisting (Join-Path $OutputDir "libGLESv2_static.lib") @((Join-Path $outDir "libGLESv2_static.lib"), (Join-Path $outDir "obj\libGLESv2_static.lib"), (Join-Path $outDir "obj\libGLESv2_static\libGLESv2_static.lib"))
foreach ($libcxxName in @("libc++.lib", "libc++abi.lib")) {
$libcxxPath = Join-Path $src "third_party\llvm-build\Release+Asserts\lib\$libcxxName"
if (Test-Path $libcxxPath) {
Copy-Item $libcxxPath (Join-Path $OutputDir $libcxxName) -Force
Write-Host "Wrote $(Join-Path $OutputDir $libcxxName)"
}
}
} finally {
Pop-Location
}
}
New-Item -ItemType Directory -Path $WorkDir -Force | Out-Null
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
switch ($Target) {
"skia" { Build-Skia }
"angle-preflight" { Test-AnglePatch }
"angle" { Build-Angle }
"all" { Build-Skia; Build-Angle }
}
+154
View File
@@ -0,0 +1,154 @@
param(
[Parameter(Mandatory = $true)]
[string]$ProjectDir,
[Parameter(Mandatory = $true)]
[string]$NuGetSource,
[Parameter(Mandatory = $true)]
[string]$StaticLinkVersion,
[string]$AvaloniaVersion = "11.3.14",
[string]$StaticLinkNativeVersion = ""
)
$ErrorActionPreference = "Stop"
New-Item -ItemType Directory -Path $ProjectDir -Force | Out-Null
$nativeReference = ""
if ($StaticLinkNativeVersion) {
$nativeReference = "`n <PackageReference Include=`"StaticLink.Avalonia.Native`" Version=`"$StaticLinkNativeVersion`" />"
}
@"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="local-staticlink" value="$NuGetSource" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
"@ | Set-Content -Path (Join-Path $ProjectDir "NuGet.config") -Encoding UTF8
@"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<PublishAot>true</PublishAot>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>false</PublishReadyToRun>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$AvaloniaVersion" />
<PackageReference Include="Avalonia.Desktop" Version="$AvaloniaVersion" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$AvaloniaVersion" />
<PackageReference Include="StaticLink.Avalonia" Version="$StaticLinkVersion" />$nativeReference
</ItemGroup>
</Project>
"@ | Set-Content -Path (Join-Path $ProjectDir "AvaloniaStaticLinkSmoke.csproj") -Encoding UTF8
@"
using Avalonia;
namespace AvaloniaStaticLinkSmoke;
internal static class Program
{
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
public static AppBuilder BuildAvaloniaApp()
{
var builder = AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
if (OperatingSystem.IsMacOS())
{
builder = builder.With(new AvaloniaNativePlatformOptions
{
RenderingMode = [AvaloniaNativeRenderingMode.Software]
});
}
return builder;
}
}
"@ | Set-Content -Path (Join-Path $ProjectDir "Program.cs") -Encoding UTF8
@"
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace AvaloniaStaticLinkSmoke;
public sealed partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}
"@ | Set-Content -Path (Join-Path $ProjectDir "App.axaml.cs") -Encoding UTF8
@"
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaStaticLinkSmoke.App">
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
"@ | Set-Content -Path (Join-Path $ProjectDir "App.axaml") -Encoding UTF8
@"
using Avalonia.Controls;
namespace AvaloniaStaticLinkSmoke;
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
"@ | Set-Content -Path (Join-Path $ProjectDir "MainWindow.axaml.cs") -Encoding UTF8
@"
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaStaticLinkSmoke.MainWindow"
Width="420"
Height="220"
Title="Avalonia StaticLink Smoke">
<Border Padding="24">
<StackPanel Spacing="8" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Avalonia $AvaloniaVersion" FontSize="24" FontWeight="SemiBold" HorizontalAlignment="Center" />
<TextBlock Text="StaticLink NativeAOT smoke publish" HorizontalAlignment="Center" />
</StackPanel>
</Border>
</Window>
"@ | Set-Content -Path (Join-Path $ProjectDir "MainWindow.axaml") -Encoding UTF8