Browse Source

Revert "Update macOS build"

This reverts commit 1b8621fdf71b093b4dd645174b531a7f5cbcbea2.
Ruben 7 months ago
parent
commit
8a87f8ce0b

+ 9 - 23
.github/workflows/BuildMacOS.yml

@@ -40,20 +40,13 @@ jobs:
             -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64" `
             -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64" `
             -appVersion "${{steps.get-version.outputs.version}}"
             -appVersion "${{steps.get-version.outputs.version}}"
         shell: pwsh
         shell: pwsh
-      
-      # Step 6: Run fix_dylibs.sh script for arm64
-      - name: Run fix_dylibs script for arm64
-        run: |
-          chmod +x "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app/Contents/MacOS/fix_dylibs.sh"
-          cd "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app/Contents/MacOS/"
-          ./fix_dylibs.sh
-      
-      # Step 7: Create DMG for arm64
+        
+      # Step 6: Create DMG for arm64
       - name: Create DMG for arm64
       - name: Create DMG for arm64
         run: |
         run: |
           hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg"
           hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg"
-      
-      # Step 8: Upload arm64 artifacts
+        
+      # Step 7: Upload arm64 artifacts
       - name: Upload arm64 artifacts
       - name: Upload arm64 artifacts
         uses: actions/upload-artifact@v4
         uses: actions/upload-artifact@v4
         with:
         with:
@@ -63,7 +56,7 @@ jobs:
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg
           retention-days: 14
           retention-days: 14
 
 
-      # Step 9: Build x64 version
+      # Step 8: Build x64 version
       - name: Build x64 version
       - name: Build x64 version
         run: |
         run: |
           pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
           pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
@@ -71,20 +64,13 @@ jobs:
             -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64" `
             -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64" `
             -appVersion "${{steps.get-version.outputs.version}}"
             -appVersion "${{steps.get-version.outputs.version}}"
         shell: pwsh
         shell: pwsh
-      
-      # Step 10: Run fix_dylibs.sh script for x64
-      - name: Run fix_dylibs script for x64
-        run: |
-          chmod +x "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app/Contents/MacOS/fix_dylibs.sh"
-          cd "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app/Contents/MacOS/"
-          ./fix_dylibs.sh
-      
-      # Step 11: Create DMG for x64
+        
+      # Step 9: Create DMG for x64
       - name: Create DMG for x64
       - name: Create DMG for x64
         run: |
         run: |
           hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg"
           hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg"
 
 
-      # Step 12: Upload x64 artifacts
+      # Step 10: Upload x64 artifacts
       - name: Upload x64 artifacts
       - name: Upload x64 artifacts
         uses: actions/upload-artifact@v4
         uses: actions/upload-artifact@v4
         with:
         with:
@@ -92,4 +78,4 @@ jobs:
           path: |
           path: |
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg
             ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg
-          retention-days: 14
+          retention-days: 14

+ 15 - 115
Build/Build Avalonia.MacOS.ps1

@@ -14,27 +14,25 @@ $coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core
 # Load the .csproj file as XML
 # Load the .csproj file as XML
 [xml]$coreCsproj = Get-Content $coreProjectPath
 [xml]$coreCsproj = Get-Content $coreProjectPath
 
 
-# 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"
-}
+# Define the package reference to replace
+$packageRefX64 = "Magick.NET-Q8-x64"
+$packageRefArm64 = "Magick.NET-Q8-arm64"
 
 
-# Find the Magick.NET package reference and update it
-$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -like "Magick.NET-Q8*" }
+# 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 }
 if ($packageNodes) {
 if ($packageNodes) {
     foreach ($packageNode in $packageNodes) {
     foreach ($packageNode in $packageNodes) {
-        $packageNode.Include = $packageRef
+        if ($Platform -eq "arm64") {
+            $packageNode.Include = $packageRefArm64
+        } else {
+            $packageNode.Include = $packageRefX64
+        }
     }
     }
-    
-    # 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
 # Define the project path for the actual build target
 $avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj"
 $avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj"
 
 
@@ -42,18 +40,12 @@ $avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.
 $tempBuildPath = Join-Path -Path $outputPath -ChildPath "temp"
 $tempBuildPath = Join-Path -Path $outputPath -ChildPath "temp"
 New-Item -ItemType Directory -Force -Path $tempBuildPath
 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
 # Run dotnet publish for the Avalonia project
-Write-Host "Publishing project for osx-$Platform..."
 dotnet publish $avaloniaProjectPath `
 dotnet publish $avaloniaProjectPath `
     --runtime "osx-$Platform" `
     --runtime "osx-$Platform" `
     --self-contained true `
     --self-contained true `
     --configuration Release `
     --configuration Release `
     -p:PublishSingleFile=false `
     -p:PublishSingleFile=false `
-    -p:MagickCopyNativeMacOS=true `
     --output $tempBuildPath
     --output $tempBuildPath
 
 
 # Create .app bundle structure
 # Create .app bundle structure
@@ -61,15 +53,13 @@ $appBundlePath = Join-Path -Path $outputPath -ChildPath "PicView.app"
 $contentsPath = Join-Path -Path $appBundlePath -ChildPath "Contents"
 $contentsPath = Join-Path -Path $appBundlePath -ChildPath "Contents"
 $macOSPath = Join-Path -Path $contentsPath -ChildPath "MacOS"
 $macOSPath = Join-Path -Path $contentsPath -ChildPath "MacOS"
 $resourcesPath = Join-Path -Path $contentsPath -ChildPath "Resources"
 $resourcesPath = Join-Path -Path $contentsPath -ChildPath "Resources"
-$frameworksPath = Join-Path -Path $contentsPath -ChildPath "Frameworks"
 
 
 # Create directory structure
 # Create directory structure
 New-Item -ItemType Directory -Force -Path $macOSPath
 New-Item -ItemType Directory -Force -Path $macOSPath
 New-Item -ItemType Directory -Force -Path $resourcesPath
 New-Item -ItemType Directory -Force -Path $resourcesPath
-New-Item -ItemType Directory -Force -Path $frameworksPath
 
 
 # Create Info.plist
 # Create Info.plist
-$infoPlistPath = Join-Path -Path $contentsPath -ChildPath "Info.plist"
+$infoPlistPath = Join-Path -Path $contentsPath -ChildPath "Info.plist"  # Add this line to specify the correct path
 $infoPlistContent = @"
 $infoPlistContent = @"
 <?xml version="1.0" encoding="UTF-8"?>
 <?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">
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -118,51 +108,8 @@ $utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
 [System.IO.File]::WriteAllText($infoPlistPath, $infoPlistContent, $utf8NoBomEncoding)
 [System.IO.File]::WriteAllText($infoPlistPath, $infoPlistContent, $utf8NoBomEncoding)
 
 
 # Copy build output to MacOS directory
 # Copy build output to MacOS directory
-Write-Host "Copying build output to .app structure..."
 Copy-Item -Path "$tempBuildPath/*" -Destination $macOSPath -Recurse
 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
 # Copy icon if it exists
 $iconSource = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/Assets/AppIcon.icns"
 $iconSource = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/Assets/AppIcon.icns"
 if (Test-Path $iconSource) {
 if (Test-Path $iconSource) {
@@ -172,65 +119,18 @@ if (Test-Path $iconSource) {
 # Remove PDB files
 # Remove PDB files
 Get-ChildItem -Path $macOSPath -Filter "*.pdb" -Recurse | Remove-Item -Force
 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 temporary build directory
 Remove-Item -Path $tempBuildPath -Recurse -Force
 Remove-Item -Path $tempBuildPath -Recurse -Force
 
 
 # Set proper permissions for the entire .app bundle
 # Set proper permissions for the entire .app bundle
 if ($IsLinux -or $IsMacOS) {
 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
     # Set executable permissions on all binaries and dylibs
     Get-ChildItem -Path $macOSPath -Recurse | ForEach-Object {
     Get-ChildItem -Path $macOSPath -Recurse | ForEach-Object {
-        if ($_.Extension -in @('.dylib', '') -or $_.Name -eq 'PicView') {
+        if ($_.Extension -in @('.dylib', '') -or $_.Name -eq 'PicView.Avalonia.MacOS') {
             chmod +x $_.FullName
             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
     # Set proper ownership and permissions for the entire .app bundle
     chmod -R 755 $appBundlePath
     chmod -R 755 $appBundlePath
 }
 }
-
-Write-Host "Build completed successfully: $appBundlePath"

+ 14 - 20
src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
   <PropertyGroup>
     <OutputType>WinExe</OutputType>
     <OutputType>WinExe</OutputType>
-    <TargetFramework>net9.0</TargetFramework>
+	<TargetFramework>net9.0</TargetFramework>
     <Platforms>x64;arm64</Platforms>
     <Platforms>x64;arm64</Platforms>
     <Nullable>enable</Nullable>
     <Nullable>enable</Nullable>
     <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
     <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
@@ -20,15 +20,16 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <ImplicitUsings>enable</ImplicitUsings>
     <Product>PicView</Product>
     <Product>PicView</Product>
     <AssemblyName>PicView</AssemblyName>
     <AssemblyName>PicView</AssemblyName>
-    <!-- Native library handling -->
-    <MagickCopyNativeMacOS>true</MagickCopyNativeMacOS>
-    <NativeLibraryRelocator>true</NativeLibraryRelocator>
   </PropertyGroup>
   </PropertyGroup>
-
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
     <DebugType>none</DebugType>
     <DebugType>none</DebugType>
   </PropertyGroup>
   </PropertyGroup>
 
 
+  <PropertyGroup>
+    <MagickCopyNativeMacOS>true</MagickCopyNativeMacOS>
+  </PropertyGroup>
+
+
   <PropertyGroup Condition="'$(Platform)' == 'x64'">
   <PropertyGroup Condition="'$(Platform)' == 'x64'">
     <PlatformTarget>x64</PlatformTarget>
     <PlatformTarget>x64</PlatformTarget>
   </PropertyGroup>
   </PropertyGroup>
@@ -36,6 +37,7 @@
   <PropertyGroup Condition="'$(Platform)' == 'arm64'">
   <PropertyGroup Condition="'$(Platform)' == 'arm64'">
     <PlatformTarget>ARM64</PlatformTarget>
     <PlatformTarget>ARM64</PlatformTarget>
   </PropertyGroup>
   </PropertyGroup>
+  
 
 
   <ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\PicView.Avalonia\PicView.Avalonia.csproj" />
     <ProjectReference Include="..\PicView.Avalonia\PicView.Avalonia.csproj" />
@@ -47,14 +49,6 @@
     <PackageReference Include="Avalonia.Themes.Simple" Version="11.2.5" />
     <PackageReference Include="Avalonia.Themes.Simple" Version="11.2.5" />
   </ItemGroup>
   </ItemGroup>
 
 
-  <!-- Ensure native libraries are copied to output -->
-  <Target Name="CopyNativeLibraries" AfterTargets="Publish">
-    <ItemGroup>
-      <NativeLibs Include="$(OutDir)\*.dylib" />
-    </ItemGroup>
-    <Copy SourceFiles="@(NativeLibs)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
-  </Target>
-
   <ItemGroup>
   <ItemGroup>
     <AvaloniaXaml Update="Views\ExifWindow.axaml">
     <AvaloniaXaml Update="Views\ExifWindow.axaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
@@ -79,11 +73,11 @@
     </Compile>
     </Compile>
   </ItemGroup>
   </ItemGroup>
 
 
-  <ItemGroup>
-    <InternalsVisibleTo Include="PicView.Tests" />
-  </ItemGroup>
+	<ItemGroup>
+		<InternalsVisibleTo Include="PicView.Tests" />
+	</ItemGroup>
 
 
-  <ItemGroup>
-    <UpToDateCheckInput Remove="Views\SettingsWindow.axaml" />
-  </ItemGroup>
-</Project>
+	<ItemGroup>
+	  <UpToDateCheckInput Remove="Views\SettingsWindow.axaml" />
+	</ItemGroup>
+</Project>