|
@@ -14,25 +14,27 @@ $coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core
|
|
|
# Load the .csproj file as XML
|
|
|
[xml]$coreCsproj = Get-Content $coreProjectPath
|
|
|
|
|
|
-# Define the package reference to replace
|
|
|
-$packageRefX64 = "Magick.NET-Q8-x64"
|
|
|
-$packageRefArm64 = "Magick.NET-Q8-arm64"
|
|
|
+# Define the package reference to replace based on the platform
|
|
|
+if ($Platform -eq "arm64") {
|
|
|
+ $packageRef = "Magick.NET-Q8-OpenMP-arm64"
|
|
|
+} else {
|
|
|
+ $packageRef = "Magick.NET-Q8-OpenMP-x64"
|
|
|
+}
|
|
|
|
|
|
-# Find the Magick.NET package reference and update it based on the platform
|
|
|
-$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -eq $packageRefX64 -or $_.Include -eq $packageRefArm64 }
|
|
|
+# Find the Magick.NET package reference and update it
|
|
|
+$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -like "Magick.NET-Q8*" }
|
|
|
if ($packageNodes) {
|
|
|
foreach ($packageNode in $packageNodes) {
|
|
|
- if ($Platform -eq "arm64") {
|
|
|
- $packageNode.Include = $packageRefArm64
|
|
|
- } else {
|
|
|
- $packageNode.Include = $packageRefX64
|
|
|
- }
|
|
|
+ $packageNode.Include = $packageRef
|
|
|
}
|
|
|
+
|
|
|
+ # Save the updated .csproj file
|
|
|
+ $coreCsproj.Save($coreProjectPath)
|
|
|
+ Write-Host "Updated Magick.NET package reference to $packageRef"
|
|
|
+} else {
|
|
|
+ Write-Host "Warning: No Magick.NET package reference found to update"
|
|
|
}
|
|
|
|
|
|
-# Save the updated .csproj file
|
|
|
-$coreCsproj.Save($coreProjectPath)
|
|
|
-
|
|
|
# Define the project path for the actual build target
|
|
|
$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj"
|
|
|
|
|
@@ -40,12 +42,18 @@ $avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.
|
|
|
$tempBuildPath = Join-Path -Path $outputPath -ChildPath "temp"
|
|
|
New-Item -ItemType Directory -Force -Path $tempBuildPath
|
|
|
|
|
|
+# Run dotnet restore to ensure we have the updated packages
|
|
|
+Write-Host "Restoring packages for $avaloniaProjectPath..."
|
|
|
+dotnet restore $avaloniaProjectPath
|
|
|
+
|
|
|
# Run dotnet publish for the Avalonia project
|
|
|
+Write-Host "Publishing project for osx-$Platform..."
|
|
|
dotnet publish $avaloniaProjectPath `
|
|
|
--runtime "osx-$Platform" `
|
|
|
--self-contained true `
|
|
|
--configuration Release `
|
|
|
-p:PublishSingleFile=false `
|
|
|
+ -p:MagickCopyNativeMacOS=true `
|
|
|
--output $tempBuildPath
|
|
|
|
|
|
# Create .app bundle structure
|
|
@@ -53,13 +61,15 @@ $appBundlePath = Join-Path -Path $outputPath -ChildPath "PicView.app"
|
|
|
$contentsPath = Join-Path -Path $appBundlePath -ChildPath "Contents"
|
|
|
$macOSPath = Join-Path -Path $contentsPath -ChildPath "MacOS"
|
|
|
$resourcesPath = Join-Path -Path $contentsPath -ChildPath "Resources"
|
|
|
+$frameworksPath = Join-Path -Path $contentsPath -ChildPath "Frameworks"
|
|
|
|
|
|
# Create directory structure
|
|
|
New-Item -ItemType Directory -Force -Path $macOSPath
|
|
|
New-Item -ItemType Directory -Force -Path $resourcesPath
|
|
|
+New-Item -ItemType Directory -Force -Path $frameworksPath
|
|
|
|
|
|
# Create Info.plist
|
|
|
-$infoPlistPath = Join-Path -Path $contentsPath -ChildPath "Info.plist" # Add this line to specify the correct path
|
|
|
+$infoPlistPath = Join-Path -Path $contentsPath -ChildPath "Info.plist"
|
|
|
$infoPlistContent = @"
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -108,8 +118,51 @@ $utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
|
|
|
[System.IO.File]::WriteAllText($infoPlistPath, $infoPlistContent, $utf8NoBomEncoding)
|
|
|
|
|
|
# Copy build output to MacOS directory
|
|
|
+Write-Host "Copying build output to .app structure..."
|
|
|
Copy-Item -Path "$tempBuildPath/*" -Destination $macOSPath -Recurse
|
|
|
|
|
|
+# Find and copy Magick.NET dylibs to the Frameworks directory
|
|
|
+Write-Host "Looking for Magick.NET dylibs..."
|
|
|
+$dylibs = Get-ChildItem -Path $tempBuildPath -Filter "*.dylib" -Recurse
|
|
|
+if ($dylibs) {
|
|
|
+ Write-Host "Found $($dylibs.Count) dylibs, copying to Frameworks directory"
|
|
|
+ foreach ($dylib in $dylibs) {
|
|
|
+ Copy-Item -Path $dylib.FullName -Destination $frameworksPath -Force
|
|
|
+ }
|
|
|
+} else {
|
|
|
+ Write-Host "Warning: No dylibs found in the build output"
|
|
|
+
|
|
|
+ # Find Magick.NET package in the NuGet cache and copy dylibs if available
|
|
|
+ $nugetPackagesDir = if ($env:NUGET_PACKAGES) {
|
|
|
+ $env:NUGET_PACKAGES
|
|
|
+ } else {
|
|
|
+ Join-Path -Path $HOME -ChildPath ".nuget/packages"
|
|
|
+ }
|
|
|
+
|
|
|
+ # Look for the Magick.NET package
|
|
|
+ $magickPackageDir = Join-Path -Path $nugetPackagesDir -ChildPath $packageRef
|
|
|
+
|
|
|
+ if (Test-Path $magickPackageDir) {
|
|
|
+ Write-Host "Found Magick.NET package directory: $magickPackageDir"
|
|
|
+ $newestVersion = (Get-ChildItem $magickPackageDir | Sort-Object -Property Name -Descending)[0].Name
|
|
|
+ $runtimesDir = Join-Path -Path $magickPackageDir -ChildPath "$newestVersion/runtimes/osx-$Platform/native"
|
|
|
+
|
|
|
+ if (Test-Path $runtimesDir) {
|
|
|
+ Write-Host "Copying dylibs from package cache: $runtimesDir"
|
|
|
+ $packageDylibs = Get-ChildItem -Path $runtimesDir -Filter "*.dylib"
|
|
|
+ foreach ($dylib in $packageDylibs) {
|
|
|
+ Copy-Item -Path $dylib.FullName -Destination $frameworksPath -Force
|
|
|
+ # Also copy to the MacOS directory as a fallback
|
|
|
+ Copy-Item -Path $dylib.FullName -Destination $macOSPath -Force
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Write-Host "Couldn't find expected native runtimes in NuGet package: $runtimesDir"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Write-Host "Couldn't find Magick.NET package in NuGet cache"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
# Copy icon if it exists
|
|
|
$iconSource = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/Assets/AppIcon.icns"
|
|
|
if (Test-Path $iconSource) {
|
|
@@ -119,18 +172,65 @@ if (Test-Path $iconSource) {
|
|
|
# Remove PDB files
|
|
|
Get-ChildItem -Path $macOSPath -Filter "*.pdb" -Recurse | Remove-Item -Force
|
|
|
|
|
|
+# Create a script to fix library paths in the main executable
|
|
|
+$fixDylibPath = Join-Path -Path $macOSPath -ChildPath "fix_dylibs.sh"
|
|
|
+$fixDylibScript = @"
|
|
|
+#!/bin/bash
|
|
|
+cd "\$(dirname "\$0")"
|
|
|
+
|
|
|
+# Process PicView executable
|
|
|
+EXECUTABLE="./PicView"
|
|
|
+
|
|
|
+# Process each dylib in the Frameworks directory
|
|
|
+for dylib in ../Frameworks/*.dylib; do
|
|
|
+ # Get just the filename
|
|
|
+ dylib_name=\$(basename \$dylib)
|
|
|
+ echo "Processing \$dylib_name"
|
|
|
+
|
|
|
+ # For executable
|
|
|
+ install_name_tool -change "@rpath/\$dylib_name" "@executable_path/../Frameworks/\$dylib_name" \$EXECUTABLE
|
|
|
+
|
|
|
+ # For each dylib that might depend on other dylibs
|
|
|
+ for target_dylib in ../Frameworks/*.dylib; do
|
|
|
+ install_name_tool -change "@rpath/\$dylib_name" "@executable_path/../Frameworks/\$dylib_name" \$target_dylib
|
|
|
+ done
|
|
|
+done
|
|
|
+
|
|
|
+echo "Library paths fixed successfully"
|
|
|
+"@
|
|
|
+
|
|
|
+# Save fix_dylibs script
|
|
|
+$utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
|
|
|
+[System.IO.File]::WriteAllText($fixDylibPath, $fixDylibScript, $utf8NoBomEncoding)
|
|
|
+
|
|
|
# Remove temporary build directory
|
|
|
Remove-Item -Path $tempBuildPath -Recurse -Force
|
|
|
|
|
|
# Set proper permissions for the entire .app bundle
|
|
|
if ($IsLinux -or $IsMacOS) {
|
|
|
+ # Make the fix_dylibs.sh script executable
|
|
|
+ chmod +x $fixDylibPath
|
|
|
+
|
|
|
+ # Run the fix_dylibs script if we're on macOS
|
|
|
+ if ($IsMacOS) {
|
|
|
+ Write-Host "Running fix_dylibs.sh script"
|
|
|
+ & $fixDylibPath
|
|
|
+ }
|
|
|
+
|
|
|
# Set executable permissions on all binaries and dylibs
|
|
|
Get-ChildItem -Path $macOSPath -Recurse | ForEach-Object {
|
|
|
- if ($_.Extension -in @('.dylib', '') -or $_.Name -eq 'PicView.Avalonia.MacOS') {
|
|
|
+ if ($_.Extension -in @('.dylib', '') -or $_.Name -eq 'PicView') {
|
|
|
chmod +x $_.FullName
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ # Set executable permissions on dylibs in Frameworks directory
|
|
|
+ Get-ChildItem -Path $frameworksPath -Filter "*.dylib" | ForEach-Object {
|
|
|
+ chmod +x $_.FullName
|
|
|
+ }
|
|
|
+
|
|
|
# Set proper ownership and permissions for the entire .app bundle
|
|
|
chmod -R 755 $appBundlePath
|
|
|
}
|
|
|
+
|
|
|
+Write-Host "Build completed successfully: $appBundlePath"
|