Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Build, test and package Filee for Windows on ARM64 (stage 1)
KnifeLemon4690bc1fd770
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 4f89e1dd..c8b8e47a 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -190,3 +190,92 @@ jobs:tests/Filee.App.Tests/bin/Release/net10.0/screenshots/tests/Filee.Setup.Tests/bin/Release/net10.0/screenshots/if-no-files-found: ignore++ # Windows on ARM64 (#236), built and tested natively: the Explorer menu DLL, Setup, 7-Zip, rhwp and Unhwp's library+ # are ARM64 builds, the downloaded engines (Pandoc here) x64 ones under emulation. rhwp and Unhwp come from pinned+ # builds of .github/workflows/windows-arm64-native.yml (build/fetch-engines.ps1). Until both are pinned, their tests+ # skip and no package is built; once they are, the job also builds the win-arm64 Setup and portable zip to try out.+ build-arm64:+ name: build (win-arm64)+ needs: changes+ if: ${{ !cancelled() && needs.changes.outputs.code != 'false' }}+ runs-on: windows-11-arm+ timeout-minutes: 120+ defaults:+ run:+ shell: pwsh+ steps:+ - uses: actions/checkout@v7++ - uses: actions/setup-dotnet@v6+ with:+ global-json-file: global.json++ - name: ARM64 pins+ id: pins+ run: |+ $missing = @(./build/fetch-engines.ps1 -Runtime win-arm64 -MissingPins)+ if ($missing) {+ Write-Host "::warning::Not pinned yet for win-arm64: $($missing -join ', '). Their tests skip and no package is built (build/fetch-engines.ps1)."+ }+ "ready=$(([string](-not $missing)).ToLowerInvariant())" >> $env:GITHUB_OUTPUT++ - name: Restore+ run: dotnet restore Filee.slnx++ - name: Fonts+ run: ./build/fetch-fonts.ps1++ # The pinned rhwp and Unhwp builds when there are, as for the package; Unhwp's library goes next to the test+ # programs through the build.+ - name: Fetch engines for engine tests+ run: |+ $only = @('pandoc', '7zip')+ if ('${{ steps.pins.outputs.ready }}' -eq 'true') { $only += @('rhwp', 'unhwp') }+ ./build/fetch-engines.ps1 -Runtime win-arm64 -Only $only++ - name: Build+ run: |+ $native = @()+ if ('${{ steps.pins.outputs.ready }}' -eq 'true') { $native = @("-p:UnhwpNativeLibrary=$((Resolve-Path engines/unhwp/unhwp.dll).Path)") }+ dotnet build Filee.slnx --no-restore -c Release @native+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }++ # The x64 Zig toolchain the build job saves; it cross-compiles the ARM64 DLL under x64 emulation.+ - name: Restore Zig toolchain+ uses: actions/cache/restore@v5+ with:+ path: build/.cache/zig-x86_64-windows-0.16.0+ key: zig-0.16.0-x86_64-windows++ - name: Build Explorer menu extension+ run: ./build/build-explorer-menu.ps1 -Architecture arm64++ - name: Test UI on its own+ run: dotnet test tests/Filee.App.Tests --no-build -c Release --blame-crash --blame-hang-timeout 5m --logger "console;verbosity=normal" --results-directory TestResults/app++ - name: Test+ run: dotnet test Filee.slnx --no-build -c Release --filter "FullyQualifiedName!~Filee.App.Tests" --logger "trx" --results-directory TestResults++ - name: Check the installer+ run: ./build/build-installer.ps1 -CheckOnly -Runtime win-arm64++ - name: Build package+ if: steps.pins.outputs.ready == 'true'+ run: ./build/build-installer.ps1 -Runtime win-arm64 -Portable++ - name: Upload package+ if: steps.pins.outputs.ready == 'true'+ uses: actions/upload-artifact@v7+ with:+ name: windows-arm64-package+ path: Releases/*-win-arm64-*+ if-no-files-found: error++ - name: Upload test results+ if: failure()+ uses: actions/upload-artifact@v7+ with:+ name: test-results-windows-arm64+ path: TestResults/+ if-no-files-found: ignorediff --git a/.github/workflows/portable.yml b/.github/workflows/portable.ymlindex 4baad749..e065aea7 100644--- a/.github/workflows/portable.yml+++ b/.github/workflows/portable.yml@@ -1,10 +1,12 @@name: Linux and macOS packages# Linux packages are built on Ubuntu 24.04 but must run on Ubuntu 22.04 (glibc 2.35). The rhwp CLI release needs a-# newer glibc, so it is built from pinned source on Ubuntu 22.04 first (linux-native, build/build-linux-native.py) and-# replaces the download in the package. SharpHook (>= 8.0.1) ships libuiohook builds for glibc 2.34 and is packaged as-# is. Every ELF file in a Linux package is then checked against glibc 2.35, and the x64 and arm64 packages are tried on-# Ubuntu 22.04, which also catches a SharpHook or engine update that raises the requirement again.+# newer glibc, so it is built from pinned source on Ubuntu 22.04 first (linux-native, build/build-native.py) and+# replaces the download in the package. Unhwp's NuGet package has no linux-arm64 library: linux-native builds it from+# the package's source too, and the arm64 tests and package use it. SharpHook (>= 8.0.1) ships libuiohook builds for+# glibc 2.34 and is packaged as is. Every ELF file in a Linux package is then checked against glibc 2.35, and the x64+# and arm64 packages are tried on Ubuntu 22.04, which also catches a SharpHook or engine update that raises the+# requirement again.on:workflow_call:@@ -43,6 +45,7 @@ jobs:rid: linux-x64- runner: ubuntu-22.04-armrid: linux-arm64+ unhwp: trueruns-on: ${{ matrix.runner }}timeout-minutes: 90defaults:@@ -53,19 +56,19 @@ jobs:steps:- uses: actions/checkout@v7- # Fails when engines.json moved to another rhwp version while build/build-linux-native.py still builds the old- # source (also when the build below comes from the cache).+ # Fails when engines.json or Directory.Packages.props moved to another rhwp or Unhwp version while+ # build/build-native.py still builds the old source (also when the build below comes from the cache).- name: Check pinned sources- run: python3 build/build-linux-native.py check+ run: python3 build/build-native.py check- name: Restore native buildsid: native-cacheuses: actions/cache@v5with:path: build/.cache/linux-native/${{ matrix.rid }}- key: linux-native-${{ matrix.rid }}-ubuntu-22.04-${{ hashFiles('build/build-linux-native.py') }}+ key: linux-native-${{ matrix.rid }}-ubuntu-22.04-${{ hashFiles('build/build-native.py') }}- # rhwp's default features are pure Rust: a C toolchain for the linker and build scripts is enough.+ # rhwp's default features are pure Rust; Unhwp's zstd-sys compiles C. A C toolchain is enough for both.- name: Build dependenciesif: steps.native-cache.outputs.cache-hit != 'true'run: |@@ -85,12 +88,16 @@ jobs:~/.cargo/registry/index~/.cargo/registry/cache~/.cargo/git/db- key: cargo-registry-${{ matrix.rid }}-${{ hashFiles('build/build-linux-native.py') }}+ key: cargo-registry-${{ matrix.rid }}-${{ hashFiles('build/build-native.py') }}restore-keys: cargo-registry-${{ matrix.rid }}-- name: Build rhwpif: steps.native-cache.outputs.cache-hit != 'true'- run: python3 build/build-linux-native.py rhwp --output "$NATIVE_OUT/rhwp" --work "$RUNNER_TEMP/rhwp"+ run: python3 build/build-native.py rhwp --output "$NATIVE_OUT/rhwp" --work "$RUNNER_TEMP/rhwp"++ - name: Build Unhwp+ if: matrix.unhwp && steps.native-cache.outputs.cache-hit != 'true'+ run: python3 build/build-native.py unhwp --output "$NATIVE_OUT/unhwp" --work "$RUNNER_TEMP/unhwp"- name: Check glibc requirementsrun: python3 build/check-elf-glibc.py --max 2.35 --needed "$NATIVE_OUT"@@ -150,10 +157,15 @@ jobs:path: build/.cache/portable-downloadskey: portable-engines-${{ matrix.rid }}-${{ hashFiles('src/Filee.Engines/Infrastructure/engines.json') }}+ # linux-arm64: Unhwp from linux-native (see the top), so its tests run there too.- name: Build and test native projectsrun: |./build/fetch-portable-engines.ps1 -Runtime '${{ matrix.rid }}' -Destination engines- dotnet build Filee.slnx -c Release+ $native = @()+ if ('${{ matrix.rid }}' -eq 'linux-arm64') {+ $native = @("-p:UnhwpNativeLibrary=$(Join-Path $env:RUNNER_TEMP 'linux-native/unhwp/libunhwp.so')")+ }+ dotnet build Filee.slnx -c Release @nativeif ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }$projects = @('Filee.Core.Tests', 'Filee.Platform.Tests', 'Filee.Engines.Tests', 'Filee.Cli.Tests', 'Filee.App.Tests')foreach ($project in $projects) {@@ -171,7 +183,7 @@ jobs:if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }}- # Linux: rhwp from linux-native instead of the download (see the top).+ # Linux: rhwp from linux-native instead of the download, and on arm64 Unhwp's library (see the top).- name: Build portable packageenv:PACKAGE_VERSION: ${{ inputs.version }}@@ -180,6 +192,9 @@ jobs:if ($IsLinux) {$native = @{ RhwpOverride = Join-Path $env:RUNNER_TEMP 'linux-native/rhwp' }}+ if ('${{ matrix.rid }}' -eq 'linux-arm64') {+ $native.UnhwpOverride = Join-Path $env:RUNNER_TEMP 'linux-native/unhwp/libunhwp.so'+ }./build/build-portable.ps1 -Runtime '${{ matrix.rid }}' -Version $env:PACKAGE_VERSION -SkipFonts @native- name: Check archive and run native convertersdiff --git a/.github/workflows/windows-arm64-native.yml b/.github/workflows/windows-arm64-native.ymlnew file mode 100644index 00000000..718b037f--- /dev/null+++ b/.github/workflows/windows-arm64-native.yml@@ -0,0 +1,88 @@+name: Windows ARM64 native++# rhwp has no Windows ARM64 release and Unhwp's NuGet package no win-arm64 library (#236). This builds both on a+# Windows ARM64 runner from their pinned sources (build/build-native.py: the commit of rhwp's release tag, the commit+# Unhwp's nuspec names) with the C runtime linked statically, so they need no Visual C++ Redistributable, and uploads+# them with their SHA-256.+#+# Run it once per rhwp or Unhwp version (Actions > Windows ARM64 native > Run workflow; a pull request that changes the+# build runs it too). Then host the two files of the artifact at the URLs in build/fetch-engines.ps1 ($arm64Pins) and+# fill in their sha256 from SHA256SUMS.txt: build/build-installer.ps1 -Runtime win-arm64 and CI's win-arm64 job use+# them from then on.++on:+ workflow_dispatch:+ pull_request:+ paths:+ - .github/workflows/windows-arm64-native.yml+ - build/build-native.py++permissions:+ contents: read++jobs:+ build:+ name: rhwp and Unhwp (win-arm64)+ runs-on: windows-11-arm+ timeout-minutes: 90+ defaults:+ run:+ shell: pwsh+ steps:+ - uses: actions/checkout@v7+ with:+ persist-credentials: false++ # An ARM64 Python, so build-native.py can load the ARM64 unhwp.dll to check it.+ - uses: actions/setup-python@v6+ with:+ python-version: '3.13'+ architecture: arm64++ - name: Check pinned sources+ run: python build/build-native.py check++ - name: Rust+ run: |+ if (-not (Get-Command rustup -ErrorAction SilentlyContinue)) {+ $installer = Join-Path $env:RUNNER_TEMP 'rustup-init.exe'+ Invoke-WebRequest https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe -OutFile $installer+ & $installer -y --profile minimal --default-toolchain none --no-modify-path+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ Join-Path $env:USERPROFILE '.cargo\bin' >> $env:GITHUB_PATH+ }++ - name: Build rhwp+ run: python build/build-native.py rhwp --output "$env:RUNNER_TEMP/native/rhwp" --work "$env:RUNNER_TEMP/work"++ - name: Build Unhwp+ run: python build/build-native.py unhwp --output "$env:RUNNER_TEMP/native/unhwp" --work "$env:RUNNER_TEMP/work"++ # The file names build/fetch-engines.ps1 pins: rhwp in the layout of its release archives, Unhwp's library as is.+ - name: Package+ run: |+ $version = { param($name) (Select-String build/build-native.py "^$name = `"(.+)`"").Matches[0].Groups[1].Value }+ $out = New-Item -ItemType Directory -Force (Join-Path $env:RUNNER_TEMP 'out')+ $rhwp = Join-Path $out "rhwp-v$(& $version RHWP_VERSION)-windows-aarch64.zip"+ $unhwp = Join-Path $out "unhwp-$(& $version UNHWP_VERSION)-win-arm64.dll"+ Compress-Archive -Path "$env:RUNNER_TEMP/native/rhwp/*" -DestinationPath $rhwp+ Copy-Item "$env:RUNNER_TEMP/native/unhwp/unhwp.dll" $unhwp+ # Unhwp's license and the source note go next to the file for whoever hosts it.+ Copy-Item "$env:RUNNER_TEMP/native/unhwp/LICENSE" (Join-Path $out 'unhwp-LICENSE.txt')+ Copy-Item "$env:RUNNER_TEMP/native/unhwp/SOURCE.txt" (Join-Path $out 'unhwp-SOURCE.txt')+ foreach ($file in $rhwp, $unhwp) {+ $name = Split-Path $file -Leaf+ if (-not (Select-String build/fetch-engines.ps1 -SimpleMatch "/$name'")) {+ Write-Host "::error::build/fetch-engines.ps1 doesn't pin $name: update the url in `$arm64Pins."+ exit 1+ }+ }+ Get-ChildItem $out -File | ForEach-Object { "$((Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant()) $($_.Name)" } |+ Set-Content (Join-Path $out 'SHA256SUMS.txt') -Encoding ascii+ Get-Content (Join-Path $out 'SHA256SUMS.txt')++ - uses: actions/upload-artifact@v7+ with:+ name: windows-arm64-native+ path: ${{ runner.temp }}/out/+ if-no-files-found: errordiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex b7daaa57..784f3ad4 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -41,8 +41,8 @@ install/uninstall scripts. `Filee-<version>-<rid>-SHA256SUMS.txt` verifies the aand notarization. `-SigningIdentity` can supply a signing identity, but does not perform notarization.Linux release packages must run on Ubuntu 22.04 (glibc 2.35). CI builds rhwp from source on Ubuntu 22.04-(`build/build-linux-native.py`) and passes it with `-RhwpOverride`; a local package without it needs the glibc of the-machine that built it. Check a package with+(`build/build-native.py`) and passes it with `-RhwpOverride` (and on ARM64 Unhwp's library with `-UnhwpOverride`); a+local package without it needs the glibc of the machine that built it. Check a package with`python3 build/check-elf-glibc.py --max 2.35 <unpacked package>`. See [docs/ENGINES.md](docs/ENGINES.md#linux-builds-for-older-glibc).- **Linux:** drag gestures require X11 by default. Install the Avalonia desktop dependencies (fontconfig, FreeType, X11,diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.mdindex 890992ba..9ca80c47 100644--- a/THIRD-PARTY-NOTICES.md+++ b/THIRD-PARTY-NOTICES.md@@ -58,8 +58,13 @@ Bundled with the installer:The Linux packages contain an rhwp built by Filee's CI from the unmodified source of the same release (tag `v0.8.7`,commit `1a76570e833917d15817415a53c09ad61ab3203f`, `cargo build --release --locked --bin rhwp` on Ubuntu 22.04), so it-runs on older Linux systems than rhwp's own Linux build. It is under the same MIT license; its `LICENSE` is next to it-(`engines/rhwp`). Windows and macOS use rhwp's release builds.+runs on older Linux systems than rhwp's own Linux build. The Windows ARM64 build contains an rhwp built the same way+on Windows ARM64 (with the C runtime linked statically), as rhwp has no ARM64 release. Both are under the same MIT+license; its `LICENSE` is next to them (`engines/rhwp`). Windows x64 and macOS use rhwp's release builds.++Unhwp's NuGet package has no native library for Linux ARM64 and Windows ARM64. Those builds contain one built by+Filee's CI from the unmodified source the package was built from (commit `405b17e137b3ca06299dcbc8a156599ac7027e91`,+`cargo build --release --locked -p unhwp --lib --features ffi`), under Unhwp's MIT license.7-Zip is Copyright (C) 1999-2026 Igor Pavlov; its `License.txt` is installed next to it (`engines/7zip`). The RARdecompression code in `7z.dll` is under the unRAR license restriction: it may be used to unpack RAR archives, but notdiff --git a/build/build-explorer-menu.ps1 b/build/build-explorer-menu.ps1index 911a6d46..803b6472 100644--- a/build/build-explorer-menu.ps1+++ b/build/build-explorer-menu.ps1@@ -10,15 +10,21 @@Both files belong next to Filee.exe; the release workflow passes the publish folder as -Destination.+ The DLL is loaded into explorer.exe, so it is built for the architecture of the Filee build it ships with+ (-Architecture): x64, or arm64 for win-arm64 (the package then says arm64 too). The x64 Zig toolchain cross-compiles+ both; on Windows on ARM it runs under x64 emulation.+.EXAMPLEpwsh build/build-explorer-menu.ps1pwsh build/build-explorer-menu.ps1 -Destination publish/win-x64 -Version 1.2.0+ pwsh build/build-explorer-menu.ps1 -Destination publish/win-arm64 -Architecture arm64#>[CmdletBinding()]param([string]$Destination = (Join-Path $PSScriptRoot '.cache\explorer-menu'),# Written into the DLL's version resource; defaults to <Version> in Directory.Build.props.- [string]$Version+ [string]$Version,+ [ValidateSet('x64', 'arm64')][string]$Architecture = 'x64')$ErrorActionPreference = 'Stop'@@ -95,10 +101,11 @@ $rc = Join-Path $obj 'FileeExplorerMenu.rc'$defines = "#define FILEE_VERSION_MAJOR $major`r`n#define FILEE_VERSION_MINOR $minor`r`n#define FILEE_VERSION_PATCH $patch`r`n#define FILEE_VERSION_TEXT `"$Version`"`r`n"Set-Content -Path $rc -Value ($defines + (Get-Content (Join-Path $source 'FileeExplorerMenu.rc') -Raw)) -Encoding utf8NoBOM -NoNewline-Write-Host "build FileeExplorerMenu.dll $Version"+Write-Host "build FileeExplorerMenu.dll $Version ($Architecture)"$dll = Join-Path $obj 'FileeExplorerMenu.dll'+$target = @{ 'x64' = 'x86_64-windows-gnu'; 'arm64' = 'aarch64-windows-gnu' }[$Architecture]# -nostdlib: no C runtime inside explorer.exe; the entry point is DllMain itself. -s strips symbols.-& $zig cc -target x86_64-windows-gnu -shared -O2 -s -nostdlib -Wall -Wextra -Werror `+& $zig cc -target $target -shared -O2 -s -nostdlib -Wall -Wextra -Werror `-isystem (Join-Path (Split-Path $zig) 'lib\libc\include\any-windows-any') `(Join-Path $source 'FileeExplorerMenu.c') (Join-Path $source 'FileeExplorerMenu.def') $rc `-lkernel32 -luser32 -lole32 -lshell32 -lshlwapi '-Wl,--entry=DllMain' -o $dll@@ -109,7 +116,7 @@ Write-Host "pack FileeExplorerMenu.msix"$Destination = (Resolve-Path $Destination).PathPush-Location $roottry {- & dotnet run build/tools/make-explorer-package.cs -- $Destination+ & dotnet run build/tools/make-explorer-package.cs -- $Destination $Architectureif ($LASTEXITCODE -ne 0) { throw "make-explorer-package failed with exit code $LASTEXITCODE" }}finally {diff --git a/build/build-installer.ps1 b/build/build-installer.ps1index d33e61cf..aeb6240c 100644--- a/build/build-installer.ps1+++ b/build/build-installer.ps1@@ -14,6 +14,12 @@engines Setup offers from EngineDownloads. The portable zip is the publish folder as it is: without Setup'suninstall.exe next to Filee.exe, Filee knows it is a portable copy.+.PARAMETER Runtime+ win-x64 (default) or win-arm64. The ARM64 build (Filee-<version>-win-arm64-Setup.exe and -Portable.zip) has an ARM64+ Setup, Explorer menu DLL, rhwp, 7-Zip and Unhwp library (fetch-engines.ps1 -Runtime win-arm64, which fails while+ the ARM64 rhwp and Unhwp builds are not pinned yet). They link the C runtime statically: no Microsoft C++ runtime+ DLLs are copied.+.PARAMETER CertificateThumbprintSigns the release (build/sign-windows.ps1): the programs in the publish folder that come unsigned, the Setupprogram (it becomes uninstall.exe) and, after the payload is appended, Setup.exe. The release workflow builds@@ -40,7 +46,8 @@ param([string]$OutputDir = (Join-Path $PSScriptRoot '..\Releases'),[switch]$Portable,[string]$CertificateThumbprint,- [switch]$CheckOnly+ [switch]$CheckOnly,+ [ValidateSet('win-x64', 'win-arm64')][string]$Runtime = 'win-x64')$ErrorActionPreference = 'Stop'@@ -70,17 +77,24 @@ if ($CheckOnly) {$OutputDir = $check}elseif (-not $PublishDir) {- $PublishDir = Join-Path $root 'publish\win-x64'+ $PublishDir = Join-Path $root "publish\$Runtime"Remove-Item $PublishDir -Recurse -Force -ErrorAction SilentlyContinue+ # Unhwp's package has no win-arm64 library: the pinned ARM64 build goes next to Filee.exe through the build.+ $native = @()+ if ($Runtime -eq 'win-arm64') {+ $natives = Join-Path $cache 'win-arm64-native'+ & (Join-Path $PSScriptRoot 'fetch-engines.ps1') -Runtime $Runtime -Only unhwp -Destination $natives+ $native = @("-p:UnhwpNativeLibrary=$(Join-Path $natives 'unhwp\unhwp.dll')")+ }Invoke-Checked 'dotnet publish' {- dotnet publish (Join-Path $root 'src\Filee.App\Filee.App.csproj') -c Release -r win-x64 --self-contained `- "-p:Version=$Version" -p:PublishReadyToRun=true -p:FileeRelease=true -o $PublishDir+ dotnet publish (Join-Path $root 'src\Filee.App\Filee.App.csproj') -c Release -r $Runtime --self-contained `+ "-p:Version=$Version" -p:PublishReadyToRun=true -p:FileeRelease=true @native -o $PublishDir}# The command line, in the same folder so it shares the runtime and the engines (filee-cli.exe). Its name can't# be filee.exe next to Filee.exe, so the "filee" command is cli\filee.cmd, which Setup can put on PATH.Invoke-Checked 'dotnet publish (cli)' {- dotnet publish (Join-Path $root 'src\Filee.Cli\Filee.Cli.csproj') -c Release -r win-x64 --self-contained `- "-p:Version=$Version" -p:PublishReadyToRun=true -p:FileeRelease=true -o $PublishDir+ dotnet publish (Join-Path $root 'src\Filee.Cli\Filee.Cli.csproj') -c Release -r $Runtime --self-contained `+ "-p:Version=$Version" -p:PublishReadyToRun=true -p:FileeRelease=true @native -o $PublishDir}# Native debug symbols from NuGet packages (libSkiaSharp.pdb, libHarfBuzzSharp.pdb: ~105 MB) are useless to users.# Filee.App's publish removes them, but publishing the command line into the same folder brings them back.@@ -88,19 +102,23 @@ elseif (-not $PublishDir) {New-Item -ItemType Directory -Force -Path (Join-Path $PublishDir 'cli') | Out-NullSet-Content (Join-Path $PublishDir 'cli\filee.cmd') "@`"%~dp0..\filee-cli.exe`" %*" -Encoding ascii# Next to Filee.exe: the Explorer menu package's external location is the install folder.- & (Join-Path $PSScriptRoot 'build-explorer-menu.ps1') -Destination $PublishDir -Version $Version+ $architecture = $Runtime.Substring(4)+ & (Join-Path $PSScriptRoot 'build-explorer-menu.ps1') -Destination $PublishDir -Version $Version -Architecture $architecture# Only the small rhwp and 7-Zip are bundled; the app downloads the others when the user picks them. The Microsoft# C++ runtime goes next to rhwp.exe and next to Filee.exe (unhwp.dll imports VCRUNTIME140.dll), so neither needs- # the Visual C++ Redistributable (#248).- & (Join-Path $PSScriptRoot 'fetch-engines.ps1') -Only rhwp, 7zip -Destination (Join-Path $PublishDir 'engines') -RuntimeTo $PublishDir+ # the Visual C++ Redistributable (#248). The ARM64 builds need none.+ $runtimeTo = @{}+ if ($Runtime -eq 'win-x64') { $runtimeTo = @{ RuntimeTo = $PublishDir } }+ & (Join-Path $PSScriptRoot 'fetch-engines.ps1') -Runtime $Runtime -Only rhwp, 7zip -Destination (Join-Path $PublishDir 'engines') @runtimeTo}$PublishDir = (Resolve-Path $PublishDir).Pathif (-not (Test-Path (Join-Path $PublishDir 'Filee.exe'))) { throw "Filee.exe is missing in $PublishDir" }if (-not $CheckOnly) {# Without them rhwp and unhwp fail on PCs without the Visual C++ Redistributable (#248). They go into the payload# and the portable zip; Setup checks again after unpacking (RuntimeCheck) on the user's PC.- foreach ($dll in 'vcruntime140.dll', 'engines\rhwp\msvcp140.dll', 'engines\rhwp\vcruntime140.dll') {- if (-not (Test-Path (Join-Path $PublishDir $dll))) { throw "$dll is missing in $PublishDir (see fetch-engines.ps1 -RuntimeTo)" }+ $required = if ($Runtime -eq 'win-x64') { 'vcruntime140.dll', 'engines\rhwp\msvcp140.dll', 'engines\rhwp\vcruntime140.dll' } else { @('unhwp.dll') }+ foreach ($dll in $required) {+ if (-not (Test-Path (Join-Path $PublishDir $dll))) { throw "$dll is missing in $PublishDir (see fetch-engines.ps1)" }}# A leftover from a run of the old installer or of Setup would make the zip an "installed" copy.foreach ($file in 'uninstall.exe', 'uninstall.json', 'unins000.exe') {@@ -113,7 +131,7 @@ if (-not $SetupProgram) {$setupFolder = Join-Path $cache 'setup'Remove-Item $setupFolder -Recurse -Force -ErrorAction SilentlyContinueInvoke-Checked 'dotnet publish (setup)' {- dotnet publish (Join-Path $root 'src\Filee.Setup\Filee.Setup.csproj') -c Release -r win-x64 -p:FileeSetupPublish=true `+ dotnet publish (Join-Path $root 'src\Filee.Setup\Filee.Setup.csproj') -c Release -r $Runtime -p:FileeSetupPublish=true `"-p:Version=$Version" -o $setupFolder}$SetupProgram = Join-Path $setupFolder 'Filee.Setup.exe'@@ -127,7 +145,9 @@ if ($sign) {& $sign -Path $PublishDir, $SetupProgram -CertificateThumbprint $CertificateThumbprint}-$setupExe = Join-Path $OutputDir "Filee-$Version-win-Setup.exe"+# The x64 names are the ones Filee's updater looks for (-win-Setup.exe, -SHA256SUMS.txt).+$prefix = if ($Runtime -eq 'win-x64') { "Filee-$Version-win" } else { "Filee-$Version-$Runtime" }+$setupExe = Join-Path $OutputDir "$prefix-Setup.exe"Write-Host "pack installer $Version"$fast = @(if ($CheckOnly) { '--fast' })Push-Location $root@@ -170,7 +190,7 @@ if ($CheckOnly) {$files = @($setupExe)if ($Portable) {- $zip = Join-Path $OutputDir "Filee-$Version-win-Portable.zip"+ $zip = Join-Path $OutputDir "$prefix-Portable.zip"Remove-Item $zip -ErrorAction SilentlyContinueWrite-Host "zip $zip"Add-Type -AssemblyName System.IO.Compression.FileSystem@@ -179,7 +199,7 @@ if ($Portable) {}# Checksums for people who verify their download.-$sums = Join-Path $OutputDir "Filee-$Version-SHA256SUMS.txt"+$sums = Join-Path $OutputDir $(if ($Runtime -eq 'win-x64') { "Filee-$Version-SHA256SUMS.txt" } else { "$prefix-SHA256SUMS.txt" })$files | ForEach-Object { "$((Get-FileHash $_ -Algorithm SHA256).Hash.ToLowerInvariant()) $(Split-Path $_ -Leaf)" } |Set-Content $sums -Encoding asciiGet-Item ($files + $sums) | Format-Table Name, Lengthdiff --git a/build/build-linux-native.py b/build/build-linux-native.pydeleted file mode 100644index 123b55a6..00000000--- a/build/build-linux-native.py+++ /dev/null@@ -1,158 +0,0 @@-#!/usr/bin/env python3-"""Builds the Linux native pieces of the portable package that upstream builds on a newer glibc than Filee supports.--Filee's Linux packages must start on Ubuntu 22.04 (glibc 2.35). The rhwp CLI (HWP/HWPX -> PDF) release binary is linked-on Ubuntu 24.04 (GLIBC_2.39), so CI builds it from its pinned source on Ubuntu 22.04 and build/build-portable.ps1 puts it-into the package. SharpHook's native libraries (libuiohook) come from its NuGet package: from 8.0.1 on they need glibc-2.34 at most.--Subcommands:- check verify the rhwp pin below still matches engines.json- rhwp --output DIR build the rhwp CLI into DIR (rhwp, LICENSE, README files, like its release archive)--Needs git, a C toolchain and rustup. Standard library only.-"""--import argparse-import json-import os-import platform-import shutil-import subprocess-import sys-import tempfile--ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))--# The rhwp release pinned in engines.json for Linux (`check` compares the versions). RUST_TOOLCHAIN is the one in the-# tag's rust-toolchain.toml. Cargo.lock in the tag pins every dependency (--locked).-RHWP_VERSION = "0.8.7"-RHWP_REPOSITORY = "https://github.com/edwardkim/rhwp"-RHWP_COMMIT = "1a76570e833917d15817415a53c09ad61ab3203f"-RUST_TOOLCHAIN = "1.93.1"---class BuildError(Exception):- pass---def run(command, cwd=None, env=None, capture=False):- print("+ " + " ".join(command), flush=True)- result = subprocess.run(command, cwd=cwd, env=env, check=False, text=True,- stdout=subprocess.PIPE if capture else None)- if result.returncode != 0:- raise BuildError(f"{command[0]} failed with exit code {result.returncode}")- return result.stdout if capture else None---def linux_rhwp_versions():- path = os.path.join(ROOT, "src", "Filee.Engines", "Infrastructure", "engines.json")- with open(path, encoding="utf-8") as stream:- manifest = json.load(stream)- return {rid: manifest["platforms"][rid]["components"]["rhwp"]["version"] for rid in ("linux-x64", "linux-arm64")}---def check():- problems = []- for rid, rhwp in linux_rhwp_versions().items():- if rhwp != RHWP_VERSION:- problems.append(- f"engines.json pins rhwp {rhwp} for {rid}, but build/build-linux-native.py builds rhwp {RHWP_VERSION}. "- "Update RHWP_VERSION, RHWP_COMMIT and RUST_TOOLCHAIN (from the tag's rust-toolchain.toml).")- if problems:- raise BuildError("\n".join(problems))- print(f"Pins match: rhwp {RHWP_VERSION} -> {RHWP_COMMIT} (Rust {RUST_TOOLCHAIN}).")---def fetch(repository, commit, destination):- """A shallow checkout of exactly one commit (GitHub serves any reachable commit by its hash)."""- os.makedirs(destination)- run(["git", "init", "-q", destination])- run(["git", "-C", destination, "fetch", "-q", "--depth", "1", repository, commit])- run(["git", "-C", destination, "checkout", "-q", "--detach", "FETCH_HEAD"])- head = run(["git", "-C", destination, "rev-parse", "HEAD"], capture=True).strip()- if head != commit:- raise BuildError(f"{repository}: expected commit {commit}, got {head}")---def verify_rhwp_tag():- """Warns when the tag no longer points at the pinned commit (the pinned commit is built either way)."""- lines = run(["git", "ls-remote", RHWP_REPOSITORY, f"refs/tags/v{RHWP_VERSION}", f"refs/tags/v{RHWP_VERSION}^{{}}"],- capture=True).splitlines()- refs = dict(reversed(line.split("\t", 1)) for line in lines if "\t" in line)- tagged = refs.get(f"refs/tags/v{RHWP_VERSION}^{{}}") or refs.get(f"refs/tags/v{RHWP_VERSION}")- if tagged != RHWP_COMMIT:- print(f"::warning::rhwp tag v{RHWP_VERSION} points at {tagged}, the build uses the pinned {RHWP_COMMIT}.")---def build_rhwp(output, work):- if shutil.which("rustup") is None:- raise BuildError("rhwp needs rustup (https://rustup.rs).")- verify_rhwp_tag()- source = os.path.join(work, "rhwp")- fetch(RHWP_REPOSITORY, RHWP_COMMIT, source)- run(["rustup", "toolchain", "install", RUST_TOOLCHAIN, "--profile", "minimal", "--no-self-update"])- # "+toolchain" takes precedence over the repository's rust-toolchain.toml (whose wasm target the CLI doesn't need).- env = dict(os.environ, CARGO_TARGET_DIR=os.path.join(work, "rhwp-target"))- run(["cargo", f"+{RUST_TOOLCHAIN}", "build", "--release", "--locked", "--bin", "rhwp"], cwd=source, env=env)- program = os.path.join(env["CARGO_TARGET_DIR"], "release", "rhwp")- version = run([program, "--version"], capture=True)- print(version.strip())- if RHWP_VERSION not in version:- raise BuildError(f"rhwp --version printed {version.strip()!r}, expected {RHWP_VERSION}.")- # The same layout as rhwp's release archive, which build/fetch-portable-engines.ps1 unpacks for local builds.- os.makedirs(output, exist_ok=True)- shutil.copy2(program, os.path.join(output, "rhwp"))- for name in ("LICENSE", "README.md", "README_EN.md"):- if os.path.isfile(os.path.join(source, name)):- shutil.copy2(os.path.join(source, name), os.path.join(output, name))- write_source_note(output, "rhwp", RHWP_REPOSITORY, RHWP_COMMIT,- f"v{RHWP_VERSION}; cargo +{RUST_TOOLCHAIN} build --release --locked --bin rhwp; {platform.machine()}")---def write_source_note(output, name, repository, commit, details):- with open(os.path.join(output, "SOURCE.txt"), "w", encoding="utf-8") as stream:- stream.write(f"{name} built from source by Filee's CI on {distribution()}.\n"- f"Source: {repository}/tree/{commit}\n{details}\n")---def distribution():- try:- with open("/etc/os-release", encoding="utf-8") as stream:- for line in stream:- if line.startswith("PRETTY_NAME="):- return line.split("=", 1)[1].strip().strip('"')- except OSError:- pass- return platform.platform()---def main(argv=None):- parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])- parser.add_argument("component", choices=["check", "rhwp"])- parser.add_argument("--output", help="folder for the built files (must not exist yet)")- parser.add_argument("--work", help="scratch folder (default: a new temporary folder)")- options = parser.parse_args(argv)- try:- check()- if options.component == "check":- return 0- if not sys.platform.startswith("linux"):- raise BuildError("Build the Linux native pieces on Linux.")- if not options.output:- raise BuildError("--output is required.")- output = os.path.abspath(options.output)- if os.path.exists(output):- raise BuildError(f"{output} already exists. Use a fresh output folder.")- work = os.path.abspath(options.work) if options.work else tempfile.mkdtemp(prefix=f"filee-{options.component}-")- os.makedirs(work, exist_ok=True)- build_rhwp(output, work)- print(f"{options.component} ready in {output}: {', '.join(sorted(os.listdir(output)))}")- return 0- except BuildError as error:- print(f"::error::{error}" if os.environ.get("GITHUB_ACTIONS") else f"error: {error}", file=sys.stderr)- return 1---if __name__ == "__main__":- sys.exit(main())diff --git a/build/build-native.py b/build/build-native.pynew file mode 100644index 00000000..c5e320f5--- /dev/null+++ b/build/build-native.py@@ -0,0 +1,305 @@+#!/usr/bin/env python3+"""Builds the Rust native pieces of Filee's packages that upstream doesn't build for a platform Filee supports.++Linux packages must start on Ubuntu 22.04 (glibc 2.35). The rhwp CLI (HWP/HWPX -> PDF) release binary is linked on+Ubuntu 24.04 (GLIBC_2.39), so CI builds it from its pinned source on Ubuntu 22.04 and build/build-portable.ps1 puts it+into the package. Unhwp's NuGet package has no native library for linux-arm64, so the same job builds that on+Ubuntu 22.04 ARM64 too. SharpHook's native libraries (libuiohook) come from its NuGet package: from 8.0.1 on they need+glibc 2.34 at most.++Windows on ARM64: rhwp has no ARM64 release and Unhwp's NuGet package no win-arm64 library. They are built on a+Windows ARM64 runner (.github/workflows/windows-arm64-native.yml), hosted on dl.filee.sh and pinned by SHA-256 in+build/fetch-engines.ps1. Both link the C runtime statically (+crt-static): they import no Visual C++ runtime DLL, so+no ARM64 copy of it has to ship next to them.++Subcommands:+ check verify the pins below still match engines.json and Directory.Packages.props+ rhwp --output DIR build the rhwp CLI into DIR (rhwp[.exe], LICENSE, README files, like its release archive)+ unhwp --output DIR build Unhwp's native library into DIR (libunhwp.so or unhwp.dll, LICENSE)++Builds for the machine it runs on. Needs git, a C toolchain (Visual Studio's on Windows) and rustup. Standard library+only.+"""++import argparse+import ctypes+import json+import os+import platform+import re+import shutil+import struct+import subprocess+import sys+import tempfile+import xml.etree.ElementTree as ElementTree++ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))+WINDOWS = sys.platform == "win32"++# The rhwp release pinned in engines.json (`check` compares the versions). RUST_TOOLCHAIN is the one in the tag's+# rust-toolchain.toml. Cargo.lock in the tag pins every dependency (--locked).+RHWP_VERSION = "0.8.7"+RHWP_REPOSITORY = "https://github.com/edwardkim/rhwp"+RHWP_COMMIT = "1a76570e833917d15817415a53c09ad61ab3203f"+RUST_TOOLCHAIN = "1.93.1"++# The Unhwp NuGet package in Directory.Packages.props; its nuspec names the commit it was built from (repository+# commit=...). Upstream builds the library with `cargo build --release --features ffi`; Cargo.lock pins the rest.+UNHWP_VERSION = "0.13.0"+UNHWP_REPOSITORY = "https://github.com/iyulab/unhwp"+UNHWP_COMMIT = "405b17e137b3ca06299dcbc8a156599ac7027e91"++# Visual C++ runtime DLLs, as src/Filee.Setup/Installation/RuntimeCheck.cs matches them.+VC_RUNTIME_DLL = re.compile(r"^(vcruntime|msvcp|concrt|vcomp|vccorlib|mfc|mfcm)140[a-z0-9_]*\.dll$", re.IGNORECASE)+PE_MACHINES = {0x8664: "x64", 0xAA64: "arm64"}+++class BuildError(Exception):+ pass+++def run(command, cwd=None, env=None, capture=False):+ print("+ " + " ".join(command), flush=True)+ result = subprocess.run(command, cwd=cwd, env=env, check=False, text=True,+ stdout=subprocess.PIPE if capture else None)+ if result.returncode != 0:+ raise BuildError(f"{command[0]} failed with exit code {result.returncode}")+ return result.stdout if capture else None+++def pinned_rhwp_versions():+ path = os.path.join(ROOT, "src", "Filee.Engines", "Infrastructure", "engines.json")+ with open(path, encoding="utf-8") as stream:+ manifest = json.load(stream)+ versions = {rid: manifest["platforms"][rid]["components"]["rhwp"]["version"] for rid in ("linux-x64", "linux-arm64")}+ # Windows ARM64 gets the version of the win-x64 download.+ versions["win-x64"] = manifest["components"]["rhwp"]["version"]+ return versions+++def pinned_unhwp_version():+ path = os.path.join(ROOT, "Directory.Packages.props")+ for element in ElementTree.parse(path).iter():+ if element.tag.endswith("PackageVersion") and element.get("Include") == "Unhwp":+ return element.get("Version")+ raise BuildError("Directory.Packages.props has no Unhwp version.")+++def check():+ problems = []+ for rid, rhwp in pinned_rhwp_versions().items():+ if rhwp != RHWP_VERSION:+ problems.append(+ f"engines.json pins rhwp {rhwp} for {rid}, but build/build-native.py builds rhwp {RHWP_VERSION}. "+ "Update RHWP_VERSION, RHWP_COMMIT and RUST_TOOLCHAIN (from the tag's rust-toolchain.toml).")+ unhwp = pinned_unhwp_version()+ if unhwp != UNHWP_VERSION:+ problems.append(+ f"Directory.Packages.props pins Unhwp {unhwp}, but build/build-native.py builds Unhwp {UNHWP_VERSION}. "+ "Update UNHWP_VERSION and UNHWP_COMMIT (the commit in the package's .nuspec), then build and pin the "+ "win-arm64 library again (build/fetch-engines.ps1).")+ if problems:+ raise BuildError("\n".join(problems))+ print(f"Pins match: rhwp {RHWP_VERSION} -> {RHWP_COMMIT}, Unhwp {UNHWP_VERSION} -> {UNHWP_COMMIT} "+ f"(Rust {RUST_TOOLCHAIN}).")+++def fetch(repository, commit, destination):+ """A shallow checkout of exactly one commit (GitHub serves any reachable commit by its hash)."""+ os.makedirs(destination)+ run(["git", "init", "-q", destination])+ run(["git", "-C", destination, "fetch", "-q", "--depth", "1", repository, commit])+ run(["git", "-C", destination, "checkout", "-q", "--detach", "FETCH_HEAD"])+ head = run(["git", "-C", destination, "rev-parse", "HEAD"], capture=True).strip()+ if head != commit:+ raise BuildError(f"{repository}: expected commit {commit}, got {head}")+++def verify_rhwp_tag():+ """Warns when the tag no longer points at the pinned commit (the pinned commit is built either way)."""+ lines = run(["git", "ls-remote", RHWP_REPOSITORY, f"refs/tags/v{RHWP_VERSION}", f"refs/tags/v{RHWP_VERSION}^{{}}"],+ capture=True).splitlines()+ refs = dict(reversed(line.split("\t", 1)) for line in lines if "\t" in line)+ tagged = refs.get(f"refs/tags/v{RHWP_VERSION}^{{}}") or refs.get(f"refs/tags/v{RHWP_VERSION}")+ if tagged != RHWP_COMMIT:+ print(f"::warning::rhwp tag v{RHWP_VERSION} points at {tagged}, the build uses the pinned {RHWP_COMMIT}.")+++def cargo(source, work, name, arguments):+ """Runs cargo build with the pinned toolchain; returns the target folder's release directory."""+ if shutil.which("rustup") is None:+ raise BuildError(f"{name} needs rustup (https://rustup.rs).")+ toolchain = RUST_TOOLCHAIN+ if WINDOWS:+ # The toolchain of this machine by name: an x64 rustup on Windows on ARM would otherwise build x64 programs.+ toolchain += {"ARM64": "-aarch64", "AMD64": "-x86_64"}[platform.machine().upper()] + "-pc-windows-msvc"+ run(["rustup", "toolchain", "install", toolchain, "--profile", "minimal", "--no-self-update"])+ # "+toolchain" takes precedence over a repository's rust-toolchain.toml (rhwp's adds a wasm target).+ env = dict(os.environ, CARGO_TARGET_DIR=os.path.join(work, f"{name}-target"))+ if WINDOWS:+ # The C runtime linked in (/MT): nothing to import from the Visual C++ Redistributable.+ env["RUSTFLAGS"] = "-C target-feature=+crt-static"+ run(["cargo", f"+{toolchain}", "build", "--release", "--locked"] + arguments, cwd=source, env=env)+ return os.path.join(env["CARGO_TARGET_DIR"], "release")+++def build_rhwp(output, work):+ verify_rhwp_tag()+ source = os.path.join(work, "rhwp")+ fetch(RHWP_REPOSITORY, RHWP_COMMIT, source)+ program_name = "rhwp.exe" if WINDOWS else "rhwp"+ program = os.path.join(cargo(source, work, "rhwp", ["--bin", "rhwp"]), program_name)+ check_windows_binary(program)+ version = run([program, "--version"], capture=True)+ print(version.strip())+ if RHWP_VERSION not in version:+ raise BuildError(f"rhwp --version printed {version.strip()!r}, expected {RHWP_VERSION}.")+ # The same layout as rhwp's release archive, which build/fetch-portable-engines.ps1 and build/fetch-engines.ps1+ # unpack.+ os.makedirs(output, exist_ok=True)+ shutil.copy2(program, os.path.join(output, program_name))+ copy_notices(source, output, ("LICENSE", "README.md", "README_EN.md"))+ write_source_note(output, "rhwp", RHWP_REPOSITORY, RHWP_COMMIT,+ f"v{RHWP_VERSION}; {build_flags()}cargo +{RUST_TOOLCHAIN} build --release --locked --bin rhwp; "+ f"{platform.machine()}")+++def build_unhwp(output, work):+ source = os.path.join(work, "unhwp")+ fetch(UNHWP_REPOSITORY, UNHWP_COMMIT, source)+ library_name = "unhwp.dll" if WINDOWS else "libunhwp.so"+ # --lib builds the crate's cdylib (the C ABI behind the "ffi" feature) next to its rlib.+ library = os.path.join(cargo(source, work, "unhwp", ["-p", "unhwp", "--lib", "--features", "ffi"]), library_name)+ check_windows_binary(library)+ version = unhwp_version(library)+ print(f"unhwp_version() = {version}")+ if version != UNHWP_VERSION:+ raise BuildError(f"unhwp_version() returned {version!r}, expected {UNHWP_VERSION}.")+ os.makedirs(output, exist_ok=True)+ shutil.copy2(library, os.path.join(output, library_name))+ copy_notices(source, output, ("LICENSE",))+ write_source_note(output, "Unhwp", UNHWP_REPOSITORY, UNHWP_COMMIT,+ f"NuGet Unhwp {UNHWP_VERSION}; {build_flags()}cargo +{RUST_TOOLCHAIN} build --release --locked "+ f"-p unhwp --lib --features ffi; {platform.machine()}")+++def unhwp_version(library):+ """Loads the library the way the app does and asks it for its version (proves it loads and exports the C ABI)."""+ native = ctypes.CDLL(library)+ native.unhwp_version.restype = ctypes.c_char_p+ native.unhwp_version.argtypes = []+ return native.unhwp_version().decode("utf-8")+++def build_flags():+ return "RUSTFLAGS=\"-C target-feature=+crt-static\" " if WINDOWS else ""+++def copy_notices(source, output, names):+ for name in names:+ if os.path.isfile(os.path.join(source, name)):+ shutil.copy2(os.path.join(source, name), os.path.join(output, name))+ if not os.path.isfile(os.path.join(output, "LICENSE")):+ raise BuildError(f"{source} has no LICENSE file to ship with the build.")+++def check_windows_binary(path):+ """A Windows build must be for this machine and must not need the Visual C++ Redistributable."""+ if not WINDOWS:+ return+ machine, imports = pe_imports(path)+ expected = {"AMD64": "x64", "ARM64": "arm64"}.get(platform.machine().upper())+ if machine != expected:+ raise BuildError(f"{os.path.basename(path)} is built for {machine}, expected {expected}.")+ runtime = [name for name in imports if VC_RUNTIME_DLL.match(name)]+ if runtime:+ raise BuildError(f"{os.path.basename(path)} imports {', '.join(runtime)}; it must link the C runtime statically.")+ print(f"{os.path.basename(path)}: {machine}, imports {', '.join(sorted(imports))}")+++def pe_imports(path):+ """The machine (x64, arm64) and the imported DLL names of a PE file (its import directory)."""+ with open(path, "rb") as stream:+ data = stream.read()+ if data[:2] != b"MZ":+ raise BuildError(f"{path} is not a PE file.")+ header = struct.unpack_from("<I", data, 0x3C)[0]+ if data[header:header + 4] != b"PE\0\0":+ raise BuildError(f"{path} is not a PE file.")+ machine, sections, _, _, _, optional_size, _ = struct.unpack_from("<HHIIIHH", data, header + 4)+ optional = header + 24+ if struct.unpack_from("<H", data, optional)[0] != 0x20B:+ raise BuildError(f"{path} is not a 64-bit PE file.")+ import_rva = struct.unpack_from("<I", data, optional + 112 + 8)[0]+ table = optional + optional_size+ section_list = [struct.unpack_from("<IIII", data, table + 40 * index + 8) for index in range(sections)]++ def offset(rva):+ for virtual_size, address, raw_size, raw_offset in section_list:+ if address <= rva < address + max(virtual_size, raw_size):+ return raw_offset + rva - address+ raise BuildError(f"{path}: RVA {rva:#x} is outside every section.")++ names = []+ if import_rva:+ entry = offset(import_rva)+ while True:+ descriptor = struct.unpack_from("<IIIII", data, entry)+ if not any(descriptor):+ break+ start = offset(descriptor[3])+ names.append(data[start:data.index(b"\0", start)].decode("ascii"))+ entry += 20+ return PE_MACHINES.get(machine, hex(machine)), names+++def write_source_note(output, name, repository, commit, details):+ with open(os.path.join(output, "SOURCE.txt"), "w", encoding="utf-8") as stream:+ stream.write(f"{name} built from source by Filee's CI on {distribution()}.\n"+ f"Source: {repository}/tree/{commit}\n{details}\n")+++def distribution():+ try:+ with open("/etc/os-release", encoding="utf-8") as stream:+ for line in stream:+ if line.startswith("PRETTY_NAME="):+ return line.split("=", 1)[1].strip().strip('"')+ except OSError:+ pass+ return platform.platform()+++def main(argv=None):+ parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])+ parser.add_argument("component", choices=["check", "rhwp", "unhwp"])+ parser.add_argument("--output", help="folder for the built files (must not exist yet)")+ parser.add_argument("--work", help="scratch folder (default: a new temporary folder)")+ options = parser.parse_args(argv)+ try:+ check()+ if options.component == "check":+ return 0+ if not (sys.platform.startswith("linux") or WINDOWS):+ raise BuildError("Build the native pieces on Linux or Windows.")+ if not options.output:+ raise BuildError("--output is required.")+ output = os.path.abspath(options.output)+ if os.path.exists(output):+ raise BuildError(f"{output} already exists. Use a fresh output folder.")+ work = os.path.abspath(options.work) if options.work else tempfile.mkdtemp(prefix=f"filee-{options.component}-")+ os.makedirs(work, exist_ok=True)+ if options.component == "rhwp":+ build_rhwp(output, work)+ else:+ build_unhwp(output, work)+ print(f"{options.component} ready in {output}: {', '.join(sorted(os.listdir(output)))}")+ return 0+ except BuildError as error:+ print(f"::error::{error}" if os.environ.get("GITHUB_ACTIONS") else f"error: {error}", file=sys.stderr)+ return 1+++if __name__ == "__main__":+ sys.exit(main())diff --git a/build/build-portable.ps1 b/build/build-portable.ps1index dc8438d1..876b1096 100644--- a/build/build-portable.ps1+++ b/build/build-portable.ps1@@ -2,10 +2,13 @@# disk image (Filee.app next to an Applications link, to drag it there), signed and notarized as the app is.## Linux packages must run on Ubuntu 22.04 (glibc 2.35). rhwp's Linux release needs a newer glibc, so CI builds it from-# source on Ubuntu 22.04 (build/build-linux-native.py) and passes it in:-# -RhwpOverride <dir> a folder with the rhwp program (rhwp's release archive layout) used instead of the rhwp-# download pinned in engines.json+# source on Ubuntu 22.04 (build/build-native.py) and passes it in:+# -RhwpOverride <dir> a folder with the rhwp program (rhwp's release archive layout) used instead of the rhwp+# download pinned in engines.json# Without it (local builds) the package uses the download, which needs a newer glibc.+# Unhwp's NuGet package has no linux-arm64 library; CI builds it the same way and passes it in:+# -UnhwpOverride <file> libunhwp.so, put next to the app (dotnet publish -p:UnhwpNativeLibrary)+# Without it a linux-arm64 package has no Unhwp (HWP/HWPX to text, Markdown and HTML).## macOS packages must run on macOS 13 (LSMinimumSystemVersion). Magick.NET's own macOS ImageMagick library needs macOS# 14 (Apple silicon) or 15 (Intel), so it is replaced by the same Magick.Native release built for macOS 13@@ -18,7 +21,8 @@ param([string]$OutputDir = (Join-Path $PSScriptRoot '../Releases'),[string]$SigningIdentity = '-',[switch]$SkipFonts,- [string]$RhwpOverride+ [string]$RhwpOverride,+ [string]$UnhwpOverride)$ErrorActionPreference = 'Stop'@@ -34,6 +38,15 @@ if (($Runtime.StartsWith('osx-') -and -not $IsMacOS) -or ($Runtime.StartsWith('lif ($RhwpOverride -and -not $Runtime.StartsWith('linux-')) {throw '-RhwpOverride is for Linux packages.'}+if ($UnhwpOverride -and $Runtime -ne 'linux-arm64') {+ throw '-UnhwpOverride is for linux-arm64 packages (the others get the library from the Unhwp package).'+}+$native = @()+if ($UnhwpOverride) {+ $UnhwpOverride = (Resolve-Path -LiteralPath $UnhwpOverride).Path+ if ((Split-Path $UnhwpOverride -Leaf) -ne 'libunhwp.so') { throw "-UnhwpOverride: $UnhwpOverride is not libunhwp.so." }+ $native = @("-p:UnhwpNativeLibrary=$UnhwpOverride")+}if ($RhwpOverride) {$RhwpOverride = (Resolve-Path -LiteralPath $RhwpOverride).Pathif (-not (Test-Path -LiteralPath (Join-Path $RhwpOverride 'rhwp') -PathType Leaf)) {@@ -84,7 +97,7 @@ if (-not $SkipFonts) { & (Join-Path $PSScriptRoot 'fetch-fonts.ps1') }foreach ($project in @('Filee.App', 'Filee.Cli')) {Invoke-Checked "Publish $project" {dotnet publish (Join-Path $root "src/$project/$project.csproj") -c Release -r $Runtime --self-contained true `- "-p:Version=$Version" -p:FileeRelease=true -p:PublishReadyToRun=false -o $publish+ "-p:Version=$Version" -p:FileeRelease=true -p:PublishReadyToRun=false @native -o $publish}}$engines = Join-Path $publish 'engines'diff --git a/build/fetch-engines.ps1 b/build/fetch-engines.ps1index e0926784..af514a73 100644--- a/build/fetch-engines.ps1+++ b/build/fetch-engines.ps1@@ -29,6 +29,13 @@into its program folder), so they also run on PCs without the Visual C++ Redistributable. -RuntimeTo copies it intomore folders (build-installer.ps1: next to Filee.exe, for unhwp.dll).+ Windows on ARM64 (-Runtime win-arm64): rhwp and 7-Zip are ARM64 builds, and "unhwp" is Unhwp's ARM64 library+ (unhwp\unhwp.dll; the build passes it to dotnet with -p:UnhwpNativeLibrary, see build-installer.ps1). rhwp and Unhwp+ have no ARM64 release: .github/workflows/windows-arm64-native.yml builds them from the pinned sources+ (build/build-native.py), the files are hosted on dl.filee.sh and pinned below ($arm64Pins). Both link the C runtime+ statically, so nothing gets the Microsoft C++ runtime DLLs. Every other engine is the x64 download, which Windows 11+ on ARM runs under emulation.+.PARAMETER DestinationTarget "engines" folder. Default: <repo>/engines (picked up automatically by debug builds).@@ -36,19 +43,28 @@Restrict to some engines, e.g. -Only rhwp,pandoc (LibreOffice is large: ~356 MB download)..PARAMETER RuntimeTo- More folders that get the Microsoft C++ runtime DLLs, e.g. the published app folder.+ More folders that get the Microsoft C++ runtime DLLs, e.g. the published app folder (win-x64 only).++.PARAMETER Runtime+ win-x64 (default) or win-arm64.++.PARAMETER MissingPins+ Lists the win-arm64 downloads that are not pinned yet (one name per line) and downloads nothing..EXAMPLEpwsh build/fetch-engines.ps1pwsh build/fetch-engines.ps1 -Only rhwppwsh build/fetch-engines.ps1 -Destination publish/win-x64/engines+ pwsh build/fetch-engines.ps1 -Runtime win-arm64 -Only rhwp,7zip,unhwp#>[CmdletBinding()]param([string]$Destination = (Join-Path $PSScriptRoot '..\engines'),# Accepts an array (-Only rhwp,jre from PowerShell) or one comma-separated string (pwsh -File ... -Only rhwp,jre).[string[]]$Only,- [string[]]$RuntimeTo+ [string[]]$RuntimeTo,+ [ValidateSet('win-x64', 'win-arm64')][string]$Runtime = 'win-x64',+ [switch]$MissingPins)$ErrorActionPreference = 'Stop'@@ -61,12 +77,67 @@ foreach ($component in $manifest.components.PSObject.Properties) {$engines[$component.Name] = @{ Url = $component.Value.url; Sha256 = $component.Value.sha256 }}+# The ARM64 builds for -Runtime win-arm64, each of the version the x64 build uses (engines.json; Unhwp:+# Directory.Packages.props). rhwp and unhwp: run the "Windows ARM64 native" workflow (Actions tab), upload the files of+# its artifact to the url below and copy sha256 from its SHA256SUMS.txt. A version update needs a new build: the+# workflow fails until build/build-native.py builds the new version, and this script until the pin is updated.+$arm64Pins = [ordered]@{+ rhwp = @{+ Version = '0.8.7'+ Url = 'https://dl.filee.sh/engines/rhwp/0.8.7/rhwp-v0.8.7-windows-aarch64.zip'+ Sha256 = ''+ }+ unhwp = @{+ Version = '0.13.0'+ Url = 'https://dl.filee.sh/engines/unhwp/0.13.0/unhwp-0.13.0-win-arm64.dll'+ Sha256 = ''+ }+ # The official ARM64 installer, a 7z self-extracting archive; it is unpacked, never run.+ '7zip' = @{+ Version = '26.03'+ Url = 'https://github.com/ip7z/7zip/releases/download/26.03/7z2603-arm64.exe'+ Sha256 = 'E22CE71C11DCF503C448FE51E56F41830EB4E1344FA5C7731AE63BCE533A8E8E'+ }+}++if ($Runtime -eq 'win-arm64') {+ $x64Versions = @{+ rhwp = $manifest.components.rhwp.version+ '7zip' = $manifest.components.'7zip'.version+ unhwp = ([xml](Get-Content (Join-Path $PSScriptRoot '..\Directory.Packages.props') -Raw)).Project.ItemGroup.PackageVersion |+ Where-Object { $_.Include -eq 'Unhwp' } | ForEach-Object Version+ }+ $missing = @($arm64Pins.Keys | Where-Object { $arm64Pins[$_].Sha256 -notmatch '^[0-9a-fA-F]{64}$' })+ if ($MissingPins) {+ $missing+ return+ }+ foreach ($name in $arm64Pins.Keys) {+ if ($arm64Pins[$name].Version -ne $x64Versions[$name]) {+ throw "build/fetch-engines.ps1 pins $name $($arm64Pins[$name].Version) for win-arm64, but the x64 build uses $($x64Versions[$name]). Pin the ARM64 build of $($x64Versions[$name])."+ }+ }+}+elseif ($MissingPins) {+ throw '-MissingPins is for -Runtime win-arm64.'+}+if ($RuntimeTo -and $Runtime -ne 'win-x64') {+ throw "-RuntimeTo is for win-x64: the $Runtime builds of rhwp and Unhwp link the C runtime statically."+}+$cache = Join-Path $PSScriptRoot '.cache'New-Item -ItemType Directory -Force -Path $cache, $Destination | Out-Null$Destination = (Resolve-Path $Destination).Path-function Get-Engine([string]$name) {+# The download for this runtime: the ARM64 pin for -Runtime win-arm64 where there is one, else engines.json.+function Get-Engine([string]$name, [switch]$X64) {$info = $engines[$name]+ if ($Runtime -eq 'win-arm64' -and -not $X64 -and $arm64Pins.Contains($name)) {+ $info = $arm64Pins[$name]+ if ($info.Sha256 -notmatch '^[0-9a-fA-F]{64}$') {+ throw "$name for win-arm64 is not pinned yet. Run the ""Windows ARM64 native"" workflow (.github/workflows/windows-arm64-native.yml), host its file at $($info.Url) and set its SHA-256 in build/fetch-engines.ps1 (`$arm64Pins)."+ }+ }$file = Join-Path $cache ([Uri]::UnescapeDataString(($info.Url -split '/')[-1]))if ((Test-Path $file) -and (Get-FileHash $file -Algorithm SHA256).Hash -eq $info.Sha256) {Write-Host "ok $name (cached)"@@ -151,8 +222,16 @@ function Optimize-LibreOffice([string]$root) {}$selected = if ($Only) { @($Only -split ',' | ForEach-Object { $_.Trim().ToLowerInvariant() } | Where-Object { $_ }) } else { @($engines.Keys) }+# Unhwp's library is only downloaded for win-arm64, and only when asked for (the x64 one comes in its NuGet package).+$valid = @($engines.Keys) + @(if ($Runtime -eq 'win-arm64') { 'unhwp' })foreach ($name in $selected) {- if (-not $engines.Contains($name)) { throw "Unknown engine '$name'. Valid: $($engines.Keys -join ', ')" }+ if ($name -notin $valid) { throw "Unknown engine '$name' for $Runtime. Valid: $($valid -join ', ')" }+}++if ('unhwp' -in $selected) {+ $target = Join-Path $Destination 'unhwp'+ Reset-Folder $target+ Copy-Item (Get-Engine 'unhwp') (Join-Path $target 'unhwp.dll')}if ('rhwp' -in $selected) {@@ -164,8 +243,11 @@ if ('rhwp' -in $selected) {if ($exe.DirectoryName -ne (Join-Path $Destination 'rhwp')) {Get-ChildItem $exe.DirectoryName -Force | Move-Item -Destination (Join-Path $Destination 'rhwp') -Force}- # rhwp.exe imports MSVCP140.dll and VCRUNTIME140.dll; without them Windows does not start it (#248).- Copy-VcRuntime (Join-Path $Destination 'rhwp')+ # rhwp.exe imports MSVCP140.dll and VCRUNTIME140.dll; without them Windows does not start it (#248). The ARM64+ # build imports neither.+ if ($Runtime -eq 'win-x64') {+ Copy-VcRuntime (Join-Path $Destination 'rhwp')+ }}if ('pandoc' -in $selected) {@@ -177,7 +259,9 @@ if ('pandoc' -in $selected) {if ('7zip' -in $selected) {# The official MSI unpacked with an administrative install (files only, no system changes). Only the console# program is kept: 7z.exe + 7z.dll (all formats, incl. RAR), the license and the readme; not the GUI or help.- $msi = Get-Engine '7zip'+ # win-arm64: there is no ARM64 MSI, only the installer program, a 7z self-extracting archive. Windows' tar.exe+ # can't undo its ARM64 executable filter, so the x64 7-Zip from the MSI unpacks it (under emulation on ARM64).+ $msi = Get-Engine '7zip' -X64$tmp = Join-Path $cache '7z-admin'Reset-Folder $tmp$proc = Start-Process msiexec.exe -ArgumentList @('/a', "`"$msi`"", '/qn', "TARGETDIR=`"$tmp`"") -Wait -PassThru@@ -187,8 +271,18 @@ if ('7zip' -in $selected) {if (-not $exe) { throw '7z.exe not found after extracting the 7-Zip MSI.' }$target = Join-Path $Destination '7zip'Reset-Folder $target- foreach ($name in @('7z.exe', '7z.dll', 'License.txt', 'readme.txt')) {- Copy-Item (Join-Path $exe.DirectoryName $name) $target+ $files = @('7z.exe', '7z.dll', 'License.txt', 'readme.txt')+ if ($Runtime -eq 'win-arm64') {+ & $exe.FullName x -y "-o$target" (Get-Engine '7zip') @files | Out-Null+ if ($LASTEXITCODE -ne 0) { throw "7-Zip could not unpack its ARM64 installer (exit code $LASTEXITCODE)." }+ foreach ($name in $files) {+ if (-not (Test-Path (Join-Path $target $name))) { throw "$name not found in the 7-Zip ARM64 installer." }+ }+ }+ else {+ foreach ($name in $files) {+ Copy-Item (Join-Path $exe.DirectoryName $name) $target+ }}Remove-Item $tmp -Recurse -Force}diff --git a/build/smoke-portable.ps1 b/build/smoke-portable.ps1index 0f06d85b..9cc707a2 100644--- a/build/smoke-portable.ps1+++ b/build/smoke-portable.ps1@@ -70,6 +70,10 @@ if ($IsLinux) {Invoke-Checked 'Load libuiohook-xrecord.so' {python3 -c 'import ctypes, sys; ctypes.CDLL(sys.argv[1]); print("Loaded " + sys.argv[1])' $backend}+ # Unhwp: from its package on x64, Filee's own build on ARM64 (build/build-native.py, -UnhwpOverride).+ Invoke-Checked 'Load libunhwp.so' {+ python3 -c 'import ctypes, sys; f = ctypes.CDLL(sys.argv[1]).unhwp_version; f.restype = ctypes.c_char_p; print("Loaded " + sys.argv[1] + ", unhwp " + f().decode())' (Join-Path $bin 'libunhwp.so')+ }}if ($env:GITHUB_ENV) {diff --git a/build/tools/make-explorer-package.cs b/build/tools/make-explorer-package.csindex d3c3c8c1..88eef144 100644--- a/build/tools/make-explorer-package.cs+++ b/build/tools/make-explorer-package.cs@@ -1,5 +1,5 @@// Packs FileeExplorerMenu.msix, the unsigned sparse package behind the Windows 11 "Convert with Filee" menu entry.-// Run by build/build-explorer-menu.ps1: dotnet run build/tools/make-explorer-package.cs -- <output folder>+// Run by build/build-explorer-menu.ps1: dotnet run build/tools/make-explorer-package.cs -- <output folder> [x64|arm64]// Uses the Windows packaging API (AppxPackaging.dll, part of Windows 10/11): it validates the manifest and writes the// block map and content types exactly like MakeAppx, so no Windows SDK is needed. The manifest comes from// ExplorerMenuPackage.CreateManifest (unit tested).@@ -11,11 +11,12 @@ using System.Runtime.InteropServices;using System.Text;using Filee.Platform.Windows;-if (args.Length != 1)+if (args.Length is < 1 or > 2 || (args.Length == 2 && !ExplorerMenuPackage.Architectures.Contains(args[1]))){- Console.Error.WriteLine("usage: dotnet run build/tools/make-explorer-package.cs -- <output folder>");+ Console.Error.WriteLine("usage: dotnet run build/tools/make-explorer-package.cs -- <output folder> [x64|arm64]");return 2;}+var architecture = args.Length == 2 ? args[1] : ExplorerMenuPackage.Architecture;var output = Path.GetFullPath(args[0]);Directory.CreateDirectory(output);@@ -27,11 +28,11 @@ var work = Directory.CreateTempSubdirectory("filee-msix-");try{var manifestPath = Path.Combine(work.FullName, "AppxManifest.xml");- File.WriteAllText(manifestPath, ExplorerMenuPackage.CreateManifest(), new UTF8Encoding(false));+ File.WriteAllText(manifestPath, ExplorerMenuPackage.CreateManifest(architecture), new UTF8Encoding(false));var packagePath = Path.Combine(output, ExplorerMenuPackage.PackageFileName);var logo = Path.Combine(repo, "src", "Filee.App", "Assets", "Icons", "filee.png");Appx.Pack(packagePath, manifestPath, [(ExplorerMenuPackage.LogoPath, logo, "image/png")]);- Console.WriteLine($"Wrote {packagePath} ({new FileInfo(packagePath).Length:N0} bytes, manifest {ExplorerMenuPackage.ManifestVersion})");+ Console.WriteLine($"Wrote {packagePath} ({new FileInfo(packagePath).Length:N0} bytes, manifest {ExplorerMenuPackage.ManifestVersion}, {architecture})");}finally{diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex 7026af65..4513562e 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -135,7 +135,8 @@ table, e.g. `dumpbin /dependents`) and look for `MSVCP140*.dll`, `VCRUNTIME140*.To bump a version, change `url`, `sha256` and `size` in engines.json together, run`pwsh build/fetch-engines.ps1`, test, and update `THIRD-PARTY-NOTICES.md`. For rhwp, also update `RHWP_VERSION`,-`RHWP_COMMIT` and `RUST_TOOLCHAIN` in `build/build-linux-native.py` (see below); CI fails until they match. When the+`RHWP_COMMIT` and `RUST_TOOLCHAIN` in `build/build-native.py` (see below); CI fails until they match. The Windows+ARM64 builds of rhwp and Unhwp need a new build and pin too (see [Windows on ARM64](#windows-on-arm64)). When theLibreOffice team retires a version from `download.documentfoundation.org/libreoffice/stable/`, its URL stops working:keep the pinned version current.@@ -143,13 +144,17 @@ keep the pinned version current.Linux packages run on Ubuntu 22.04 (glibc 2.35). rhwp's Linux release is linked on Ubuntu 24.04 (needs glibc 2.39).The `linux-native` job of `.github/workflows/portable.yml` builds it from its pinned, unmodified source on Ubuntu 22.04-(x64 and arm64) with `build/build-linux-native.py`:+(x64 and arm64) with `build/build-native.py`:- `rhwp`: `cargo build --release --locked --bin rhwp` at the tag's commit with its pinned Rust toolchain, in thelayout of rhwp's release archive.-- `check` (also run on its own): fails when engines.json pins another rhwp version than the script builds.+- `unhwp` (arm64 only): Unhwp's NuGet package ships no linux-arm64 library, so `libunhwp.so` is built from the commit+ the package's nuspec names (`cargo build --release --locked -p unhwp --lib --features ffi`, as upstream builds it).+- `check` (also run on its own): fails when engines.json pins another rhwp version, or Directory.Packages.props+ another Unhwp version, than the script builds.-The Linux package jobs pass the result to `build/build-portable.ps1 -RhwpOverride <dir>`. Local builds without it use+The Linux package jobs pass the result to `build/build-portable.ps1 -RhwpOverride <dir>` (arm64 also+`-UnhwpOverride <libunhwp.so>`, which the arm64 tests are built with too: `-p:UnhwpNativeLibrary`). Local builds without it usethe downloaded rhwp (fine on the machine that builds it). SharpHook's native libraries are packaged as they comefrom NuGet: SharpHook 8.0.0 built its X11 back ends against glibc 2.38, 8.0.1 needs glibc 2.34 at most again.@@ -157,7 +162,27 @@ from NuGet: SharpHook 8.0.0 built its X11 back ends against glibc 2.38, 8.0.1 neand the packages are unpacked and started on Ubuntu 22.04 (`build/smoke-portable.ps1`: CLI, rhwp conversions, loadingthe X11 input hook back end; `build/smoke-launch-app.py`: the app under Xvfb). If a SharpHook or engine update failsthese checks, keep the previous version until upstream builds for an older glibc again, or build the binary from its-pinned source in `build/build-linux-native.py` like rhwp (PR #113 did this for SharpHook 8.0.0's libuiohook back ends).+pinned source in `build/build-native.py` like rhwp (PR #113 did this for SharpHook 8.0.0's libuiohook back ends).++## Windows on ARM64++`build/build-installer.ps1 -Runtime win-arm64` builds `Filee-<version>-win-arm64-Setup.exe` (and `-Portable.zip`): the+app, the command line and Setup for win-arm64, the Explorer menu DLL for ARM64 (`build-explorer-menu.ps1+-Architecture arm64`, packaged as `arm64`), and ARM64 builds of the bundled engines (`fetch-engines.ps1 -Runtime+win-arm64`). The engines the app downloads stay x64; Windows 11 on ARM runs them under emulation.++- **7-Zip**: the official ARM64 installer of the version engines.json pins, a 7z self-extracting archive unpacked by+ the x64 7-Zip (Windows' `tar.exe` can't undo its ARM64 executable filter).+- **rhwp** and **Unhwp's library** have no ARM64 release. `.github/workflows/windows-arm64-native.yml` (run it from the+ Actions tab once per version) builds them on a Windows ARM64 runner with `build/build-native.py`, from the same+ pinned commits as above, with the C runtime linked statically (`+crt-static`): they import no Visual C++ runtime DLL,+ so the ARM64 build ships none. Its artifact is hosted on dl.filee.sh and pinned by SHA-256 in `$arm64Pins` of+ `build/fetch-engines.ps1`; until a pin is filled in, a win-arm64 build stops and says so. `unhwp.dll` goes next to+ `Filee.exe` through the build (`-p:UnhwpNativeLibrary`).++`UnhwpConverter` reports Unhwp as available where its library loads, so a build without it shows the engine as not+available on this platform. CI's `build (win-arm64)` job builds and tests on Windows 11 ARM64; once both pins are filled+in it also builds the package (artifact `windows-arm64-package`).## Images and vector graphicsdiff --git a/src/Filee.Engines/Filee.Engines.csproj b/src/Filee.Engines/Filee.Engines.csprojindex b3121143..0c52aa32 100644--- a/src/Filee.Engines/Filee.Engines.csproj+++ b/src/Filee.Engines/Filee.Engines.csproj@@ -35,6 +35,16 @@<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" /></ItemGroup>+ <!--+ Unhwp's package has no native library for linux-arm64 and win-arm64. build/build-native.py builds it from the+ package's source; the build passes it in (dotnet build/publish -p:UnhwpNativeLibrary=<path to libunhwp.so or+ unhwp.dll>) and it lands next to the app, where Unhwp looks for it. Unset everywhere else.+ -->+ <ItemGroup Condition="'$(UnhwpNativeLibrary)' != ''">+ <None Include="$(UnhwpNativeLibrary)" Link="$([System.IO.Path]::GetFileName('$(UnhwpNativeLibrary)'))"+ CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Visible="false" />+ </ItemGroup>+<ItemGroup><InternalsVisibleTo Include="Filee" /><InternalsVisibleTo Include="Filee.Engines.Tests" />diff --git a/src/Filee.Engines/Hwp/UnhwpConverter.cs b/src/Filee.Engines/Hwp/UnhwpConverter.csindex 494b7ca7..88d116fc 100644--- a/src/Filee.Engines/Hwp/UnhwpConverter.cs+++ b/src/Filee.Engines/Hwp/UnhwpConverter.cs@@ -34,17 +34,46 @@ public sealed class UnhwpConverter : IConverternew("hwp", "html", 14), new("hwpx", "html", 14),];- public EngineStatus GetStatus()- {- // The native library only ships for win-x64, osx-x64/arm64 and linux-x64.- var arch = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;- var supported = arch == System.Runtime.InteropServices.Architecture.X64- || (OperatingSystem.IsMacOS() && arch == System.Runtime.InteropServices.Architecture.Arm64);- return supported+ public EngineStatus GetStatus() =>+ NativeLibraryUsable.Value? EngineStatus.Available(version: EngineVersions.Library("Unhwp", typeof(UnhwpDocument))): EngineStatus.Unavailable("engine.reason.unsupported_platform");++ /// <summary>+ /// Whether this process has Unhwp's native library. The package ships it for win-x64, linux-x64 and macOS; Filee's+ /// own build adds linux-arm64 and win-arm64 (build/build-native.py). Decided once, by loading it.+ /// </summary>+ private static readonly Lazy<bool> NativeLibraryUsable = new(() =>+ NativeLibraryLoads() || (OperatingSystem.IsWindows() && NativeLibraryShipped(NativeSearchDirectories())));++ /// <summary>Asks the library its version, through Unhwp's own P/Invoke and library resolver.</summary>+ private static bool NativeLibraryLoads()+ {+ try+ {+ _ = UnhwpDocument.Version;+ return true;+ }+ catch (Exception ex) when (ex is DllNotFoundException or EntryPointNotFoundException or BadImageFormatException)+ {+ return false;+ }}+ /// <summary>+ /// True when unhwp.dll is in one of <paramref name="directories"/>. It is there but doesn't load when Windows lacks+ /// the C++ runtime it imports: the engine then stays listed and the conversion says what is missing (see+ /// <see cref="Parse"/>), as before the library was probed.+ /// </summary>+ internal static bool NativeLibraryShipped(IEnumerable<string> directories) =>+ directories.Any(directory => File.Exists(Path.Combine(directory, "unhwp.dll")));++ /// <summary>Where .NET looks for this app's native libraries: its folder and the deps.json native asset folders.</summary>+ private static IEnumerable<string> NativeSearchDirectories() =>+ ((AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES") as string) ?? "")+ .Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)+ .Append(AppContext.BaseDirectory);+public Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken) =>Task.Run<IReadOnlyList<string>>(() =>{diff --git a/src/Filee.Platform.Windows/ExplorerMenuPackage.cs b/src/Filee.Platform.Windows/ExplorerMenuPackage.csindex a4da7b42..f6e6a0a1 100644--- a/src/Filee.Platform.Windows/ExplorerMenuPackage.cs+++ b/src/Filee.Platform.Windows/ExplorerMenuPackage.cs@@ -51,9 +51,15 @@ public static class ExplorerMenuPackage/// </summary>public const string TitleFileName = "explorer-menu.txt";- /// <summary>Processor architecture of the DLL (it is loaded into explorer.exe, so it must match Explorer).</summary>+ /// <summary>+ /// Processor architecture of the DLL (it is loaded into explorer.exe, so it must match Explorer) when the build+ /// names none: x64. ARM64 builds of Filee ship an ARM64 DLL in an "arm64" package.+ /// </summary>public const string Architecture = "x64";+ /// <summary>The package architectures <see cref="CreateManifest"/> accepts (build/build-explorer-menu.ps1 -Architecture).</summary>+ public static IReadOnlyList<string> Architectures { get; } = ["x64", "arm64"];+/// <summary>Windows 11 (build 22000) is the first version with the new context menu and unsigned packages.</summary>public const int MinimumBuild = 22000;@@ -69,11 +75,14 @@ public static class ExplorerMenuPackageprivate static readonly XNamespace Rescap = "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities";/// <summary>- /// Builds AppxManifest.xml. Paths in it (Filee.exe, the DLL) are relative to the external location, i.e. the- /// install folder given at registration.+ /// Builds AppxManifest.xml for a DLL built for <paramref name="architecture"/> (one of <see cref="Architectures"/>).+ /// Paths in it (Filee.exe, the DLL) are relative to the external location, i.e. the install folder given at+ /// registration./// </summary>- public static string CreateManifest()+ public static string CreateManifest(string architecture = Architecture){+ if (!Architectures.Contains(architecture))+ throw new ArgumentOutOfRangeException(nameof(architecture), architecture, $"Expected one of {string.Join(", ", Architectures)}.");var clsid = ClassId.ToString("D").ToUpperInvariant();var package = new XElement(Foundation + "Package",new XAttribute("xmlns", Foundation.NamespaceName),@@ -88,7 +97,7 @@ public static class ExplorerMenuPackagenew XAttribute("Name", PackageName),new XAttribute("Publisher", Publisher),new XAttribute("Version", ManifestVersion.ToString(4)),- new XAttribute("ProcessorArchitecture", Architecture)),+ new XAttribute("ProcessorArchitecture", architecture)),new XElement(Foundation + "Properties",new XElement(Foundation + "DisplayName", "Filee"),new XElement(Foundation + "PublisherDisplayName", "Filee contributors"),diff --git a/src/Filee.Platform.Windows/ExplorerMenuRegistration.cs b/src/Filee.Platform.Windows/ExplorerMenuRegistration.csindex b11060ef..147b3471 100644--- a/src/Filee.Platform.Windows/ExplorerMenuRegistration.cs+++ b/src/Filee.Platform.Windows/ExplorerMenuRegistration.cs@@ -28,10 +28,14 @@ public static class ExplorerMenuRegistration/// <param name="ExternalLocation">Folder the package points at (null when Windows does not say).</param>public sealed record RegisteredPackage(string FullName, Version Version, string? ExternalLocation);- /// <summary>Windows 11 on x64: the new context menu exists and Explorer can load the x64 DLL.</summary>+ /// <summary>+ /// Windows 11 on x64 or ARM64: the new context menu exists, and Explorer can load the DLL shipped with this build+ /// (built for the same architecture as Filee itself, so not an x64 Filee on ARM64 Windows).+ /// </summary>public static bool IsSupportedOs =>OperatingSystem.IsWindowsVersionAtLeast(10, 0, ExplorerMenuPackage.MinimumBuild)- && RuntimeInformation.OSArchitecture == Architecture.X64;+ && RuntimeInformation.OSArchitecture is Architecture.X64 or Architecture.Arm64+ && RuntimeInformation.OSArchitecture == RuntimeInformation.ProcessArchitecture;/// <summary>The title file the DLL reads (see <see cref="ExplorerMenuPackage.TitleFileName"/>).</summary>public static string TitleFilePath => Path.Combine(UserDataStore.DefaultDirectory, ExplorerMenuPackage.TitleFileName);diff --git a/tests/Filee.App.Tests/ExplorerMenuTests.cs b/tests/Filee.App.Tests/ExplorerMenuTests.csindex d1df752d..791e0658 100644--- a/tests/Filee.App.Tests/ExplorerMenuTests.cs+++ b/tests/Filee.App.Tests/ExplorerMenuTests.cs@@ -47,6 +47,9 @@ public class ExplorerMenuTestsAssert.Contains("OID.2.25.311729368913984317654407730594956997722=1", (string?)identity.Attribute("Publisher"));Assert.Equal(ExplorerMenuPackage.ManifestVersion.ToString(4), (string?)identity.Attribute("Version"));Assert.Equal("x64", (string?)identity.Attribute("ProcessorArchitecture"));+ Assert.Equal("arm64", (string?)XDocument.Parse(ExplorerMenuPackage.CreateManifest("arm64")).Root!+ .Element(F + "Identity")!.Attribute("ProcessorArchitecture"));+ Assert.Throws<ArgumentOutOfRangeException>(() => ExplorerMenuPackage.CreateManifest("x86"));Assert.Equal("true", (string?)manifest.Element(F + "Properties")!.Element(Uap10 + "AllowExternalContent"));Assert.Equal("10.0.22000.0", (string?)manifest.Descendants(F + "TargetDeviceFamily").Single().Attribute("MinVersion"));@@ -212,7 +215,10 @@ public class ExplorerMenuTestsAssert.NotNull(zip.GetEntry("[Content_Types].xml"));Assert.NotNull(zip.GetEntry(ExplorerMenuPackage.LogoPath.Replace('\\', '/')));using var stream = zip.GetEntry("AppxManifest.xml")!.Open();- Assert.True(XNode.DeepEquals(XDocument.Parse(ExplorerMenuPackage.CreateManifest()).Root, XDocument.Load(stream).Root),+ var built = XDocument.Load(stream).Root!;+ // Built for x64 or, with -Architecture arm64, for ARM64 (CreateManifest rejects any other).+ var architecture = (string)built.Element(F + "Identity")!.Attribute("ProcessorArchitecture")!;+ Assert.True(XNode.DeepEquals(XDocument.Parse(ExplorerMenuPackage.CreateManifest(architecture)).Root, built),"The package is stale: run build/build-explorer-menu.ps1 again.");}@@ -220,8 +226,8 @@ public class ExplorerMenuTestspublic void Native_dll_serves_the_explorer_command_in_process(){var dll = Path.Combine(BuiltFolder, ExplorerMenuPackage.DllFileName);- Assert.SkipUnless(OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.X64 && File.Exists(dll),- "Run build/build-explorer-menu.ps1 first (x64 Windows).");+ Assert.SkipUnless(OperatingSystem.IsWindows() && File.Exists(dll) && DllArchitecture(dll) == RuntimeInformation.ProcessArchitecture,+ "Run build/build-explorer-menu.ps1 first (-Architecture arm64 on Windows on ARM).");using var command = NativeCommand.Create(dll);// The title comes from the file the app writes into its data folder; without it the English default is used.@@ -245,6 +251,20 @@ public class ExplorerMenuTests}}+ /// <summary>The machine a PE file is built for (its COFF header), or null for any other than x64 and ARM64.</summary>+ private static Architecture? DllArchitecture(string path)+ {+ using var reader = new BinaryReader(File.OpenRead(path));+ reader.BaseStream.Position = 0x3C;+ reader.BaseStream.Position = reader.ReadInt32() + 4;+ return reader.ReadUInt16() switch+ {+ 0x8664 => Architecture.X64,+ 0xAA64 => Architecture.Arm64,+ _ => null,+ };+ }+/// <summary>Calls FileeExplorerMenu.dll through its exports and the raw IExplorerCommand vtable.</summary>private sealed class NativeCommand : IDisposable{diff --git a/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj b/tests/Filee.Engines.Tests/Filee.Engines.Tests.csprojindex 90946d30..3d4e74b6 100644--- a/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj+++ b/tests/Filee.Engines.Tests/Filee.Engines.Tests.csproj@@ -20,6 +20,14 @@<Using Include="Xunit" /></ItemGroup>+ <ItemGroup>+ <!-- Built with a self-built Unhwp library (-p:UnhwpNativeLibrary, ARM64 CI): UnhwpNativeTests then expect Unhwp. -->+ <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">+ <_Parameter1>UnhwpNativeLibrary</_Parameter1>+ <_Parameter2>$(UnhwpNativeLibrary)</_Parameter2>+ </AssemblyAttribute>+ </ItemGroup>+<ItemGroup><!-- Small OFL test fonts for FontTests (see Fonts/OFL.txt and Fonts/make-test-fonts.py). --><None Update="Fonts\*.ttf;Fonts\*.otf;Fonts\*.woff2" CopyToOutputDirectory="PreserveNewest" />diff --git a/tests/Filee.Engines.Tests/HwpxAssert.cs b/tests/Filee.Engines.Tests/HwpxAssert.csindex 211917a1..22fc6458 100644--- a/tests/Filee.Engines.Tests/HwpxAssert.cs+++ b/tests/Filee.Engines.Tests/HwpxAssert.cs@@ -87,7 +87,7 @@ internal static class HwpxAssert}/// <summary>- /// The text of an HWPX as an independent reader sees it: Unhwp where its native library exists, else (Linux ARM64)+ /// The text of an HWPX as an independent reader sees it: Unhwp where its native library exists, else (an ARM64 build without it)/// the text of the section XML./// </summary>public static string ReadBackText(string hwpx)diff --git a/tests/Filee.Engines.Tests/NewExtensionsRealTests.cs b/tests/Filee.Engines.Tests/NewExtensionsRealTests.csindex 8106e9c3..f4286ed8 100644--- a/tests/Filee.Engines.Tests/NewExtensionsRealTests.cs+++ b/tests/Filee.Engines.Tests/NewExtensionsRealTests.cs@@ -57,7 +57,7 @@ public class NewExtensionsRealTests(EngineFixture fx) : IClassFixture<EngineFixt""", TestContext.Current.CancellationToken);// One row per request: method, address and status side by side. CSV is the table step every table route- // (Markdown, spreadsheets, PDF) starts from; Markdown itself goes through Unhwp, which Linux ARM64 lacks.+ // (Markdown, spreadsheets, PDF) starts from; Markdown itself goes through Unhwp, which an ARM64 build may lack.var csv = await File.ReadAllTextAsync(await ConvertAsync(har, "csv"), TestContext.Current.CancellationToken);Assert.Contains("GET,https://example.com/api/items,200", csv);var json = await File.ReadAllTextAsync(await ConvertAsync(har, "json"), TestContext.Current.CancellationToken);diff --git a/tests/Filee.Engines.Tests/UnhwpNativeTests.cs b/tests/Filee.Engines.Tests/UnhwpNativeTests.csnew file mode 100644index 00000000..ae556ddf--- /dev/null+++ b/tests/Filee.Engines.Tests/UnhwpNativeTests.cs@@ -0,0 +1,57 @@+// Unhwp is available where its native library loads: from its NuGet package (win-x64, linux-x64, macOS) or from+// Filee's own build of the same release (linux-arm64, win-arm64; build/build-native.py, -p:UnhwpNativeLibrary).++using System.Reflection;+using Filee.Engines.Hwp;+using Filee.Engines.Infrastructure;+using Unhwp;++namespace Filee.Engines.Tests;++public class UnhwpNativeTests+{+ /// <summary>The library this build was given with -p:UnhwpNativeLibrary, or null.</summary>+ private static string? BuiltWith =>+ typeof(UnhwpNativeTests).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()+ .SingleOrDefault(a => a.Key == "UnhwpNativeLibrary")?.Value is { Length: > 0 } path ? path : null;++ [Fact]+ public void Status_follows_whether_the_native_library_loads()+ {+ var status = new UnhwpConverter().GetStatus();+ if (EngineDownloads.RuntimeIdentifier is "win-x64" or "linux-x64" or "osx-x64" or "osx-arm64")+ Assert.True(status.IsAvailable, "Unhwp's package ships the library for this platform.");+ if (BuiltWith is { } library)+ Assert.True(status.IsAvailable, $"This build copied {library} next to the app, but it doesn't load.");++ if (status.IsAvailable)+ {+ // A self-built library must be the release the managed binding comes from.+ var managed = typeof(UnhwpDocument).Assembly.GetName().Version!;+ Assert.Equal($"{managed.Major}.{managed.Minor}.{managed.Build}", UnhwpDocument.Version);+ }+ else+ {+ Assert.Equal("engine.reason.unsupported_platform", status.ReasonKey);+ }+ }++ [Fact]+ public void A_shipped_library_that_does_not_load_counts_as_shipped()+ {+ var empty = Directory.CreateTempSubdirectory("filee-unhwp-").FullName;+ var shipped = Directory.CreateTempSubdirectory("filee-unhwp-").FullName;+ try+ {+ File.WriteAllText(Path.Combine(shipped, "unhwp.dll"), "not a library");+ Assert.False(UnhwpConverter.NativeLibraryShipped([]));+ Assert.False(UnhwpConverter.NativeLibraryShipped([empty]));+ Assert.True(UnhwpConverter.NativeLibraryShipped([empty, shipped]));+ }+ finally+ {+ Directory.Delete(empty, recursive: true);+ Directory.Delete(shipped, recursive: true);+ }+ }+}